Skip to content

Instantly share code, notes, and snippets.

@bengrunfeld
Created June 21, 2020 08:21
Show Gist options
  • Save bengrunfeld/0e4db14ee97189507c3cf8b1da8f3fc8 to your computer and use it in GitHub Desktop.
Save bengrunfeld/0e4db14ee97189507c3cf8b1da8f3fc8 to your computer and use it in GitHub Desktop.
GraphQL-Apollo-NextJS Starter App: pages/api/graphql-data.js
import { ApolloServer, gql } from "apollo-server-micro";
let book = {
name: "The Hungarian Sausage",
author: "Ben Grunfeld",
};
const typeDefs = gql`
type Book {
name: String
author: String
}
type Query {
book: Book
}
type Mutation {
updateBook(name: String!, author: String!): Book
}
`;
const resolvers = {
Query: {
book: () => book,
},
Mutation: {
updateBook: (root, args) => {
book.name = args.name;
book.author = args.author;
return book;
},
},
};
const server = new ApolloServer({ typeDefs, resolvers });
const handler = server.createHandler({ path: "/api/graphql-data" });
export const config = {
api: {
bodyParser: false,
},
};
export default handler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment