Graphql 说未定义类型的验证错误

Graphql saying Validation error of type undefined

所以我是 运行 React 应用程序上的 gql 查询并传递一些默认变量。但是当查询运行时我得到这个错误:

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

这是 .js 文件中的查询:

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

之前上面的查询是:

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

注意查询关键字后面的{}。但是在这种情况下,我收到一条错误消息 Syntax Error: Expected Name, found $

我在 playground 上使用这个查询,它没有任何问题:

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

healthcareWorkers 架构:

firstname 字段存在于 healthcareWorkers 类型中。试试这个查询:

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