graphql-python / graphql-server

This is the core package for using GraphQL in a custom server easily
MIT License
120 stars 72 forks source link

Variables in get_response() are ignored #11

Closed NiklasRosenstein closed 6 years ago

NiklasRosenstein commented 6 years ago

To reproduce:

import graphene
import graphql_server

class Query(graphene.ObjectType):
  reverse = graphene.String(word=graphene.String())

  def resolve_reverse(self, info, word):
      return word[::-1]

schema = graphene.Schema(query=Query)

params = graphql_server.GraphQLParams('query { reverse(word: $name) }', {'name': "GraphQl User"}, None)
res = graphql_server.get_response(schema, params)
print(res.data)
print(res.errors)

This gives you

None
[GraphQLError('Variable "$name" is not defined.',)]

I have encountered this error using Flask-GraphQL as any variables I pass via the HTTP request are ignored due to this issue.

syrusakbary commented 6 years ago

@NiklasRosenstein you will need to define the variable in the query itself:

You currently have:

query { reverse(word: $name) }

It should be:

query($name: String) { reverse(word: $name) }

Let me know if this fixes the issue.

syrusakbary commented 6 years ago

I will close the issue. But please comment back if you have any further question.