GraphQL

#Cons of REST

Cons of rest, composition of multiple resources requires multiple network requests

#Fragment Container

https://facebook.github.io/relay/docs/fragment-container.html

Cons:

  • Can't change the params

#Refetch Container

https://facebook.github.io/relay/docs/refetch-container.html

Cons:

  • First set of params/variables can't be dynamic/set

#Pagination Container

https://facebook.github.io/relay/docs/pagination-container.html

Cons:

  • Can only change the count variable, nothing else

#Best Practices

#Ids

https://github.com/graphql/graphql-relay-js/blob/4fdadd3bbf3d5aaf66f1799be3e4eb010c115a4a/src/node/node.js

import {fromGlobalId, toGlobalId} from 'graphql-relay';
let {type, id} = fromGlobalId(globalId);
let globalID = toGlobalId(type, id);

#Resolve

See GraphQLFieldResolveFn https://graphql.org/graphql-js/type/#graphqlobjecttype

resolve: async (root, args, context, info)
type GraphQLFieldResolveFn = (
  source?: any,
  args?: {[argName: string]: any},
  context?: any,
  info?: GraphQLResolveInfo
) => any

#Fragments

Group fragments at top, for example:

fragment Example {
  ...Fragment1
  ...Fragment2
  field1
  field2
}

#Examples