Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Fix CORS issue in GraphQL example that prevented Apollo Studio from w…
Browse files Browse the repository at this point in the history
…orking (vercel#27486)

Update example so Apollo Studio works properly
  • Loading branch information
Mahmoud Abdelwahab authored Jul 25, 2021
1 parent d06c854 commit 826fd3b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/api-routes-graphql/pages/api/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ 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'
)
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({
Expand Down

0 comments on commit 826fd3b

Please sign in to comment.