Search code examples
graphqlclojurescriptre-frame

re-graph: CORS error with remote graphql server


I'm using re-graph to make a graphql query to a remote server:

(re-frame/dispatch [::re-graph/init
                    {:http-url "https://api.spacex.land/graphql"
                     :ws-url nil
                      :http-parameters
                               {:headers {"Access-Control-Allow-Headers" "Content-Type"
                                          "Access-Control-Allow-Origin" "*"}}}])

But I keep getting this CORS error:

Access to XMLHttpRequest at 'https://api.spacex.land/graphql' from origin 'http://localhost:3449' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

Any idea what I need to do?


Solution

  • Simple fix:

    (re-frame/dispatch [::re-graph/init
                        {:http-url "https://api.spacex.land/graphql"
                         :ws-url nil
                          :http-parameters {:with-credentials? false}}])