Skip to content

Commit a6535f3

Browse files
author
Travis CI
committed
Input & Output type definition
Throughtout the spec we refer to input and output types but never clearly define them in a referenced section. This adds that section and removes the ad-hoc descriptions from elsewhere in the spec. It also uses the formal algorithms in place of prose where relevant. Finally it adds to the schema validation rules for Object, Interface, and Input Object fields / arguments.
1 parent 8b9d351 commit a6535f3

File tree

3 files changed

+64
-21
lines changed

3 files changed

+64
-21
lines changed

spec/Section 3 -- Type System.md

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,34 @@ referred to as "named types". A wrapping type has an underlying named type,
272272
found by continually unwrapping the type until a named type is found.
273273

274274

275+
### Input and Output Types
276+
277+
Types are used throughout GraphQL to describe both the values accepted as input
278+
to arguments and variables as well as the values output by fields. These two
279+
uses categorize types as *input types* and *output types*. Some kinds of types,
280+
like Scalar and Enum types, can be used as both input types and output types;
281+
other kinds types can only be used in one or the other. Input Object types can
282+
only be used as input types. Object, Interface, and Union types can only be used
283+
as output types. Lists and Non-Null types may be used as input types or output
284+
types depending on how the wrapped type may be used.
285+
286+
IsInputType(type) :
287+
* If {type} is a List type or Non-Null type:
288+
* Let {unwrappedType} be the unwrapped type of {type}.
289+
* Return IsInputType({unwrappedType})
290+
* If {type} is a Scalar, Enum, or Input Object type:
291+
* Return {true}
292+
* Return {false}
293+
294+
IsOutputType(type) :
295+
* If {type} is a List type or Non-Null type:
296+
* Let {unwrappedType} be the unwrapped type of {type}.
297+
* Return IsOutputType({unwrappedType})
298+
* If {type} is a Scalar, Object, Interface, Union, or Enum type:
299+
* Return {true}
300+
* Return {false}
301+
302+
275303
### Type Extensions
276304

277305
TypeExtension :
@@ -757,10 +785,16 @@ Object types have the potential to be invalid if incorrectly defined. This set
757785
of rules must be adhered to by every Object type in a GraphQL schema.
758786

759787
1. An Object type must define one or more fields.
760-
2. The fields of an Object type must have unique names within that Object type;
761-
no two fields may share the same name.
762-
3. Each field of an Object type must not have a name which begins with the
763-
characters {"__"} (two underscores).
788+
2. For each field of an Object type:
789+
1. The field must have a unique name within that Object type;
790+
no two fields may share the same name.
791+
2. The field must not have a name which begins with the
792+
characters {"__"} (two underscores).
793+
3. The field must return a type where {IsOutputType(fieldType)} returns {true}.
794+
4. For each argument of the field:
795+
1. The argument must not have a name which begins with the
796+
characters {"__"} (two underscores).
797+
2. The argument must accept a type where {IsInputType(argumentType)} returns {true}.
764798
4. An object type may declare that it implements one or more unique interfaces.
765799
5. An object type must be a super-set of all interfaces it implements:
766800
1. The object type must include a field of the same name for every field
@@ -834,7 +868,8 @@ May yield the result:
834868
}
835869
```
836870

837-
The type of an object field argument can be any Input type.
871+
The type of an object field argument must be an input type (any type except an
872+
Object, Interface, or Union type).
838873

839874

840875
### Field Deprecation
@@ -1009,10 +1044,18 @@ Interfaces are never valid inputs.
10091044
Interface types have the potential to be invalid if incorrectly defined.
10101045

10111046
1. An Interface type must define one or more fields.
1012-
2. The fields of an Interface type must have unique names within that Interface
1013-
type; no two fields may share the same name.
1014-
3. Each field of an Interface type must not have a name which begins with the
1015-
characters {"__"} (two underscores).
1047+
2. For each field of an Interface type:
1048+
1. The field must have a unique name within that Interface type;
1049+
no two fields may share the same name.
1050+
2. The field must not have a name which begins with the
1051+
characters {"__"} (two underscores).
1052+
3. The field must return a type where {IsOutputType(fieldType)}
1053+
returns {true}.
1054+
4. For each argument of the field:
1055+
1. The argument must not have a name which begins with the
1056+
characters {"__"} (two underscores).
1057+
2. The argument must accept a type where {IsInputType(argumentType)}
1058+
returns {true}.
10161059

10171060

10181061
### Interface Extensions
@@ -1360,9 +1403,13 @@ Literal Value | Variables | Coerced Value
13601403
**Type Validation**
13611404

13621405
1. An Input Object type must define one or more input fields.
1363-
2. The fields of an Input Object type must have unique names within that
1364-
Input Object type; no two fields may share the same name.
1365-
3. The return types of each defined field must be an Input type.
1406+
2. For each input field of an Input Object type:
1407+
1. The input field must have a unique name within that Input Object type;
1408+
no two input fields may share the same name.
1409+
2. The input field must not have a name which begins with the
1410+
characters {"__"} (two underscores).
1411+
3. The input field must accept a type where {IsInputType(inputFieldType)}
1412+
returns {true}.
13661413

13671414

13681415
### Input Object Extensions

spec/Section 5 -- Validation.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,15 +1531,12 @@ fragment HouseTrainedFragment {
15311531
* For every {operation} in a {document}
15321532
* For every {variable} on each {operation}
15331533
* Let {variableType} be the type of {variable}
1534-
* While {variableType} is {LIST} or {NON_NULL}
1535-
* Let {variableType} be the referenced type of {variableType}
1536-
* {variableType} must be of kind {SCALAR}, {ENUM} or {INPUT_OBJECT}
1534+
* {IsInputType(variableType)} must be {true}
15371535

15381536
**Explanatory Text**
15391537

1540-
Variables can only be scalars, enums, input objects, or lists and non-null
1541-
variants of those types. These are known as input types. Objects, unions,
1542-
and interfaces cannot be used as inputs.
1538+
Variables can only be input types. Objects, unions, and interfaces cannot be
1539+
used as inputs.
15431540

15441541
For these examples, consider the following typesystem additions:
15451542

spec/Section 6 -- Execution.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ CoerceVariableValues(schema, operation, variableValues):
8282
* For each {variableDefinition} in {variableDefinitions}:
8383
* Let {variableName} be the name of {variableDefinition}.
8484
* Let {variableType} be the expected type of {variableDefinition}.
85-
* Assert: {variableType} must be an input type.
85+
* Assert: {IsInputType(variableType)} must be {true}.
8686
* Let {defaultValue} be the default value for {variableDefinition}.
8787
* Let {hasValue} be {true} if {variableValues} provides a value for the
8888
name {variableName}.
@@ -556,8 +556,7 @@ ExecuteField(objectType, objectValue, fieldType, fields, variableValues):
556556

557557
Fields may include arguments which are provided to the underlying runtime in
558558
order to correctly produce a value. These arguments are defined by the field in
559-
the type system to have a specific input type: Scalars, Enum, Input Object, or
560-
List or Non-Null wrapped variations of these three.
559+
the type system to have a specific input type.
561560

562561
At each argument position in a query may be a literal {Value}, or a {Variable}
563562
to be provided at runtime.

0 commit comments

Comments
 (0)