重新绘制:远程 graphql 服务器出现 CORS 错误

re-graph: CORS error with remote graphql server

我正在使用 re-graph 对远程服务器进行 graphql 查询:

(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" "*"}}}])

但我不断收到此 CORS 错误:

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.

知道我需要做什么吗?

Access-Control-Allow-HeadersAccess-Control-Allow-Origin headers 应该由服务器而不是客户端设置。删除它们可能足以修复它?

简单修复:

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

这对我有用:

(re-frame/dispatch [::re-graph/init 
                      {:ws nil
                       :http {:url "http://api.example.com/graphql"                              
                              :impl {:oauth-token token
                                     :with-credentials? false }}}])