用Python请求处理Graphql变异
我正在尝试使用waveapps API。看来我的变异手术做得不对 我想创建一个。下面是我的代码:用Python请求处理Graphql变异,python,python-requests,graphql,Python,Python Requests,Graphql,我正在尝试使用waveapps API。看来我的变异手术做得不对 我想创建一个。下面是我的代码: query = """ mutation ($input: MoneyTransactionCreateInput!) {moneyTransactionCreate(input: $input) {moneyTransaction {id externalId date description anchor{accountId amount direction} lineItems[{accoun
query = """ mutation ($input: MoneyTransactionCreateInput!) {moneyTransactionCreate(input: $input) {moneyTransaction {id externalId date description anchor{accountId amount direction} lineItems[{accountId amount balance}]}}}"""
moneyTransaction = {'businessId':'5ODAtNzQ3OS00ZGQ4LTg5NWYtMzU4ZWNiNDNmMTI2',
'externalId':'21', 'date':'2020-05-16', 'description':'my money', 'anchor':{'accountId':'1',
'amount':'15.00', 'direction':'DEPOSIT'},
'lineItems':[{'accountId':'1', 'amount':'15.00', 'balance':'CREDIT'}]}
variables = {'input': moneyTransaction}
rex = requests.post(wave_url, json={'query':query, 'variables':variables}, headers=after_headers)
我得到了这个错误:
'{"errors":[{"extensions":{"id":"e6b88a8d-a5f8-4331-80db-191dbb319690","code":"GRAPHQL_PARSE_FAILED"},"message":"Syntax Error: Expected Name, found [","locations":[{"line":1,"column":183}]}]}\n'
我遗漏了一些东西,但无法找出问题所在。我是Graphql新手 您的查询中有多余的方括号。方括号仅在指定列表类型时使用——在选择集中不需要使用它们
mutation ($input: MoneyTransactionCreateInput!) {
moneyTransactionCreate(input: $input) {
moneyTransaction {
id
externalId
date
description
anchor {
accountId
amount
direction
}
lineItems {
accountId
amount
balance
}
}
}
}
这也奏效了
mutation ($inputMoneyTransactionCreate: MoneyTransactionCreateInput!) {
moneyTransactionCreate(input: $inputMoneyTransactionCreate) {
didSucceed
inputErrors {
code
message
path
}
}
}
和变量已更改为:
variables = {'inputMoneyTransactionCreate': moneyTransaction}