Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApolloServer.applyMiddleware doesn't support OPTIONS requests #2253

Closed
nounder opened this issue Jan 31, 2019 · 3 comments
Closed

ApolloServer.applyMiddleware doesn't support OPTIONS requests #2253

nounder opened this issue Jan 31, 2019 · 3 comments
Labels
⛲️ feature New addition or enhancement to existing solutions
Milestone

Comments

@nounder
Copy link
Contributor

nounder commented Jan 31, 2019

As far as I know, it only applies to Koa integration. Could be for other integrations, too.

ApolloServer.applyMiddleware only add middleware to support GET and POST requests. It should also support OPTIONS. Otherwise it will break setup when client and server are on different hosts.

Why does it matter? Given you want to access GraphQL server (at graphql.local) on web client (at frontend.local) browser will send OPTIONS request before any user request to make sure graphql.local accepts requests made from frontend.local (via Access-Control-Allow-Origin header).

@abernix
Copy link
Member

abernix commented Feb 7, 2019

I would happily review a PR which adds this! There are implementations of this in other integrations (it is missing from -express, -koa, and probably others) which can be used as prior art.

For example, the Azure Functions integration :

if (req.method === 'OPTIONS') {
context.done(null, {
body: '',
status: 204,
headers: corsHeaders,
});
return;
}

...and in the Google Cloud Functions implementation as well:

if (req.method === 'OPTIONS') {
res.status(204).send('');
return;
}

@abernix abernix added the ⛲️ feature New addition or enhancement to existing solutions label Feb 7, 2019
@abernix abernix added this to the Release 2.4.x milestone Feb 19, 2019
@cheapsteak
Copy link
Member

cheapsteak commented Feb 19, 2019

It looks like OPTIONS is working for -express (I just checked against fullstack-tutorial)
image

I would guess the cors middleware is handling OPTIONS automatically

if (cors === true) {
app.use(path, corsMiddleware());
} else if (cors !== false) {
app.use(path, corsMiddleware(cors));
}

It looks like there are similar lines in -koa

if (cors === true) {
app.use(middlewareFromPath(path, corsMiddleware()));
} else if (cors !== false) {
app.use(middlewareFromPath(path, corsMiddleware(cors)));
}

I wonder if '@koa/cors' should handle this?

@abernix
Copy link
Member

abernix commented Feb 19, 2019

Ah, that makes sense. I guess some integrations handle it at another level. Thanks for pointing this out, @cheapsteak!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⛲️ feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

3 participants