Skip to content

Commit c88cc30

Browse files
committed
Note on omission of schema definition
1 parent aace4b1 commit c88cc30

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

spec/Section 2 -- Language.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,26 +1018,46 @@ SchemaDefinition : schema { OperationTypeDefinition+ }
10181018

10191019
OperationTypeDefinition : OperationType : NamedType
10201020

1021-
A GraphQL Type System includes exactly one Schema Definition, which defines
1022-
the type to be used for each operation.
1021+
A GraphQL Type System includes at most one Schema Definition, which defines
1022+
the *root types* to be used for each operation.
10231023

1024-
In this example, a GraphQL schema is defined with both query and mutation types:
1024+
In this example, a GraphQL schema is defined with both query and mutation
1025+
root types:
10251026

10261027
```graphql
10271028
schema {
1028-
query: QueryRoot
1029-
mutation: MutationRoot
1029+
query: MyQueryRootType
1030+
mutation: MyMutationRootType
10301031
}
10311032

1032-
type QueryRoot {
1033+
type MyQueryRootType {
10331034
someField: String
10341035
}
10351036

1036-
type MutationRoot {
1037+
type MyMutationRootType {
10371038
setSomeField(to: String): String
10381039
}
10391040
```
10401041

1042+
**Default Root Types**
1043+
1044+
While any type can be the *root type* for a GraphQL query or mutation operation,
1045+
GraphQL type system definitions can omit the schema definition when the query
1046+
and mutation root types are named `Query` and `Mutation`, respectively.
1047+
1048+
Similarly, when serializing a GraphQL schema using the type system language, a
1049+
schema definition should be omitted if only uses the default root type names.
1050+
1051+
This example describes a valid complete GraphQL schema, despite not explicitly
1052+
including a schema definition. The `Query` type is presumed to be the query
1053+
root type of the schema.
1054+
1055+
```graphql
1056+
type Query {
1057+
someField: String
1058+
}
1059+
```
1060+
10411061

10421062
### Type Definition
10431063

spec/Section 5 -- Validation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ For this section of this schema, we will assume the following type system
3636
in order to demonstrate examples:
3737

3838
```
39+
type Query {
40+
dog: Dog
41+
}
42+
3943
enum DogCommand { SIT, DOWN, HEEL }
4044
4145
type Dog implements Pet {
@@ -76,10 +80,6 @@ type Cat implements Pet {
7680
union CatOrDog = Cat | Dog
7781
union DogOrHuman = Dog | Human
7882
union HumanOrAlien = Human | Alien
79-
80-
type QueryRoot {
81-
dog: Dog
82-
}
8383
```
8484

8585

@@ -532,7 +532,7 @@ and unions without subfields are disallowed.
532532
Let's assume the following additions to the query root type of the schema:
533533

534534
```
535-
extend type QueryRoot {
535+
extend type Query {
536536
human: Human
537537
pet: Pet
538538
catOrDog: CatOrDog
@@ -617,7 +617,7 @@ type Arguments {
617617
booleanListArgField(booleanListArg: [Boolean]!): [Boolean]
618618
}
619619
620-
extend type QueryRoot {
620+
extend type Query {
621621
arguments: Arguments
622622
}
623623
```
@@ -1479,7 +1479,7 @@ For these examples, consider the following typesystem additions:
14791479
```
14801480
input ComplexInput { name: String, owner: String }
14811481
1482-
extend type QueryRoot {
1482+
extend type Query {
14831483
findDog(complex: ComplexInput): Dog
14841484
booleanList(booleanListArg: [Boolean!]): Boolean
14851485
}

0 commit comments

Comments
 (0)