Skip to content

Allow schema @behavior(onError: ...) without explicit root operations #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: error-behavior2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions spec/Appendix B -- Grammar Summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :

Expand Down
53 changes: 42 additions & 11 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -216,14 +219,23 @@ 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_,
- the schema does not have a description, and
- the schema uses the {"PROPAGATE"} _default error behavior_.

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
Expand Down Expand Up @@ -259,6 +271,27 @@ type Mutation {
}
```

<!-- https://github.com/prettier/prettier/issues/17286 -->
<!-- prettier-ignore -->
This example describes a valid GraphQL schema with a description, _default
error behavior_ of {"NO\_PROPAGATE"}, and both a {`query`} and {`mutation`}
operation type:

```graphql example
"""
Example schema
"""
schema @behavior(onError: NO_PROPAGATE)

type Query {
someField: String
}

type Mutation {
someMutation: String
}
```

### Schema Extension

SchemaExtension :
Expand Down Expand Up @@ -2187,7 +2220,5 @@ In this example, the schema indicates it is using the {"NO\_PROPAGATE"} _default
error behavior_:

```graphql example
schema @behavior(onError: NO_PROPAGATE) {
query: Query
}
schema @behavior(onError: NO_PROPAGATE)
```