Skip to content

Commit ac483bd

Browse files
benjaminjkraftbenjieShane32
authored
Add validation rule that operation types exist (#955)
* Add validation rule that operation types exist Right now the spec says that, for example, if the schema does not define a mutation root type, then the schema does not support mutations. But there's no validation rule for it, which means that many parsers (including graphql-js) treat a mutation as valid against such a schema. (Indeed, many end up considering *any* mutation as valid, since they don't know what type to validate the root selection set against.) This commit adds a validation rule to make the schema text explicit. Slated for discussion at the June 2 working group meeting. See also graphql/graphql-js#3592. * prettier * typofix Co-authored-by: Benjie Gillam <[email protected]> * indentation Co-authored-by: Benjie Gillam <[email protected]> * Add 5.2.4 Operation Type Configuration * Update spec/Section 5 -- Validation.md * Update spec/Section 5 -- Validation.md * Update spec/Section 5 -- Validation.md * Apply suggestions from code review Co-authored-by: Benjie <[email protected]> * Reformat * Undo changes to Section 3 * Editorial * Move Shane's content * More editorial * More editorial * Update spec/Section 5 -- Validation.md Co-authored-by: Shane Krueger <[email protected]> * Update spec/Section 5 -- Validation.md --------- Co-authored-by: Benjie Gillam <[email protected]> Co-authored-by: Shane Krueger <[email protected]>
1 parent 883c759 commit ac483bd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

spec/Section 5 -- Validation.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,51 @@ extend type Dog {
135135

136136
## Operations
137137

138+
### All Operation Definitions
139+
140+
#### Operation Type Existence
141+
142+
**Formal Specification**
143+
144+
- For each operation definition {operation} in the document:
145+
- Let {rootOperationType} be the _root operation type_ in {schema}
146+
corresponding to the kind of {operation}.
147+
- {rootOperationType} must exist.
148+
149+
**Explanatory Text**
150+
151+
A schema defines the _root operation type_ for each kind of operation that it
152+
supports. Every schema must support `query` operations, however support for
153+
`mutation` and `subscription` operations is optional.
154+
155+
If the schema does not include the necessary _root operation type_ for the kind
156+
of an operation defined in the document, that operation is invalid since it
157+
cannot be executed.
158+
159+
For example given the following schema:
160+
161+
```graphql example
162+
type Query {
163+
hello: String
164+
}
165+
```
166+
167+
The following operation is valid:
168+
169+
```graphql example
170+
query helloQuery {
171+
hello
172+
}
173+
```
174+
175+
While the following operation is invalid:
176+
177+
```graphql counter-example
178+
mutation goodbyeMutation {
179+
goodbye
180+
}
181+
```
182+
138183
### Named Operation Definitions
139184

140185
#### Operation Name Uniqueness

0 commit comments

Comments
 (0)