[英]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.