1
votes

Using the below Type Definition and query:


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

I'm receiving the error:

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

The query does return the an array of Location objects, but the validation fails. Having looked through the graphql and apollo-graphql docs and frantically googled this error it seems to be the proper implementation. Is there anything else that could be impacting this?

1

1 Answers

0
votes

You have to select the subfield of a schema type when requesting something. Here you're requesting an array of type Location which has id and name in it. You must include one of those for it to return something like below

This should get rid of that error.

query {
  getLocations{
   id
   name
  }
}

Hope this helps !