-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update graphql example #27334
Update graphql example #27334
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to run lint
, but code LGTM!
This is not working for me. Tried both a local version with |
I managed to get it working by changing to this: export default async function handler(req, res) {
res.setHeader('Access-Control-Allow-Credentials', 'true')
res.setHeader(
'Access-Control-Allow-Origin',
'https://studio.apollographql.com'
)
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
)
if (req.method === 'OPTIONS') {
res.end()
return false
}
await startServer
await apolloServer.createHandler({
path: '/api/graphql',
})(req, res)
} Not sure if this is the correct way of doing it? |
## Documentation / Examples This is an update to the [GraphQL example](https://github.com/vercel/next.js/tree/canary/examples/api-routes-graphql) to use [apollo server 3](https://www.apollographql.com/docs/apollo-server). This example works with Apollo Studio
@fredrik-sogaard With apollo-server v3 we need to use apolloServer.start() in contrast to how it was in the v2. Is it correct approach? As I understand Next.JS runs its own server and we don't need to run another one. Please explain me if I'm wrong. |
Documentation / Examples
This is an update to the GraphQL example to use apollo server 3. This example works with Apollo Studio