This is a presentation given by Dirk-Jan Rutten and Florentijn Hogerwerf at the React-Amsterdam Winter Event held on the 23rd of February 2017 (https://www.meetup.com/React-Amsterdam/events/237423993/).
2. Dirk-Jan @excite-engineer
Dirk is a Software Engineer with a
focus on Javascript who gets (way
too) excited about writing stable and
well tested code. GraphQL fan.
Florentijn @Mr_Blue_Sql
GraphQL enthusiast. Focusing on
Javascript and realizing highly
available, easy to maintain solutions
on AWS. I like giving high ves.
6. Properties
Client controls data, not the server
Multiple resources in a single
request
Documentation is awesome
Type system
Developer tools: GraphiQL
23. Business Logic
Single source of truth for enforcing
business rules.
Determines how data is retrieved,
created and updated from DB.
Performs authorization for data
Performs validation
24. Connecting GraphQL to the business
logic:
Resolver functions maps directly to the
business logic.
29. Example 2: Mutation to update a joke
mutation {
updateJoke(jokeId: "1", funnyLevel: 10) {
id
text
funnyLevel
}
}
30. GraphQL
const mutation = {
type: new GraphQLNonNull(GraphQLJoke),
description: "Update a joke.",
args: {
jokeId: { type: new GraphQLNonNull(GraphQLID) },
funnyLevel: { type: new GraphQLNonNull(GraphQLInt) }
},
resolve: (root, args, context) => {
//...
}
}
31. Single source of truth for authorization
import Joke from "../logic";
resolve: (root, args, context) => {
/* Authorization */
const joke = Joke.gen(context.viewer, args.jokeId);
if (!joke) throw new Error('No joke found for the id');
/* Performs validation and updates DB */
joke.setFunnyLevel(args.funnyLevel);
return joke;
}
45. List Example
"data" {
"viewer" {
"jokes": [
{
"id": "1",
"text": "How do you make a tissue"
},
...
{
"id": "500",
"text": "Pfooo, only half way"
},
...
{
"id": "1000",
49. Advantages Relay Compliant Schema
Enforce globally unique id that is
opaque
Any resource that belongs to you
can be retrieved using a single query
Pagination for lists is built in
Opportunity to change to Relay if
you wish
50. To Sum Up
Lesson 1: API, Business Logic,
Persistence Layer
Lesson 2: Relay compliant schema