GraphQL

This page refers to the GraphQL JavaScript package

Directory Structure

src/graphql/Schema.ts
src/graphql/Mutation.ts
src/graphql/User.ts (GraphQLObjectType)
src/graphql/mutations/UserMutation.ts

Schema

Put edges in a "Viewer" GraphQLObjectType so that you can use it as the "root" object.

type Query {
  entries(order: String, sort: String, after: String, first: Int, before: String, last: Int): EntryConnection
  tags(after: String, first: Int, before: String, last: Int): TagConnection
  viewer: Viewer
}

type Viewer implements EntryConnectionInterface {
  entries(order: String, sort: String, after: String, first: Int, before: String, last: Int): EntryConnection
  tags(after: String, first: Int, before: String, last: Int): TagConnection
}

Resolvers

Naming:

  • Postfix function names with Resolver

  • Pass in all the args: root, args, context, info

Bugs

Could not convert from GraphQL type String

When running relay-compiler I would get this error:

Could not convert from GraphQL type String

Environment: Lerna with multiple graphql packages installed

Solution specify resolutions in local package.json:

Worse case, nuke your node_modules:

Last updated

Was this helpful?