Skip to content

Commit

Permalink
Note on omission of schema definition
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Jun 19, 2017
1 parent aace4b1 commit c88cc30
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
34 changes: 27 additions & 7 deletions spec/Section 2 -- Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,26 +1018,46 @@ SchemaDefinition : schema { OperationTypeDefinition+ }

OperationTypeDefinition : OperationType : NamedType

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

In this example, a GraphQL schema is defined with both query and mutation types:
In this example, a GraphQL schema is defined with both query and mutation
root types:

```graphql
schema {
query: QueryRoot
mutation: MutationRoot
query: MyQueryRootType
mutation: MyMutationRootType
}

type QueryRoot {
type MyQueryRootType {
someField: String
}

type MutationRoot {
type MyMutationRootType {
setSomeField(to: String): String
}
```

**Default Root Types**

While any type can be the *root type* for a GraphQL query or mutation operation,
GraphQL type system definitions can omit the schema definition when the query
and mutation root types are named `Query` and `Mutation`, respectively.

Similarly, when serializing a GraphQL schema using the type system language, a
schema definition should be omitted if only uses the default root type names.

This example describes a valid complete GraphQL schema, despite not explicitly
including a schema definition. The `Query` type is presumed to be the query
root type of the schema.

```graphql
type Query {
someField: String
}
```


### Type Definition

Expand Down
14 changes: 7 additions & 7 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ For this section of this schema, we will assume the following type system
in order to demonstrate examples:

```
type Query {
dog: Dog
}
enum DogCommand { SIT, DOWN, HEEL }
type Dog implements Pet {
Expand Down Expand Up @@ -76,10 +80,6 @@ type Cat implements Pet {
union CatOrDog = Cat | Dog
union DogOrHuman = Dog | Human
union HumanOrAlien = Human | Alien
type QueryRoot {
dog: Dog
}
```


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

```
extend type QueryRoot {
extend type Query {
human: Human
pet: Pet
catOrDog: CatOrDog
Expand Down Expand Up @@ -617,7 +617,7 @@ type Arguments {
booleanListArgField(booleanListArg: [Boolean]!): [Boolean]
}
extend type QueryRoot {
extend type Query {
arguments: Arguments
}
```
Expand Down Expand Up @@ -1479,7 +1479,7 @@ For these examples, consider the following typesystem additions:
```
input ComplexInput { name: String, owner: String }
extend type QueryRoot {
extend type Query {
findDog(complex: ComplexInput): Dog
booleanList(booleanListArg: [Boolean!]): Boolean
}
Expand Down

0 comments on commit c88cc30

Please sign in to comment.