[英]Apollo client and graphQl query error : Variable '$where' expected value of type 'OrganizationWhereUniqueInput
嗨,我正在使用 GraphQL、Apollo 客户端和 Prisma 制作后端服务器。 我正在尝试编写一个查询来获取组织数据。 发送查询的用户应该根据他们的 id 取回其组织数据。 在操场上运行查询时,出现此错误。
错误:
"message": "Variable '$where' expected value of type 'OrganizationWhereUniqueInput!' but got: {\"employees\":{\"id\":\"ckas83z13t9qk0992pucglc4k\"}}. Reason: 'employees' Field 'employees' is not defined in the input type 'OrganizationWhereUniqueInput'. (line 1, column 8):\nquery ($where: OrganizationWhereUniqueInput!) {\n ^",
我看不出我做错了什么。 我对这一切还是很陌生。 我尝试以不同的方式在Query.js
中编写 function 但没有运气。 此外,我仍然发现您在操场上收到的错误消息非常令人困惑
架构:
type Query {
getOrganization: Organization!
}
type Organization {
id: ID!
name: String!
country: String!
street: String!
zipCode: Int!
houseNumber: Int!
addings: String
employees: [User!]
}
type User {
id: ID!
firstname:String!
lastname:String!
email: String!
services: [Service!]
organization: Organization!
}
查询.js
function getOrganization(parent, args, context, info){
const userId = getUserId(context)
return context.prisma.organization({employees:{id:userId}})
}
// also tried this
/*
function getOrganization(parent, args, context, info){
const userId = getUserId(context)
return context.prisma.organization({where: {employees:{id:userId}}})
}*/
用户.js
function services (parent, args, context){
return context.prisma.user({id: parent.id}).services()
}
function organization (parent, args, context){
return context.prisma.user({id: parent.id}).organization()
}
module.exports={
services,
organization
}
组织.js
function employees(parent, args, context){
return context.prisma.organization({id: parent.id}).employees()
}
module.exports={
employees
}
谁能帮我看看出了什么问题?
在操场上查询:
query{
getOrganization{
name
id
}}
HTTP HEADER:
{
"Authorization": "Bearer {contains user token }"
}
只需使用OrganizationWhereInput而不是OrganizationWhere Unique Input 。 它将返回组织列表而不是单个结果(可能返回空数组),但它应该允许您使用员工 ID 搜索组织。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.