Skip to content

Leaf field selections clarification #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,16 @@ fragment conflictingDifferingResponses on Pet {
**Formal Specification**

- For each {selection} in the document:
- Let {selectionType} be the result type of {selection}.
- Let {selectionType} be the unwrapped result type of {selection}.
- If {selectionType} is a scalar or enum:
- The subselection set of that selection must be empty.
- If {selectionType} is an interface, union, or object:
- The subselection set of that selection must NOT BE empty.

**Explanatory Text**

Field selections on scalars or enums are never allowed, because they are the
leaf nodes of any GraphQL operation.
A field subselection is not allowed on leaf fields. A leaf field is any field
with a scalar or enum unwrapped type.

The following is valid.

Expand All @@ -604,9 +604,8 @@ fragment scalarSelectionsNotAllowedOnInt on Dog {
}
```

Conversely the leaf field selections of GraphQL operations must be of type
scalar or enum. Leaf selections on objects, interfaces, and unions without
subfields are disallowed.
Conversely, non-leaf fields must have a field subselection. A non-leaf field is
any field with an object, interface, or union unwrapped type.

Let's assume the following additions to the query root operation type of the
schema:
Expand All @@ -619,7 +618,8 @@ extend type Query {
}
```

The following examples are invalid
The following examples are invalid because they include non-leaf fields without
a field subselection.

```graphql counter-example
query directQueryOnObjectWithoutSubFields {
Expand All @@ -635,6 +635,16 @@ query directQueryOnUnionWithoutSubFields {
}
```

However the following example is valid since it includes a field subselection.

```graphql example
query directQueryOnObjectWithSubFields {
human {
name
}
}
```

## Arguments

Arguments are provided to both fields and directives. The following validation
Expand Down