简体   繁体   中英

Graphql saying Validation error of type undefined

So I am running a gql query on a React app and passing some default variables. But when the query runs I'm getting this error:

Error: GraphQL error: Validation error of type FieldUndefined: Field 'firstname' in type 'HealthcareWorkersPage' is undefined @ 'healthcareWorkers/firstname'

This is the query in the.js file:

export const GET_PROFILES = gql`query healthcareWorkers($pageNo: Int = 0, $pageSize:Int =  6) {
        healthcareWorkers(pageNo: $pageNo, pageSize: $pageSize) {
            firstname
        }
    }`;

Earlier the above query was:

export const GET_PROFILES = gql`query {
healthcareWorkers($pageNo: Int = 0, $pageSize:Int =  6) {
        healthcareWorkers(pageNo: $pageNo, pageSize: $pageSize) {
            firstname
        }
    }
    }`;

Notice the {} after the query keyword. But in this case I got an error saying Syntax Error: Expected Name, found $

I use this query on the playground and it works without any issues:

    query{
  healthcareWorkers(pageNo: 1, pageSize:6) {
    healthcareWorkers {
      firstname
    }
  }
}

The healthcareWorkers Schema: 架构

firstname field lives inside healthcareWorkers type. Try this query:

export const GET_PROFILES = gql`
  query healthcareWorkers($pageNo: Int = 0, $pageSize: Int = 6) {
    healthcareWorkers(pageNo: $pageNo, pageSize: $pageSize) {
      healthcareWorkers {
        firstname
      }
    }
  }
`;

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