andreas/ocaml-graphql-server

CORS?

Closed this issue · 4 comments

Hi. Does this support CORS? I could't find any mention of it or headers like Access-Control-Allow-Origin.

Could you give me an example of setting the CORS headers?

Thanks

This library provides an example server that doesn't allow you to customize the response headers:

| Ok (`Response data) ->
let body = Yojson.Basic.to_string data in
C.Server.respond_string ~status:`OK ~body ()

However, as I found in my own projects, that is not enough and you'll need to write your own server that calls into the constructs provided by Graphql_schema. This function is a good starting point to writing your own:

let execute_request ctx schema body =

Adding custom HTTP headers to the response will be a lot easier once this PR is merged: #126

In the meantime you can either take the approach described by @anmonteiro, or have Nginx in front and add CORS headers there (that's what I do).

graphql-cohttp is now a thing. This can probably be closed?

I'll close this one. Feel free to open a PR against graphql-cohttp with CORS support 😄