Enums GRAPHQL基于枚举查找项

Enums GRAPHQL基于枚举查找项,enums,graphql,prisma,graphiql,Enums,Graphql,Prisma,Graphiql,我正在尝试查找与某个枚举匹配的结果,这是我的类型: type User { id: ID! @id fname:String! lname:String! email:String! @unique password: String school_ID: String #@relation(Link: INLINE) role: [Role] @scalarList(strategy: RELATION) resetToken: String resetTok

我正在尝试查找与某个枚举匹配的结果,这是我的
类型

type User {
  id: ID! @id
  fname:String!
  lname:String!
  email:String! @unique
  password: String
  school_ID: String #@relation(Link: INLINE)
  role: [Role] @scalarList(strategy: RELATION)
  resetToken: String
  resetTokenExpiry: String
}
我可以搜索电子邮件,因为它有
@unique
键,但是
角色
是一个枚举,我不能向它添加
@unique
键,这是有意义的,因为结果不会是唯一的

然而,我一直得到这样的信息:

“变量\“$\u v0\”,其中\“获取了无效值{\“角色\:\“教师\”};字段\“角色\”未由类型UserWhereUniqueInput定义。”

如果我想使用电子邮件查找项目,则使用电子邮件可以得到我想要的结果

我要做的是获得一个数组返回,其中所有对象都与所选枚举结果匹配

在我的模式中,我有:

users: [User]!
user(where: UserWhereInput!): User
findUser(role: Role, id: ID, email: String): User
在我的查询解析器中,我正在使用以下内容:

  users: forwardTo('db'),
  user: forwardTo('db'),

  async findUser(parent, args, ctx, info) {
    return ctx.db.query.user({
      where: {email: args.email, id: args.id, role: args.role}
    }, info)
  },
我正在使用prisma(1.17.1)生成模式


如何更改代码或
findUser
函数以获得所需结果?

您正在使用带有以下签名的
ctx.db.query.user
函数:

user: (where: UserWhereUniqueInput) => UserNullablePromise;
如您所见,它需要
UserWhereUniqueInput
type where条件。为什么?因为用户函数应该始终只返回一个不同的唯一对象。另一方面,还有一个
ctx.db.query.users
函数:

  users: (args?: {
    where?: UserWhereInput;
    orderBy?: UserOrderByInput;
    skip?: Int;
    after?: String;
    before?: String;
    first?: Int;
    last?: Int;
  }) => FragmentableArray<User>;
用户:(args?:{
where?:UserWhereInput;
orderBy?:UserOrderByInput;
跳过?:Int;
后?:字符串;
前?:字符串;
第一:Int;
最后?:Int;
})=>碎片数组;
如您所见,此函数有更多选项,并使用
UserWhereInput
定义where条件。这还包括您案例中用户的角色。此函数可以返回多个对象,并由您进行相应的筛选/处理


提示:您也可以自己检查生成的prisma客户端。路径通常类似于
src\generated\prisma client\index.ts
。在这里,您可以看到所有函数的接口定义,例如
UserWhereUniqueInput
以及
UserWhereInput
。通过这种方式,您可以检查哪些是可能的,哪些不是

这个问题似乎是针对普里斯玛的,而不是格拉普或阿波罗。您应该相应地更新标记,并指出您正在运行的Prisma的版本。@DanielRearden done:-)-我仍然认为它与GraphQL有关,因为我正在整理我的模式