Graphiql: Variables Object wrapped in double quotes

Created on 9 May 2016  Â·  6Comments  Â·  Source: graphql/graphiql

According to the GraphQL spec, the variables key in the body should be sent as an Object.
GraphiQL client sends this as a string which can cause unexpected behaviour on other GraphQL servers which follow the spec.

operationName:"getFilms"
query:"query getFilms($first: Int){↵  allFilms(first: $first) {↵    edges {↵      node {↵        id↵        title↵      }↵    }↵  }↵}↵"
variables:"{"first": 2}"

Most helpful comment

The official graphql website states that the variables should be json object: http://graphql.org/learn/serving-over-http/#post-request

All 6 comments

:bump:

Just curious, what's the alternative to strings when sending data over HTTP? How _should_ it be sent?

In Ruby, I parse the incoming value like this:

variables_string = params["variables"]
# => "{\"first\": 2}"
variables_hash = JSON.parse(variables_string)
# => { "first" => 2 }

Would that work in the above case?

Hi @WilliamHolmes, I'm not sure if I understand your question - could I ask you for more information? I'm looking through the specification document and am not seeing anything that mentions in which type variables should be passed in as. What's the unexpected behavior you're having trouble with?

Closing this aging issue.

For some context - there really many other ways to provide this information to a web service. Get & Post data typically expects a set of keyed strings.

Also, there is no spec for GraphQL servers, however best practices are encoded in the behavior of express-graphql.

Also note that GraphiQL is just a UI element and intentionally requires you to provide your own "fetcher" to handle the network. You absolutely don't have to copy the one from the example in this repo, you can format the request to your server however your server requires it.

The official graphql website states that the variables should be json object: http://graphql.org/learn/serving-over-http/#post-request

Quotes are only added by GraphiQL when introspecting through a GET request, not when using POST. Still present in 0.7.2.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nishchit14 picture Nishchit14  Â·  5Comments

ganemone picture ganemone  Â·  4Comments

acao picture acao  Â·  4Comments

lielran picture lielran  Â·  3Comments

lukaszczapiga picture lukaszczapiga  Â·  5Comments