graphQL python示例代码中的错误

时间:2018-02-07 11:01:52

标签: python graphql graphene-python

我开始使用GraphQL,因为我来自python背景,我使用的是GraphQL和Python。 我按照此处提供的步骤进行了Link,但我仍然面临问题。

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

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:3)

看起来graphQL文档已经过时了。 Graphene-python 2改变了方法签名。尝试这样的事情

def resolve_hello(self, info, **kwargs):
    return 'Hello world!'

答案 1 :(得分:0)

你在这里没有提供太多信息,也许触发错误的代码会有所帮助,但谷歌搜索我发现了一些相关的帖子

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

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

也许请检查您在第一个链接上提到的版本