Next.js: [Next 9.0.0] GraphQL endpoint with apollo-server-micro doesn't work

Created on 8 Jul 2019  路  4Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Unable to load GraphQL Playground / endpoints in /pages/api with a lambda using apollo-server-micro

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://github.com/yoongfook/nextjs9-apollo
  2. Install and run yarn dev
  3. Go to /api/basic - works!
  4. Go to /api/micro - works!
  5. Go to /api/apollo-server-micro - unable to load schema, unable to make query, mutation

Expected behavior

Go to /api/apollo-server-micro - able to load schema, make query, mutation

Screenshots

image

System information

  • OS: macOS
  • Browser (if applies): Chrome
  • Version of Next.js: 9.0.0

Additional context

Add any other context about the problem here.

example

Most helpful comment

This was the missing piece!

https://gist.github.com/mfellner/2119db3584023092d70118a8dabd146e#file-graphql-ts-L19-L23

All 4 comments

Each file index file in pages directory should export react component, you're trying to have a graphql server there. I think what you're looking for is how to run a custom server and add grapqhl there. Take a look at docs or express example

Each file index file in pages directory should export react component, you're trying to have a graphql server there. I think what you're looking for is how to run a custom server and add grapqhl there. Take a look at docs or express example

In the latest Next 9.0.0, they have enabled support for /pages/api api routes to build api server using lambdas. Please see their example here: https://github.com/zeit/next.js/tree/canary/examples/api-routes/pages

Just tried too, it's not working, I checked the network tab and this query IntrospectionQuery is hanging.

This was the missing piece!

https://gist.github.com/mfellner/2119db3584023092d70118a8dabd146e#file-graphql-ts-L19-L23

Was this page helpful?
0 / 5 - 0 ratings