简体   繁体   English

Apollo 客户端和 graphQl 查询错误:变量 '$where' 类型的期望值 'OrganizationWhereUniqueInput

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

相关问题 Apollo客户端Graphql查询变量类型错误 - Apollo client Graphql query variable type error GraphQL Apollo:在 apollo 客户端查询中未提供变量错误,尽管我认为我设置了变量 - GraphQL Apollo: Variable was not provided error in apollo client query, although I think I set the variable 如何使用 Apollo GraphQL 更改查询值(其中:{}) - How change query value (where : { }) with Apollo GraphQL Apollo Server - GraphQL 错误:只能有一种名为“查询”的类型 - Apollo Server - GraphQL Error: There can be only one type named "Query" 反应中的奇怪错误 - 使用阿波罗/客户端 - graphql - Weird error in react - using apollo/client - graphql GraphQL 错误:预期未定义为 GraphQL 类型 - GraphQL Error: Expected undefined to be a GraphQL type 获取所需类型“String”的错误变量“$name”。 没有提供。 在从 React-Apollo 发出 Graphql 请求时 - Getting Error Variable “$name” of required type “String!” was not provided. on firing Graphql request from React-Apollo GraphQL错误:$ completedAt的默认值与React Apollo中的DateTime类型不匹配? - GraphQL error: Default value for $completedAt doesn't match type DateTime in React Apollo? 在 Javascript 中使用 GraphQL + Apollo 客户端查询具有部分字符串匹配的数据 - Query data with partial string match using GraphQL + Apollo client in Javascript 无法转换/规范化/修改 GraphQL 查询的响应 - Apollo Client - Can't transform/normalize/modify response of GraphQL query - Apollo Client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM