by Jhankar Mahbub / @jsdude005
REST. . . . . . . . . . . . . .GraphQL
Predict shape of the result
{
hero {
name
}
}
{
"data": {
"hero": {
"name": "R2-D2"
}
}
}
Add only the fields needed
{
hero {
name,
id
}
}
{
"data": {
"hero": {
"name": "R2-D2",
"id": "2001"
}
}
}
REST, can a single set of arguments on query parameters and URL segments
GraphQL, every field and nested object can get its own set of arguments
One query can replace multiple api
What was on the RIP T-shirt?
Don't Repeat use fragments
$variableName
friends(first:2 offset:2)
friends(first:2 after:$friendCursor)
__typename
, a meta field, at any point in a queryPOST
mutation
in the beginningPredetermined whether a GraphQL query is valid or not
There is no error code. Everything is 200 and read error message
Fragment cannot refer itself
import ApolloClient from 'apollo-boost';
const client = new ApolloClient();
/graphql
import ApolloClient from 'apollo-boost';
const client = new ApolloClient({
uri: 'https://graphql.example.com'
});
Mutation
for Post(create, update, delete)What was the first company?
GraphQL server with a connected database
Brand new application
GraphQL server that is a thin layer in front of a number of third party or legacy systems and integrates them through a single GraphQL API
A hybrid approach of a connected database and third party or legacy systems that can all be accessed through the same GraphQL API
Query
,
Mutation
, and
Subscription
types are the entry points for the requests sent by the client.
name
,
appearsIn
are fields on Character typeGraphQL service needs to have a Query type with hero and droid fields
To execute this query we need a type system
resolver
graphql.js
graphene
Delegate authorization logic to business logic layer
It is tempting to place authorization logic in the GraphQL layer like this
We would need to duplicate this code for each entry point into the service
Rest vs GraphQL
/graphql
http://myapi/graphql?query={me{name}}
operationName
to control which one should be executedGraphQL POST request should use the application/json content type
Think like the language you use everyday to describe your business
Fetch the previewInfo
for the first 20 drafts in the main account
What is
QL
in
GraphQL
?
thatjsdude.com/workshops/react
Email: khan4019@gmail.comTight on food budget
Want to save more...
Save even more...
Ultimate saver...
-Website: thatjsude.com
-Workshop: thatjsdude.com/workshops/react/
-Youtube: youtube.com/c/ThatJSDude
-Email: khan4019@gmail.com