@@ -122,7 +122,7 @@ RootOperationTypeDefinition : OperationType : NamedType
122
122
123
123
A GraphQL service's collective type system capabilities are referred to as that
124
124
service's "schema". A schema is defined in terms of the types and directives it
125
- supports as well as the root operation types for each kind of operation: query,
125
+ supports as well as the _ root operation type _ for each kind of operation: query,
126
126
mutation, and subscription; this determines the place in the type system where
127
127
those operations begin.
128
128
@@ -141,24 +141,24 @@ introspection system.
141
141
142
142
### Root Operation Types
143
143
144
- A schema defines the initial root operation type for each kind of operation it
145
- supports: query, mutation, and subscription; this determines the place in the
144
+ :: A schema defines the initial _ root operation type _ for each kind of operation
145
+ it supports: query, mutation, and subscription; this determines the place in the
146
146
type system where those operations begin.
147
147
148
- The {` query ` } root operation type must be provided and must be an Object type.
148
+ The {` query ` } _ root operation type _ must be provided and must be an Object type.
149
149
150
- The {` mutation ` } root operation type is optional; if it is not provided, the
150
+ The {` mutation ` } _ root operation type _ is optional; if it is not provided, the
151
151
service does not support mutations. If it is provided, it must be an Object
152
152
type.
153
153
154
- Similarly, the {` subscription ` } root operation type is also optional; if it is
154
+ Similarly, the {` subscription ` } _ root operation type _ is also optional; if it is
155
155
not provided, the service does not support subscriptions. If it is provided, it
156
156
must be an Object type.
157
157
158
158
The {` query ` }, {` mutation ` }, and {` subscription ` } root types must all be
159
159
different types if provided.
160
160
161
- The fields on the {` query ` } root operation type indicate what fields are
161
+ The fields on the {` query ` } _ root operation type _ indicate what fields are
162
162
available at the top level of a GraphQL query operation.
163
163
164
164
For example, this example operation:
@@ -169,16 +169,17 @@ query {
169
169
}
170
170
```
171
171
172
- is only valid when the {` query ` } root operation type has a field named "myName":
172
+ is only valid when the {` query ` } _ root operation type_ has a field named
173
+ "myName":
173
174
174
175
``` graphql example
175
176
type Query {
176
177
myName : String
177
178
}
178
179
```
179
180
180
- Similarly , the following mutation is only valid if the {`mutation `} root
181
- operation type has a field named "setName" .
181
+ Similarly , the following mutation is only valid if the {`mutation `} _root
182
+ operation type_ has a field named "setName" .
182
183
183
184
```graphql example
184
185
mutation {
@@ -191,8 +192,8 @@ mutation {
191
192
When using the type system definition language, a document must include at most
192
193
one {` schema ` } definition.
193
194
194
- In this example, a GraphQL schema is defined with both query and mutation root
195
- operation types :
195
+ In this example, a GraphQL schema is defined with both a query and mutation
196
+ _ root operation type _ :
196
197
197
198
``` graphql example
198
199
schema {
@@ -211,25 +212,53 @@ type MyMutationRootType {
211
212
212
213
**Default Root Operation Type Names **
213
214
214
- While any type can be the root operation type for a GraphQL operation , the type
215
- system definition language can omit the schema definition when the {`query`},
216
- {`mutation `}, and {`subscription `} root types are named {"Query" }, {"Mutation" },
217
- and {"Subscription" } respectively .
215
+ :: The _default root type name_ for each {`query `}, {`mutation `}, and
216
+ {`subscription `} _root operation type_ are {"Query" }, {"Mutation" }, and
217
+ {"Subscription" } respectively .
218
+
219
+ The type system definition language can omit the schema definition when each
220
+ _root operation type_ uses its respective _default root type name_ and no other
221
+ type uses any _default root type name_.
218
222
219
223
Likewise, when representing a GraphQL schema using the type system definition
220
- language, a schema definition should be omitted if it only uses the default root
221
- operation type names.
224
+ language, a schema definition should be omitted if each _root operation type_
225
+ uses its respective _default root type name_ and no other type uses any _default
226
+ root type name_.
222
227
223
228
This example describes a valid complete GraphQL schema, despite not explicitly
224
229
including a {`schema`} definition . The {"Query" } type is presumed to be the
225
- {`query `} root operation type of the schema .
230
+ {`query `} _root operation type_ of the schema .
226
231
227
232
```graphql example
228
233
type Query {
229
234
someField : String
230
235
}
231
236
```
232
237
238
+ This example describes a valid GraphQL schema without a {` mutation ` } _ root
239
+ operation type_ , even though it contains a type named {"Mutation"}. The schema
240
+ definition must be included, otherwise the {"Mutation"} type would be
241
+ incorrectly presumed to be the {` mutation ` } _ root operation type_ of the schema.
242
+
243
+ ``` graphql example
244
+ schema {
245
+ query : Query
246
+ }
247
+
248
+ type Query {
249
+ latestVirus : Virus
250
+ }
251
+
252
+ type Virus {
253
+ name : String
254
+ mutations : [Mutation ]
255
+ }
256
+
257
+ type Mutation {
258
+ name : String
259
+ }
260
+ ```
261
+
233
262
### Schema Extension
234
263
235
264
SchemaExtension :
@@ -325,7 +354,7 @@ IsInputType(type) :
325
354
- Return IsInputType ({unwrappedType})
326
355
- If {type } is a Scalar , Enum , or Input Object type :
327
356
- Return {true }
328
- - Return {false}
357
+ - Return {false }.
329
358
330
359
IsOutputType (type) :
331
360
@@ -334,7 +363,7 @@ IsOutputType(type) :
334
363
- Return IsOutputType ({unwrappedType})
335
364
- If {type } is a Scalar , Object , Interface , Union , or Enum type :
336
365
- Return {true }
337
- - Return {false}
366
+ - Return {false }.
338
367
339
368
### Type Extensions
340
369
@@ -405,12 +434,17 @@ conform to its described rules.
405
434
```graphql example
406
435
scalar UUID @specifiedBy (url : " https://tools.ietf.org/html/rfc4122" )
407
436
scalar URL @specifiedBy (url : " https://tools.ietf.org/html/rfc3986" )
437
+ scalar DateTime
438
+ @specifiedBy (url : " https://scalars.graphql.org/andimarek/date-time" )
408
439
```
409
440
410
441
Custom *scalar specification URL*s should provide a single, stable format to
411
442
avoid ambiguity. If the linked specification is in flux, the service should link
412
443
to a fixed version rather than to a resource which might change.
413
444
445
+ Note: Some community-maintained custom scalar specifications are hosted at
446
+ [scalars.graphql.org](https://scalars.graphql.org/).
447
+
414
448
Custom *scalar specification URL*s should not be changed once defined. Doing so
415
449
would likely disrupt tooling or could introduce breaking changes within the
416
450
linked specification's contents.
@@ -419,7 +453,9 @@ Built-in scalar types must not provide a _scalar specification URL_ as they are
419
453
specified by this document.
420
454
421
455
Note: Custom scalars should also summarize the specified format and provide
422
- examples in their description .
456
+ examples in their description; see the GraphQL scalars
457
+ [implementation guide](https://scalars.graphql.org/implementation-guide) for
458
+ more guidance.
423
459
424
460
**Result Coercion and Serialization**
425
461
@@ -878,9 +914,11 @@ of rules must be adhered to by every Object type in a GraphQL schema.
878
914
4. For each argument of the field :
879
915
1. The argument must not have a name which begins with the characters
880
916
{"\_\_" } (two underscores).
881
- 2. The argument must accept a type where {IsInputType (argumentType)}
917
+ 2. The argument must have a unique name within that field ; no two
918
+ arguments may share the same name .
919
+ 3. The argument must accept a type where {IsInputType (argumentType)}
882
920
returns {true }.
883
- 3 . If argument type is Non -Null and a default value is not defined :
921
+ 4 . If argument type is Non -Null and a default value is not defined :
884
922
- The `@deprecated ` directive must not be applied to this argument .
885
923
3. An object type may declare that it implements one or more unique interfaces .
886
924
4. An object type must be a super -set of all interfaces it implements :
@@ -1228,7 +1266,9 @@ Interface types have the potential to be invalid if incorrectly defined.
1228
1266
4. For each argument of the field :
1229
1267
1. The argument must not have a name which begins with the characters
1230
1268
{"\_\_" } (two underscores).
1231
- 2. The argument must accept a type where {IsInputType (argumentType)}
1269
+ 2. The argument must have a unique name within that field ; no two
1270
+ arguments may share the same name .
1271
+ 3. The argument must accept a type where {IsInputType (argumentType)}
1232
1272
returns {true }.
1233
1273
3. An interface type may declare that it implements one or more unique
1234
1274
interfaces , but may not implement itself .
@@ -1756,8 +1796,9 @@ to denote a field that uses a Non-Null type like this: `name: String!`.
1756
1796
**Nullable vs . Optional **
1757
1797
1758
1798
Fields are _always_ optional within the context of a selection set , a field may
1759
- be omitted and the selection set is still valid . However fields that return
1760
- Non -Null types will never return the value {null } if queried .
1799
+ be omitted and the selection set is still valid (so long as the selection set
1800
+ does not become empty). However fields that return Non -Null types will never
1801
+ return the value {null } if queried .
1761
1802
1762
1803
Inputs (such as field arguments), are always optional by default . However a
1763
1804
non -null input type is required . In addition to not accepting the value {null },
@@ -2004,7 +2045,9 @@ repeatable directives.
2004
2045
4. For each argument of the directive :
2005
2046
1. The argument must not have a name which begins with the characters
2006
2047
{"\_\_" } (two underscores).
2007
- 2. The argument must accept a type where {IsInputType (argumentType)} returns
2048
+ 2. The argument must have a unique name within that directive ; no two
2049
+ arguments may share the same name .
2050
+ 3. The argument must accept a type where {IsInputType (argumentType)} returns
2008
2051
{true }.
2009
2052
2010
2053
### @skip
@@ -2110,6 +2153,9 @@ behavior of [custom scalar types](#sec-Scalars.Custom-Scalars). The URL should
2110
2153
point to a human-readable specification of the data format, serialization, and
2111
2154
coercion rules. It must not appear on built-in scalar types.
2112
2155
2156
+ Note : Details on implementing a GraphQL scalar specification can be found in the
2157
+ [scalars .graphql .org implementation guide ](https ://scalars .graphql .org /implementation -guide ).
2158
+
2113
2159
In this example , a custom scalar type for `UUID ` is defined with a URL pointing
2114
2160
to the relevant IETF specification .
2115
2161
0 commit comments