Skip to content
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

Merged
merged 6 commits into from
Jul 20, 2021
Merged

Update graphql example #27334

merged 6 commits into from
Jul 20, 2021

Conversation

m-abdelwahab
Copy link

Documentation / Examples

This is an update to the GraphQL example to use apollo server 3. This example works with Apollo Studio

@ijjk ijjk added the examples Issue/PR related to examples label Jul 20, 2021
leerob
leerob previously approved these changes Jul 20, 2021
Copy link
Member

@leerob leerob left a 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!

@kodiakhq kodiakhq bot merged commit c3884e6 into vercel:canary Jul 20, 2021
@fredrik-sogaard
Copy link

This is not working for me. Tried both a local version with yarn create next-app --example api-routes-graphql api-routes-graphql-app and the StackBlitz version, but I'm getting CORS errors from Apple Studio.

@fredrik-sogaard
Copy link

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?

flybayer pushed a commit to blitz-js/next.js that referenced this pull request Aug 19, 2021
## 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
@nosovandrew
Copy link

@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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants