【问题标题】:Error in graphQL python example codegraphQL python示例代码中的错误
【发布时间】:2018-07-17 15:32:42
【问题描述】:

我开始研究 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

请帮我解决问题。

【问题讨论】:

    标签: python graphql graphene-python


    【解决方案1】:

    graphQL 文档似乎已过时。 Graphene-python 2 更改了方法签名。试试这样的方法

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

    【讨论】:

    • 谢谢,它帮了很多忙。也感谢您纠正我的问题。
    • 我很高兴它有帮助。我编辑了这个问题,以便下一个遇到这个问题的人可以找到它。您应该出于相同的原因接受答案(以便解决方案清晰。)
    • 我同意你的说法.. :)
    【解决方案2】:

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

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

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

    也许检查您使用的版本,正如他们在第一个链接中提到的那样

    【讨论】:

    • 我想我提供了完整的信息。我添加了一个与我已实现的细节相对应的链接。
    猜你喜欢
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多