Skip to content

A repository used in a Dojo about "Introduction to GraphQL"

License

Notifications You must be signed in to change notification settings

brunogsa/dojo-introduction-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

cf15577 · Aug 7, 2019

History

30 Commits
Jul 31, 2019
Jul 31, 2019
Jul 31, 2019
Jul 31, 2019
Jul 31, 2019
Jul 31, 2019
Jul 23, 2019
Aug 7, 2019
Jul 31, 2019
Jul 31, 2019
Jul 31, 2019
Jul 31, 2019

Repository files navigation

Dojo: Introduction to GraphQL

This repository contains some GraphQL code that covers its usage on Back-End (plus GraphiQL). Presentation Link.

Pre-reqs

  • npm
  • node
# My current environment

$ npm -v
6.4.1

$ node -v
v10.14.1

Hands-on 1/3: My first GraphQL Schema

Go to branch develop/1.

This is your data:

const candidate = {
  id:         string | number,
  name:       string,
  email:      string,
  profession: 'frontend' | 'backend' | 'devops' | 'ux' | 'po' | 'tester',
  photo:      string,
  following:  array of candidate ID,
};

const company = {
  id:         string | number,
  name:       string,
  photo:      string,
  openJobAds: array of jobAd IDs,
};

const jobAd = {
  id:                 string | number,
  title:              string,
  description:        string,  // Optional
  forCompany:         company ID,
  requiredProfession: 'frontend' | 'backend' | 'devops' | 'ux' | 'po' | 'tester',
  remainingVacancies:  number,
};

You may check data-sources/ folder for more details about how is your data.

Your first step is to build your GraphQL schema at schema.graphql file!

Reference:

You can test it with:

$ npm install
$ npm run lint:graphql

Solution on branch solution/1.

Hands-on 2/3: My first Resolver

Go to branch develop/2.

Resolvers are functions that tell GraphQL how to provide your data.

  • You need 1 resolver for each query
  • You need 1 resolver for each field of a type you defined in your schema.graphql

Now, you want to enable 3 queries for your users:

  • candidates
  • companies
  • jobAds

For that, implement those basic resolvers at resolvers/ folder, using the imported functions from your services/ folder.

You can test your resolvers with:

$ npm start               # Manually at http://localhost:3000/graphql
$ npm run test:graphql    # Automatically

Reference:

Solution on branch solution/2.

Hands-on 3/3: Passing parameters to Resolvers

Go to branch develop/3.

Implement 3 new queries for your users:

  • One that retrieves data from a candidate, either by id or email
  • One that retrieves data from a company, given its id
  • One that retrieves data from a jobAd, given its id

Again: check your services/ to reuse you already existing code!
More automated tests were added, so feel free to run the same scripts :)

Reference:

Solution on branch solution/3.

About

A repository used in a Dojo about "Introduction to GraphQL"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published