这个函数将返回所有用户而不是给定的用户名,我怎样才能使它正确?还有更好的 Python GraphQL 客户端吗? gql 太简单了,没有太多文档可以检查。
def fetch_user(username):
query = gql("""
query getUser($username: String) {
user(
where: { name: { _eq: $username } }
) {
id
name
}
}
""")
result = client.execute(query)
您可以在中使用变量graphql-python/gql https://github.com/graphql-python/gql在...的帮助下variable_values
范围。
这是我使用该变量的代码片段。
query = gql("""
mutation ($paramId: ID!, $paramTitle: String!){
XputPost(id: $paramId, title: $paramTitle){
id
title
}
}
""")
params = {
"paramId": "1",
"paramTitle": "New Post"
}
result = client.execute(query, variable_values=params)
我希望这个答案对你有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)