From f657e09b5302d5fd8cfa4ac4ec18f2f47d7b9146 Mon Sep 17 00:00:00 2001 From: Mahmoud Abdelwahab Date: Sun, 25 Jul 2021 23:47:04 +0200 Subject: [PATCH] Fix CORS issue in GraphQL example that prevented Apollo Studio from working (#27486) Update example so Apollo Studio works properly --- examples/api-routes-graphql/pages/api/graphql.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/api-routes-graphql/pages/api/graphql.js b/examples/api-routes-graphql/pages/api/graphql.js index 1c31600a20dbc..0a29f3ce88987 100644 --- a/examples/api-routes-graphql/pages/api/graphql.js +++ b/examples/api-routes-graphql/pages/api/graphql.js @@ -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({