ashkan18 / graphlient

Ruby GraphQL Client
MIT License
251 stars 44 forks source link

Bad encoding of the variables #34

Closed axos88 closed 7 years ago

axos88 commented 7 years ago

Based on http://graphql.org/learn/serving-over-http/#post-request, the variables should be sent over as a JSON object, since it is a JSON document after all.

Currently graphlient encodes the json, and sends it over as a string:

{
  "query":"query IntrospectionQuery {\n  __schema {\n    queryType {\n      name\n    }\n    mutationType {\n      name\n    }\n    subscriptionType {\n      name\n    }\n    types {\n      ...FullType\n    }\n    directives {\n      name\n      description\n      locations\n      args {\n        ...InputValue\n      }\n    }\n  }\n}\n\nfragment FullType on __Type {\n  kind\n  name\n  description\n  fields(includeDeprecated: true) {\n    name\n    description\n    args {\n      ...InputValue\n    }\n    type {\n      ...TypeRef\n    }\n    isDeprecated\n    deprecationReason\n  }\n  inputFields {\n    ...InputValue\n  }\n  interfaces {\n    ...TypeRef\n  }\n  enumValues(includeDeprecated: true) {\n    name\n    description\n    isDeprecated\n    deprecationReason\n  }\n  possibleTypes {\n    ...TypeRef\n  }\n}\n\nfragment InputValue on __InputValue {\n  name\n  description\n  type {\n    ...TypeRef\n  }\n  defaultValue\n}\n\nfragment TypeRef on __Type {\n  kind\n  name\n  ofType {\n    kind\n    name\n    ofType {\n      kind\n      name\n      ofType {\n        kind\n        name\n        ofType {\n          kind\n          name\n          ofType {\n            kind\n            name\n            ofType {\n              kind\n              name\n              ofType {\n                kind\n                name\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}",
  "operationName":"IntrospectionQuery",
  "variables":"{}"
}

Due to this we had to introduce unnecessary complexity in the server to parse that string into a JSON hash, if it's given as a string, and leave it as is when it's coming from comforming clients.

dblock commented 7 years ago

I think you're right, per spec a GET should pass query parameters, but a POST should send application/json. This should be fairly easy to fix, feel free to beat me at a PR :)

axos88 commented 7 years ago

I'm leaving for vacation tomorrow, so I guess you will win this time :)

dblock commented 7 years ago

Released as 0.2.0.