One page
GraphQL cheat sheet
What to keep at hand. If a line is not clear, go back to the matching lesson in the course.
Open the course: GraphQL: getting startedSchema
| What | How |
|---|---|
| Type | type Book { id: ID! title: String! } |
| Read | type Query { book(id: ID!): Book } |
| Write | type Mutation { addBook(input: BookInput!): Book! } |
Queries and server
| What | How |
|---|---|
| Variable | query Book($id: ID!) { book(id: $id) { title } } |
| Fragment | fragment Card on Book { id title } |
| Resolver | (parent, args, context) => value |
| DataLoader | ctx.loaders.author.load(book.authorId) |
Types, errors, pages
| What | How |
|---|---|
| Input object | input NewBookInput { title: String! } |
| One of the types | union SearchResult = Book | Author |
| Type's field | ... on Book { title } |
| An error with a code | new GraphQLError("…", { extensions: { code: "FORBIDDEN" } }) |
| Page | books(first: 20, after: $after) { edges { node { id } } pageInfo { endCursor } } |