[英]Apollo client and graphQl query error : Variable '$where' expected value of type 'OrganizationWhereUniqueInput
Hi I'm making a backend server with GraphQL, Apollo client & Prisma.嗨,我正在使用 GraphQL、Apollo 客户端和 Prisma 制作后端服务器。 I'm trying to write a query where I get organization data back.
我正在尝试编写一个查询来获取组织数据。 The user who sends the query should get its organization data back based on their id.
发送查询的用户应该根据他们的 id 取回其组织数据。 When running the query in playground I get this error.
在操场上运行查询时,出现此错误。
error:错误:
"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 ^",
I don't see what I did wrong.我看不出我做错了什么。 I'm still pretty new to it all.
我对这一切还是很陌生。 I tried to write the function in
Query.js
in different ways but no luck.我尝试以不同的方式在
Query.js
中编写 function 但没有运气。 Also, I still find the error messages you get in playground very confusing此外,我仍然发现您在操场上收到的错误消息非常令人困惑
schema:架构:
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!
}
query.js查询.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}}})
}*/
User.js用户.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
}
Organization.js组织.js
function employees(parent, args, context){
return context.prisma.organization({id: parent.id}).employees()
}
module.exports={
employees
}
Could anyone help me see what went wrong?谁能帮我看看出了什么问题?
query in playground:在操场上查询:
query{
getOrganization{
name
id
}}
HTTP HEADER:
{
"Authorization": "Bearer {contains user token }"
}
Just use OrganizationWhereInput instead of OrganizationWhere Unique Input .只需使用OrganizationWhereInput而不是OrganizationWhere Unique Input 。 It will return a list of organisations instead of a single result (might return an empty array), yet it should allow you to search for an organisation using an employee id.
它将返回组织列表而不是单个结果(可能返回空数组),但它应该允许您使用员工 ID 搜索组织。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.