Skip to content

Add validation rule that operation types exist #955

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 20 commits into
base: main
Choose a base branch
from
Open
Changes from 19 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
45 changes: 45 additions & 0 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,51 @@ extend type Dog {

## Operations

### All Operation Definitions

#### Operation Type Existence

**Formal Specification**

- For each operation definition {operation} in the document:
- Let {rootOperationType} be the _root operation type_ in {schema}
corresponding to the kind of {operation}.
- {rootOperationType} must exist.
Copy link
Member

@JoviDeCroock JoviDeCroock Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- {rootOperationType} must exist.
- {rootOperationType} must be defined in {schema}.

or schema without curlies, I see both in the other algorithms

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have existing algorithms that follow this pattern, e.g.

- Let {argumentDefinition} be the argument definition provided by the parent
field or definition named {argumentName}.
- {argumentDefinition} must exist.


**Explanatory Text**

A schema defines the _root operation type_ for each kind of operation that it
supports. Every schema must support `query` operations, however support for
`mutation` and `subscription` operations is optional.

If the schema does not include the necessary _root operation type_ for the kind
of an operation defined in the document, that operation is invalid since it
cannot be executed.

For example given the following schema:

```graphql example
type Query {
hello: String
}
```

The following operation is valid:

```graphql example
query helloQuery {
hello
}
```

While the following operation is invalid:

```graphql example
mutation goodbyeMutation {
goodbye
}
```

### Named Operation Definitions

#### Operation Name Uniqueness
Expand Down
Loading