GraphQL 查询验证定义与我的实现有何不同?

How should the GraphQL Query validation definition differ from my implementation?

使用以下类型定义和查询:


export const typeDefs = gql`
    type Query {
        getLocations: [Location]
    }...
    type Location {
        id: ID!
        name: String!
    }`
query {
  getLocations
}

我收到错误消息:

Field \"getLocations\" of type \"[Location]\" must have a selection of subfields. Did you mean \"getLocations { ... }\"

查询 return 一个 Location 对象数组,但验证失败。查看了 graphql 和 apollo-graphql 文档并疯狂地用谷歌搜索了这个错误,它似乎是正确的实现。是否还有其他可能对此产生影响的因素?

在请求某些内容时,您必须 select 架构类型的子字段。在这里,您请求一个类型为 Location 的数组,其中包含 idname。您必须将其中之一添加到 return 如下所示

这应该可以消除该错误。

query {
  getLocations{
   id
   name
  }
}

希望对您有所帮助!