This repository contains some GraphQL code that covers its usage on Back-End (plus GraphiQL). Presentation Link.
- npm
- node
# My current environment
$ npm -v
6.4.1
$ node -v
v10.14.1
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
.
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
.
Go to branch develop/3
.
Implement 3 new queries for your users:
- One that retrieves data from a
candidate
, either byid
oremail
- One that retrieves data from a
company
, given itsid
- One that retrieves data from a
jobAd
, given itsid
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
.