Search code examples
clojuregraphqlclojurescript

Connecting re-graph graphql client for clojurescript to lacinia-pedestal graphql server


I am using lacinia-pedestal for server and re-graph for client side clojuresript

My client code looks like

(re-frame/dispatch [::re-graph/init {:http-url 
                      "http://localhost:8888/graphql"
                     :ws-url nil
                    :http-parameters {:headers {"Content-Type" "application/graphql"}                                                         
                    }}])
 (re-frame/dispatch [::re-graph/query
                     "{current_user(token: ss) {id}}"  
                      nil some-func])

However when I connect to my server, I see following error in console log

"message":"Failed to parse GraphQL query.","extensions":{"errors":[{"locations":[{"line":1,"column":null}],"message":"mismatched input '\"query\"' expecting {'query', 'mutation', 'subscription', '...', NameId}"}

Following curl request it works,

curl http://localhost:8888/graphql 
    -H 'Content-Type: application/graphql' 
    -d 'query {
        current_user(token: "foo"){
           id
        }}'

Any help will be appreciated

I am attaching my network console log

enter image description here


Solution

  • re-graph uses application/json by default to send the query and variables as a JSON payload. You don't need to override the content-type in your init call.