【问题标题】:Python GraphQL variable not definedPython GraphQL 变量未定义
【发布时间】:2018-11-21 16:49:35
【问题描述】:

我正在尝试使用 Flask + Flask-GraphQL + Graphene 服务器上的 apollo-boost 客户端执行包含一些变量的 GraphQL 请求。

let data = await client.query({
  query: gql`{
    addItemToReceipt(receiptId: $receiptId, categoryId: $categoryId, value: $value, count: $count) {
      item {
        id
        category { id }
        value
        count
      }
    }
  }`,
  variables: {
    receiptId: this.id,
    categoryId: categoryId,
    value: value,
    count: mult
  }
})

但我收到“未定义变量 X”错误。

[GraphQL error]: Message: Variable "$receiptId" is not defined., Location: [object Object],[object Object], Path: undefined
[GraphQL error]: Message: Variable "$categoryId" is not defined., Location: [object Object],[object Object], Path: undefined
[GraphQL error]: Message: Variable "$value" is not defined., Location: [object Object],[object Object], Path: undefined
[GraphQL error]: Message: Variable "$count" is not defined., Location: [object Object],[object Object], Path: undefined
[Network error]: Error: Response not successful: Received status code 400

我在graphql_server/__init__.py 中添加了一些调试打印

# graphql_server/__init__.py:62
all_params = [get_graphql_params(entry, extra_data) for entry in data]
print(len(all_params))
print(all_params[0])
# ...

但是从我得到的输出来看,一切似乎都很好。 graphql_server.run_http_query() 确实接收所有变量。

GraphQLParams(query='{\n  addItemToReceipt(receiptId: $receiptId, categoryId: $categoryId, value: $value, count: $count) {\n    item {\n      id\n      category {\n        id\n        __typename\n      }\n      value\n      count\n      __typename\n    }\n    __typename\n  }\n}\n', variables={'receiptId': '13', 'categoryId': 'gt', 'value': 0, 'count': 0}, operation_name=None)

我做错了什么?

【问题讨论】:

    标签: python graphql apollo-client graphene-python


    【解决方案1】:

    我认为这可能是库本身的错误,如果您可以通过简单的方法将其报告为问题,那就太好了!

    【讨论】:

    猜你喜欢
    • 2019-06-15
    • 2019-06-08
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    相关资源
    最近更新 更多