nautilus / gateway

A federated api gateway for graphql services. https://gateway.nautilus.dev/
MIT License
397 stars 49 forks source link

about cors settings #194

Closed codebdy closed 4 months ago

codebdy commented 1 year ago

Hi, Dears i meet cors problem,when client seent "OPTION" requet, get 405 error, I find the source not not process "OPTION" method : image

Is any way to fixed it?

codebdy commented 1 year ago

add this code, fixed: image

is right?

JohnStarich commented 4 months ago

I think your solution is a good one.

It's unclear to me how a GraphQL server (library) should respond to an OPTIONS request. I skimmed the draft specification for GraphQL over HTTP and I only see POST and GET mentioned.

I think handling CORS requests in your own middleware wrapped around the gateway is probably the best choice for now. Perhaps if there's precedent from other GraphQL servers or some clarification in the spec, then we could support OPTIONS in gateway natively.

JohnStarich commented 4 months ago

You could adopt a similar HTTP handler for OPTIONS to the one provided in cmd/gateway here: https://github.com/nautilus/gateway/blob/3c19e01d118981add189ca7abe5e56a784918455/cmd/gateway/http.go#L48-L59

The library though may need to wait to adopt this until the GraphQL community establishes the right path forward. I'd be happy to reopen this once that becomes clearer.