From 470358cb7cf3b5dc79643a4b5c7d141a30f0fdb5 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 30 Apr 2025 12:39:37 +0100 Subject: [PATCH] Enable 'schema' keyword to be provided without root operations --- spec/Appendix B -- Grammar Summary.md | 7 +++-- spec/Section 3 -- Type System.md | 45 ++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/spec/Appendix B -- Grammar Summary.md b/spec/Appendix B -- Grammar Summary.md index 92f222cb3..40c41ef79 100644 --- a/spec/Appendix B -- Grammar Summary.md +++ b/spec/Appendix B -- Grammar Summary.md @@ -258,8 +258,11 @@ TypeSystemExtension : - SchemaExtension - TypeExtension -SchemaDefinition : Description? schema Directives[Const]? { -RootOperationTypeDefinition+ } +SchemaDefinition : + +- Description? schema Directives[Const]? { RootOperationTypeDefinition+ } +- Description? schema Directives[Const] [lookahead != `{`] +- Description schema [lookahead != {`{`, `@`}] SchemaExtension : diff --git a/spec/Section 3 -- Type System.md b/spec/Section 3 -- Type System.md index 47d3efb3d..c53365122 100644 --- a/spec/Section 3 -- Type System.md +++ b/spec/Section 3 -- Type System.md @@ -115,8 +115,11 @@ enum Language { ## Schema -SchemaDefinition : Description? schema Directives[Const]? { -RootOperationTypeDefinition+ } +SchemaDefinition : + +- Description? schema Directives[Const]? { RootOperationTypeDefinition+ } +- Description? schema Directives[Const] [lookahead != `{`] +- Description schema [lookahead != {`{`, `@`}] RootOperationTypeDefinition : OperationType : NamedType @@ -216,14 +219,22 @@ type MyMutationRootType { {`subscription`} _root operation type_ are {"Query"}, {"Mutation"}, and {"Subscription"} respectively. -The type system definition language can omit the schema definition when each -_root operation type_ uses its respective _default root type name_ and no other -type uses any _default root type name_. +The type system definition language can omit the schema definition's root +operation type definitions when each _root operation type_ uses its respective +_default root type name_ and no other type uses any _default root type name_. + +The type system definition language can omit the schema definition entirely when +all of the following hold: + +- each _root operation type_ uses its respective _default root type name_, +- no other type uses any _default root type name_, and +- the schema does not have a description. Likewise, when representing a GraphQL schema using the type system definition -language, a schema definition should be omitted if each _root operation type_ -uses its respective _default root type name_ and no other type uses any _default -root type name_. +language, a schema definition should be omitted if all of the above conditions +hold; otherwise the schema definition's root operation type definitions should +be omitted if each _root operation type_ uses its respective _default root type +name_ and no other type uses any _default root type name_. This example describes a valid complete GraphQL schema, despite not explicitly including a {`schema`} definition. The {"Query"} type is presumed to be the @@ -259,6 +270,24 @@ type Mutation { } ``` +This example describes a valid GraphQL schema with a description and both a +{`query`} and {`mutation`} operation type: + +```graphql example +""" +Example schema +""" +schema + +type Query { + someField: String +} + +type Mutation { + someMutation: String +} +``` + ### Schema Extension SchemaExtension :