Skip to content

Commit de54332

Browse files
committed
Note on omission of schema definition
1 parent 86cecd9 commit de54332

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
@@ -976,26 +976,46 @@ SchemaDefinition : schema { OperationTypeDefinition+ }
976976

977977
OperationTypeDefinition : OperationType : NamedType
978978

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

982-
In this example, a GraphQL schema is defined with both query and mutation types:
982+
In this example, a GraphQL schema is defined with both query and mutation
983+
root types:
983984

984985
```graphql
985986
schema {
986-
query: QueryRoot
987-
mutation: MutationRoot
987+
query: MyQueryRootType
988+
mutation: MyMutationRootType
988989
}
989990

990-
type QueryRoot {
991+
type MyQueryRootType {
991992
someField: String
992993
}
993994

994-
type MutationRoot {
995+
type MyMutationRootType {
995996
setSomeField(to: String): String
996997
}
997998
```
998999

1000+
**Default Root Types**
1001+
1002+
While any type can be the *root type* for a GraphQL query or mutation operation,
1003+
GraphQL type system definitions can omit the schema definition when the query
1004+
and mutation root types are named `Query` and `Mutation`, respectively.
1005+
1006+
Similarly, when serializing a GraphQL schema using the type system language, a
1007+
schema definition should be omitted if only uses the default root type names.
1008+
1009+
This example describes a valid complete GraphQL schema, despite not explicitly
1010+
including a schema definition. The `Query` type is presumed to be the query
1011+
root type of the schema.
1012+
1013+
```graphql
1014+
type Query {
1015+
someField: String
1016+
}
1017+
```
1018+
9991019

10001020
### Type Definition
10011021

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

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

473473
```
474-
extend type QueryRoot {
474+
extend type Query {
475475
human: Human
476476
pet: Pet
477477
catOrDog: CatOrDog
@@ -556,7 +556,7 @@ type Arguments {
556556
booleanListArgField(booleanListArg: [Boolean]!): [Boolean]
557557
}
558558
559-
extend type QueryRoot {
559+
extend type Query {
560560
arguments: Arguments
561561
}
562562
```
@@ -1365,7 +1365,7 @@ For these examples, consider the following typesystem additions:
13651365
```
13661366
input ComplexInput { name: String, owner: String }
13671367
1368-
extend type QueryRoot {
1368+
extend type Query {
13691369
findDog(complex: ComplexInput): Dog
13701370
booleanList(booleanListArg: [Boolean!]): Boolean
13711371
}

0 commit comments

Comments
 (0)