【发布时间】:2018-07-21 17:32:29
【问题描述】:
我是 graphql 的新手,我正在为查询而苦苦挣扎。 我想通过他们的电子邮件地址返回用户
我有一个类型定义调用 V1User,它有以下字段 ID, 电子邮件, 密码, 角色
此查询需要更改哪些内容才能根据电子邮件返回用户?
query GetAllV1User {
viewer {
allV1Users{
edges {
node {
id
email
role
createdAt
modifiedAt
}
}
}
}
}
我试过这个查询
query getV1UserQuery($email: String!) {
getV1User(email: $email) {
id
email
}
}
使用这些参数
{"email": "test@test.com"}
但是得到以下错误
{
"errors": [
{
"message": "Unknown argument \"email\" on field \"getV1User\" of type \"Query\".",
"locations": [
{
"line": 2,
"column": 13
}
],
"name": "GraphQLError"
},
{
"message": "Field \"getV1User\" argument \"id\" of type \"ID!\" is required but not provided.",
"locations": [
{
"line": 2,
"column": 3
}
],
"name": "GraphQLError"
}
]
}
我的架构如下
Name Type Constraints
id ID NonNull Unique
modifiedAt DateTime NonNull
createdAt DateTime NonNull
role String NonNull
password String NonNull
email String NonNull Unique Indexed
谢谢
嗨
这个查询解决了我的问题
query getUserForEmailAddressAndPassword($where: V1UserWhereArgs) {
viewer {
allV1Users(where: $where) {
edges {
node {
email
id
createdAt
password
modifiedAt
role
}
}
}
}
}
连同这些查询变量
{"where": {"email": {"eq" : "test@test.com"}, "password": {"eq":"te2st"}}}
【问题讨论】:
-
要做到这一点,您必须修改您的查询以获得一些参数。然后在解析器中发送请求中的参数。
-
刚刚更新了我遇到的错误问题
-
您能否提供此查询的架构代码?
-
我正在使用 scaphold.io 创建架构 - 我可以将您添加到我的帐户以查看它吗?
-
我从未使用过 scaphold,但我相信您可以查看架构代码,因此可以将其发布在这里。无论如何,我的第一个猜测是您需要在架构中更新
getV1UserQuery查询
标签: graphql graphql-js