Python GraphQL 变量未定义
Posted
技术标签:
【中文标题】Python GraphQL 变量未定义【英文标题】:Python GraphQL variable not defined 【发布时间】: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)
我做错了什么?
【问题讨论】:
【参考方案1】:我认为这可能是库本身的错误,如果您可以通过简单的方法将其报告为问题,那就太好了!
【讨论】:
我在这里发布了一个问题:github.com/graphql-python/graphql-server-core/issues/11以上是关于Python GraphQL 变量未定义的主要内容,如果未能解决你的问题,请参考以下文章