@@ -35,7 +35,7 @@ WhiteSpace ::
35
35
White space is used to improve legibility of source text and act as separation
36
36
between tokens, and any amount of white space may appear before or after any
37
37
token. White space between tokens is not significant to the semantic meaning of
38
- a GraphQL query document , however white space characters may appear within a
38
+ a GraphQL Document , however white space characters may appear within a
39
39
{String} or {Comment} token.
40
40
41
41
@@ -49,7 +49,7 @@ LineTerminator ::
49
49
50
50
Like white space, line terminators are used to improve the legibility of source
51
51
text, any amount may appear before or after any other token and have no
52
- significance to the semantic meaning of a GraphQL query document . Line
52
+ significance to the semantic meaning of a GraphQL Document . Line
53
53
terminators are not found within any other token.
54
54
55
55
@@ -67,8 +67,8 @@ comment always consists of all code points starting with the {`#`} character up
67
67
to but not including the line terminator.
68
68
69
69
Comments behave like white space and may appear after any token, or before a
70
- line terminator, and have no significance to the semantic meaning of a GraphQL
71
- query document .
70
+ line terminator, and have no significance to the semantic meaning of a
71
+ GraphQL Document .
72
72
73
73
74
74
### Insignificant Commas
@@ -77,7 +77,7 @@ Comma :: ,
77
77
78
78
Similar to white space and line terminators, commas ({` , ` }) are used to improve
79
79
the legibility of source text and separate lexical tokens but are otherwise
80
- syntactically and semantically insignificant within GraphQL query documents .
80
+ syntactically and semantically insignificant within GraphQL Documents .
81
81
82
82
Non-significant comma characters ensure that the absence or presence of a comma
83
83
does not meaningfully alter the interpreted syntax of the document, as this can
@@ -98,8 +98,8 @@ Token ::
98
98
A GraphQL document is comprised of several kinds of indivisible lexical tokens
99
99
defined here in a lexical grammar by patterns of source Unicode characters.
100
100
101
- Tokens are later used as terminal symbols in a GraphQL query document syntactic
102
- grammars.
101
+ Tokens are later used as terminal symbols in a GraphQL Document
102
+ syntactic grammars.
103
103
104
104
### Ignored Tokens
105
105
@@ -133,7 +133,7 @@ lacks the punctionation often used to describe mathematical expressions.
133
133
134
134
Name :: /[ _ A-Za-z] [ _0-9A-Za-z ] * /
135
135
136
- GraphQL query documents are full of named things: operations, fields, arguments,
136
+ GraphQL Documents are full of named things: operations, fields, arguments,
137
137
directives, fragments, and variables. All names must follow the same
138
138
grammatical form.
139
139
@@ -145,28 +145,34 @@ Names in GraphQL are limited to this <acronym>ASCII</acronym> subset of possible
145
145
characters to support interoperation with as many other systems as possible.
146
146
147
147
148
- ## Query Document
148
+ ## Document
149
149
150
150
Document : Definition+
151
151
152
152
Definition :
153
153
- OperationDefinition
154
154
- FragmentDefinition
155
+ - TypeDefinition
155
156
156
- A GraphQL query document describes a complete file or request string received by
157
- a GraphQL service. A document contains multiple definitions of Operations and
158
- Fragments. GraphQL query documents are only executable by a server if they
159
- contain an operation. However documents which do not contain operations may
160
- still be parsed and validated to allow client to represent a single request
161
- across many documents.
162
157
163
- If a query document contains only one query operation, that operation may be
158
+ A GraphQL Document describes a complete file or request string operated on
159
+ by a GraphQL service or client tool. A document contains multiple definitions of
160
+ Operations and Fragments, and if consumed by a client tool may also include Type
161
+ Definitions. GraphQL Documents are only executable by a server if they
162
+ contain an Operation but do not contain a Type Definition. However documents
163
+ which do not contain Operations may still be parsed and validated to allow
164
+ client tools to represent a single request across many documents.
165
+
166
+ If a Document contains only one query operation, that operation may be
164
167
represented in the shorthand form, which omits the query keyword and
165
- operation name. Otherwise, if a GraphQL query document contains multiple
166
- operations, each operation must be named. When submitting a query document with
168
+ operation name. Otherwise, if a GraphQL Document contains multiple
169
+ operations, each operation must be named. When submitting a Document with
167
170
multiple operations to a GraphQL service, the name of the desired operation to
168
171
be executed must also be provided.
169
172
173
+ GraphQL implementations which only seek to provide GraphQL query execution may
174
+ omit the {TypeDefinition} rule from Definition.
175
+
170
176
171
177
### Operations
172
178
@@ -873,3 +879,169 @@ FragmentSpreadDirectives(fragmentSpread) :
873
879
* If {directives} does not contain a directive named {directive}.
874
880
* Add {directive} into {directives}
875
881
* Return {directives}
882
+
883
+
884
+ ### Type Definitions
885
+
886
+ TypeDefinition :
887
+ - ObjectTypeDefinition
888
+ - InterfaceTypeDefinition
889
+ - UnionTypeDefinition
890
+ - ScalarTypeDefinition
891
+ - EnumTypeDefinition
892
+ - InputObjectTypeDefinition
893
+ - TypeExtensionDefinition
894
+
895
+
896
+ The GraphQL language also includes an
897
+ [ IDL] ( https://en.wikipedia.org/wiki/Interface_description_language ) used to
898
+ describe a GraphQL service's Type System. Tools may use these definitions to
899
+ provide various utilities such as client code generation or
900
+ service boot-strapping.
901
+
902
+ A GraphQL Document which contains type definitions must not be executed; GraphQL
903
+ execution services which receive a GraphQL Document containing type definitions
904
+ should return a descriptive error.
905
+
906
+ Note: This IDL is used throughout the remainder of this specification document
907
+ when illustrating examples.
908
+
909
+ #### Object
910
+
911
+ ObjectTypeDefinition : type Name ImplementsInterfaces? { FieldDefinition+ }
912
+
913
+ ImplementsInterfaces : implements NamedType+
914
+
915
+ FieldDefinition : Name ArgumentsDefinition? : Type
916
+
917
+ ArgumentsDefinition : ( InputValueDefinition+ )
918
+
919
+ InputValueDefinition : Name : Type DefaultValue?
920
+
921
+ Object types represent a list of named fields, each of which yield a value of a
922
+ specific type. Each field itself may accept a list of named arguments.
923
+
924
+ Objects may implement Interface types. When implementing an Interface type, the
925
+ Object type must supply all fields defined by the Interface.
926
+
927
+ In this example, a Object type called ` TodoItem ` is defined:
928
+
929
+ ``` graphql
930
+ type TodoItem implements Node {
931
+ id : ID
932
+ title : String
933
+ isCompleted : Boolean
934
+ }
935
+ ```
936
+
937
+ #### Interface
938
+
939
+ InterfaceTypeDefinition : interface Name { FieldDefinition+ }
940
+
941
+ Interface types , similarly to Object types represent a list of named fields .
942
+ Interface types are used as the type of a field when one of many possible Object
943
+ types may yielded during execution , but some fields are guaranteed . An Object
944
+ type is a possible type of an Interface when it both declares that it implements
945
+ that Interface as well as includes all defined fields .
946
+
947
+ In this example , an Interface type called `Node ` is defined :
948
+
949
+ ```graphql
950
+ interface Node {
951
+ id : ID
952
+ }
953
+ ```
954
+
955
+ #### Union
956
+
957
+ UnionTypeDefinition : union Name = UnionMembers
958
+
959
+ UnionMembers :
960
+ - NamedType
961
+ - UnionMembers | NamedType
962
+
963
+ Union types represent a list of named Object types . Union types are used as the
964
+ type of a field when one of many possible Object types may yielded during
965
+ execution , and no fields are guaranteed . An Object type is a possible type of a
966
+ Union when it is declared by the Union .
967
+
968
+ In this example , a Union type called `Actor ` is defined :
969
+
970
+ ```graphql
971
+ union Actor = User | Business
972
+ ```
973
+
974
+ #### Scalar
975
+
976
+ ScalarTypeDefinition : scalar Name
977
+
978
+ Scalar types represent leaf values in a GraphQL type system . While this GraphQL
979
+ specification describes a set of Scalar types which all GraphQL services must
980
+ supply , custom Scalar types may be supplied by a GraphQL service . Typically , the
981
+ set of Scalar types described in this specification are omitted from documents
982
+ which describe a schema for brevity.
983
+
984
+ In this example, a Scalar type called `DateTime` is defined:
985
+
986
+ ```graphql
987
+ scalar DateTime
988
+ ```
989
+
990
+ #### Enum
991
+
992
+ EnumTypeDefinition : enum Name { EnumValueDefinition+ }
993
+
994
+ EnumValueDefinition : EnumValue
995
+
996
+ EnumValue : Name
997
+
998
+ Enum types , like Scalar types , also represent leaf values in a GraphQL type
999
+ system . However Enum types describe the set of legal values .
1000
+
1001
+ In this example , an Enum type called `Direction ` is defined :
1002
+
1003
+ ```graphql
1004
+ enum Direction {
1005
+ NORTH
1006
+ EAST
1007
+ SOUTH
1008
+ WEST
1009
+ }
1010
+ ```
1011
+
1012
+ #### Input Object
1013
+
1014
+ InputObjectTypeDefinition : input Name { InputValueDefinition+ }
1015
+
1016
+ Input Object types represent complex input values which may be provided as an
1017
+ field argument. Input Object types cannot be the return type of an Object or
1018
+ Interface field.
1019
+
1020
+ In this example, an Input Object called ` Point2D ` is defined:
1021
+
1022
+ ``` graphql
1023
+ input Point2D {
1024
+ x : Float
1025
+ y : Float
1026
+ }
1027
+ ```
1028
+
1029
+ #### Extension
1030
+
1031
+ TypeExtensionDefinition : extend ObjectTypeDefinition
1032
+
1033
+ Type extensions may be used by client -side tools in order to represent a
1034
+ GraphQL type system which has been extended from the type system exposed via
1035
+ introspection by a GraphQL service , for example to represent fields which a
1036
+ client of GraphQL uses locally , but is not provided by a GraphQL service .
1037
+
1038
+ Any fields or interfaces provided by the extension must not already exist on the
1039
+ Object type .
1040
+
1041
+ In this example , a client only field is added to a `Story ` type :
1042
+
1043
+ ```graphql
1044
+ extend type Story {
1045
+ isHiddenLocally : Boolean
1046
+ }
1047
+ ```
0 commit comments