简体   繁体   中英

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. 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. 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. 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

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

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

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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM