Skip to content

Commit 15b8b40

Browse files
authored
RFC: SchemaExtension (#428)
* RFC: SchemaExtension This adds new grammar to the GraphQL SDL: ```graphql extend schema { mutation: MutationType } ``` This feels like the missing piece of the type system extension framework. In addition to extending types in a type system, the top level schema should be extendable as well. * Further separate type system definitions from extensions
1 parent 1d56b88 commit 15b8b40

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

spec/Appendix B -- Grammar Summary.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Document : Definition+
9696
Definition :
9797
- ExecutableDefinition
9898
- TypeSystemDefinition
99+
- TypeSystemExtension
99100

100101
ExecutableDefinition :
101102
- OperationDefinition
@@ -187,11 +188,18 @@ Directive[Const] : @ Name Arguments[?Const]?
187188
TypeSystemDefinition :
188189
- SchemaDefinition
189190
- TypeDefinition
190-
- TypeExtension
191191
- DirectiveDefinition
192192

193+
TypeSystemExtension :
194+
- SchemaExtension
195+
- TypeExtension
196+
193197
SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ }
194198

199+
SchemaExtension :
200+
- extend schema Directives[Const]? { OperationTypeDefinition+ }
201+
- extend schema Directives[Const]
202+
195203
OperationTypeDefinition : OperationType : NamedType
196204

197205
Description : StringValue

spec/Section 2 -- Language.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ Document : Definition+
171171
Definition :
172172
- ExecutableDefinition
173173
- TypeSystemDefinition
174+
- TypeSystemExtension
174175

175176
ExecutableDefinition :
176177
- OperationDefinition
@@ -181,9 +182,9 @@ by a GraphQL service or client. A document contains multiple definitions, either
181182
executable or representative of a GraphQL type system.
182183

183184
Documents are only executable by a GraphQL service if they contain an
184-
{OperationDefinition}, only contain {ExecutableDefinition} and do not contain
185-
{TypeSystemDefinition}. However documents which do not contain
186-
{OperationDefinition} or do contain {TypeSystemDefinition} may still be parsed
185+
{OperationDefinition} and otherwise only contain {ExecutableDefinition}.
186+
However documents which do not contain {OperationDefinition} or do contain
187+
{TypeSystemDefinition} or {TypeSystemExtension} may still be parsed
187188
and validated to allow client tools to represent many GraphQL uses which may
188189
appear across many individual files.
189190

@@ -195,8 +196,8 @@ multiple operations to a GraphQL service, the name of the desired operation to
195196
be executed must also be provided.
196197

197198
GraphQL services which only seek to provide GraphQL query execution may choose
198-
to only include {ExecutableDefinition} and omit the {TypeSystemDefinition} rule
199-
from {Definition}.
199+
to only include {ExecutableDefinition} and omit the {TypeSystemDefinition} and
200+
{TypeSystemExtension} rules from {Definition}.
200201

201202

202203
## Operations

spec/Section 3 -- Type System.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ are valid.
88
TypeSystemDefinition :
99
- SchemaDefinition
1010
- TypeDefinition
11-
- TypeExtension
1211
- DirectiveDefinition
1312

1413
The GraphQL language includes an
@@ -27,6 +26,18 @@ Note: The type system definition language is used throughout the remainder of
2726
this specification document when illustrating example type systems.
2827

2928

29+
## Type System Extensions
30+
31+
TypeSystemExtension :
32+
- SchemaExtension
33+
- TypeExtension
34+
35+
Type system extensions are used to represent a GraphQL type system which has been
36+
extended from some original type system. For example, this might be used by a
37+
local service to represent data a GraphQL client only accesses locally, or by a
38+
GraphQL service which is itself an extension of another GraphQL service.
39+
40+
3041
## Schema
3142

3243
SchemaDefinition : schema Directives[Const]? { RootOperationTypeDefinition+ }
@@ -139,6 +150,16 @@ type Query {
139150
}
140151
```
141152

153+
### Schema Extension
154+
155+
SchemaExtension :
156+
- extend schema Directives[Const]? { OperationTypeDefinition+ }
157+
- extend schema Directives[Const]
158+
159+
Schema extensions are used to represent a schema which has been extended from
160+
an original schema. For example, this might be used by a GraphQL service which
161+
adds additional operation types, or additional directives to an existing schema.
162+
142163

143164
## Descriptions
144165

@@ -261,10 +282,9 @@ TypeExtension :
261282
- EnumTypeExtension
262283
- InputObjectTypeExtension
263284

264-
Type extensions are used to represent a GraphQL type system which has been
265-
extended from some original type system. For example, this might be used by a
266-
local service to represent data a GraphQL client only accesses locally, or by a
267-
GraphQL service which is itself an extension of another GraphQL service.
285+
Type extensions are used to represent a GraphQL type which has been extended
286+
from some original type. For example, this might be used by a local service to
287+
represent additional fields a GraphQL client only accesses locally.
268288

269289

270290
## Scalars

0 commit comments

Comments
 (0)