Unverified Commit c3884e68 authored by Mahmoud Abdelwahab's avatar Mahmoud Abdelwahab Committed by GitHub

Update graphql example (#27334)

## 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
parent 9fc58f88
......@@ -6,12 +6,13 @@
"start": "next start"
},
"dependencies": {
"apollo-server-micro": "2.11.0",
"graphql": "14.6.0",
"apollo-server-micro": "^3.0.1",
"graphql": "^15.5.1",
"micro": "^9.3.4",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"swr": "0.1.18"
"swr": "^0.5.6"
},
"license": "MIT"
}
......@@ -19,10 +19,27 @@ const resolvers = {
const apolloServer = new ApolloServer({ typeDefs, resolvers })
const startServer = apolloServer.start()
export default async function handler(req, res) {
if (req.method === 'OPTIONS') {
res.end()
return false
}
res.setHeader('Access-Control-Allow-Credentials', 'true')
res.setHeader(
'Access-Control-Allow-Origin',
'https://studio.apollographql.com'
)
await startServer
await apolloServer.createHandler({
path: '/api/graphql',
})(req, res)
}
export const config = {
api: {
bodyParser: false,
},
}
export default apolloServer.createHandler({ path: '/api/graphql' })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment