From 416b3d66349a3f2fd83ac2e97d5c8a11206243a5 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Mon, 23 Dec 2024 18:56:03 +0100 Subject: [PATCH] Handle options requests --- handler/graphql.mjs | 9 ++++++++- netlify.toml | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/handler/graphql.mjs b/handler/graphql.mjs index 30a8997..8c43a72 100644 --- a/handler/graphql.mjs +++ b/handler/graphql.mjs @@ -10,5 +10,12 @@ import { createHandler } from 'graphql-http/lib/use/@netlify/functions'; import schema from '../lib/schema'; +const graphqlHandler = createHandler({ schema: schema.default }) + // Create the GraphQL over HTTP native fetch handler -export const handler = createHandler({ schema: schema.default }); +export const handler = async (req, ctx) => { + if (req.httpMethod === 'OPTIONS') { + return { statusCode: 200 } + } + return graphqlHandler(req, ctx) +}; diff --git a/netlify.toml b/netlify.toml index dcf54dd..58aa14b 100644 --- a/netlify.toml +++ b/netlify.toml @@ -6,3 +6,4 @@ for = "/graphql*" [headers.values] Access-Control-Allow-Origin = "*" + Access-Control-Allow-Headers = "*"