Error in graphQL python example code

Question:

I am starting working on GraphQL and as I am from python background I am using GraphQL with Python.
I followed the steps provided here Link but I am still facing issues.

An error occurred while resolving field Query.hello
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/graphql/execution/executor.py", line 311, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/usr/local/lib/python3.5/dist-packages/graphql/execution/executors/sync.py", line 7, in execute
    return fn(*args, **kwargs)
TypeError: resolve_hello() missing 2 required positional arguments: 'context' and 'info'
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/graphql/execution/executor.py", line 330, in complete_value_catching_error
    exe_context, return_type, field_asts, info, result)
  File "/usr/local/lib/python3.5/dist-packages/graphql/execution/executor.py", line 383, in complete_value
    raise GraphQLLocatedError(field_asts, original_error=result)
graphql.error.located_error.GraphQLLocatedError: resolve_hello() missing 2 required positional arguments: 'context' and 'info'
None

Please, help me resolve the issue.

Asked By: Aniruddh Agarwal

||

Answers:

You are not giving much information here, maybe the code that triggers the error would be helpful, but googling I found some related posts

https://github.com/graphql-python/graphene/issues/601

https://github.com/graphql-python/graphene-django/issues/282

Maybe check the versions that you are using as they mention on the first link

Answered By: ipop

It looks like the graphQL documentation is out of date. Graphene-python 2 changed the method signature. Try something like this instead

def resolve_hello(self, info, **kwargs):
    return 'Hello world!'
Answered By: Mark Chackerian

Try to like this one concept example on date:

Graphql required positional arguments
info,and **kwarg

 def resolve_generated_date(self, info, **kwargs):
        created_date = self.created_at.strftime('%Y-%m-%d')
        return created_date
Answered By: Sankar guru
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.