Created
July 8, 2019 20:42
-
-
Save mfellner/2119db3584023092d70118a8dabd146e to your computer and use it in GitHub Desktop.
Using Apollo Server in Next.js 9 with API route in pages/api/graphql.ts
This file contains 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'; | |
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' }); |
Thank you
Thank you!
Thank you!
Thank you!!!
Thank you!!!!!!!!!
Thank You 👍
you rock 🤘
👏 thanks for sharing!
Anyone can point me to documentation for export const config
? The snippet won't work if I remove it. Since it's not being referenced anywhere in the snippet, I wonder where it's being used.
Anyone can point me to documentation for
export const config
? The snippet won't work if I remove it. Since it's not being referenced anywhere in the snippet, I wonder where it's being used.
https://nextjs.org/docs/api-routes/api-middlewares#custom-config
It is used by next.js if declared, same as the default export of each API route.
Nice. Thanks!
How would you use this in getStaticProps
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this!