Skip to content

Instantly share code, notes, and snippets.

@kimobrian
Last active February 17, 2018 07:13
Show Gist options
  • Save kimobrian/cac278295e3701c37eab6fa78165c845 to your computer and use it in GitHub Desktop.
Save kimobrian/cac278295e3701c37eab6fa78165c845 to your computer and use it in GitHub Desktop.
A gist describing different tools in the GraphQL ecosystem: graphql-tools

makeExecutableSchema

import { makeExecutableSchema } from 'graphql-tools';

const executableSchema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

Root Resolver

let resolvers = {
  Query: {
    getBooks: () => { /* logic to return books */ }
  },
  Mutation: {
    createBook(parent, args, context, info) {
      /* Logic to create a book */
    }
  }
}

Schema

let typeDefs = `
type Book {
  id: ID!
  name: String!,
  author: String!,
  pages: Int!
}

type Query {
  getBooks: [Book!]!
}

type Mutation: {
  createBook(name: String!, author: String!, pages: Int!): Book!
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment