Skip to content

Instantly share code, notes, and snippets.

@nilportugues
Forked from mfellner/graphql.ts
Created July 9, 2019 09:31
Show Gist options
  • Save nilportugues/6ad5e97670089a430b3befb6620c66ce to your computer and use it in GitHub Desktop.
Save nilportugues/6ad5e97670089a430b3befb6620c66ce to your computer and use it in GitHub Desktop.
Using Apollo Server in Next.js 9 with API route in pages/api/graphql.ts
import { ApolloServer, gql } from 'apollo-server-micro';
const typeDefs = gql`
type Query {
sayHello: String
}
`;
const resolvers = {
Query: {
sayHello(parent, args, context) {
return 'Hello World!';
}
}
};
const apolloServer = new ApolloServer({ typeDefs, resolvers });
export const config = {
api: {
bodyParser: false
}
};
export default apolloServer.createHandler({ path: '/api/graphql' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment