0
votes

GraphQL Error Field "tags" must not have a selection since type "[String]" has no subfields.

I'm working on a GatsbyJS repo. According to the docs, GatsbyJS automatically infers the schema from my markdown files, which implicitly define the type with lines such as tags: ["sayings", "wisdom"]. Surely, GatsbyJS should infer the type to be an array, a list, or something like that. Why does GatsbyJS infer the type to be a String instead?

1

1 Answers

2
votes

While your development server is running, you can access the GraphiQL interface for it at http://localhost:8000/___graphql. GraphiQL is an IDE that can not only lets you write and run queries against your GraphQL server, but also provides a way to view your schema, including the type for each available field. Please see the docs for more info. It includes syntax highlighting, so I would highly recommend it when composing your queries.

The error you are seeing indicates that the field tags is of the type [String]. The brackets here indicate a List (or array) of the type String. String, Int, Float, Boolean and ID are all built-in scalar types. Fields that have a scalar type (or an enum) are considered "lead nodes", and as such, they cannot have a field selection themselves. In other words,

tags {}

is not valid syntax. It has to be just

tags

That is why you are seeing the above error. As it states, the type [String] has no subfields. If hypothetically the type returned by the tags field was an object type, or a list of one, then you would have to specify what fields to return.

You might find it helpful to review GraphQL concepts in more details. This tutorial would be a good starting point, and there's always the specification itself.