Created
June 21, 2020 08:21
-
-
Save bengrunfeld/0e4db14ee97189507c3cf8b1da8f3fc8 to your computer and use it in GitHub Desktop.
GraphQL-Apollo-NextJS Starter App: pages/api/graphql-data.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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