Skip to content

feat(validation): reject directive definition cycles - rewrite #4726#4816

Open
yaacovCR wants to merge 1 commit into
graphql:17.x.xfrom
yaacovCR:fix-fix
Open

feat(validation): reject directive definition cycles - rewrite #4726#4816
yaacovCR wants to merge 1 commit into
graphql:17.x.xfrom
yaacovCR:fix-fix

Conversation

@yaacovCR

Copy link
Copy Markdown
Contributor

Adds a new NoDirectiveDefinitionCyclesRule SDL validation rule that detects cycles in the graph of directives used within directive definitions.

A cycle arises when following the references within directive definitions leads back to the same directive. Two kinds of references are tracked:

  1. Directive argument types — if @foo takes an argument of type InputObject, and InputObject has a field with directive @foo, that forms a cycle: @foo → InputObject → @foo.
  2. Directives on directive definitions — when the experimental experimentalDirectivesOnDirectiveDefinitions parser option is enabled, a directive applied directly to a directive definition or extension is also a reference. If @a is annotated with @b and @b is annotated with @a, that is a cycle: @a → @b → @a.

Cycles make it impossible to build a well-defined schema; the spec already forbids
them
, and experimental directive extensions do the
same
.

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@yaacovCR is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

…l#4726

Adds a new `NoDirectiveDefinitionCyclesRule` SDL validation rule that
detects cycles in the graph of directives used within directive
definitions.

A cycle arises when following the references within directive
definitions leads back to the same directive. Two kinds of references
are tracked:

1. **Directive argument types** — if `@foo` takes an argument of type
`InputObject`, and `InputObject` has a field with directive `@foo`, that
forms a cycle: `@foo → InputObject → @foo`.
2. **Directives on directive definitions** — when the experimental
`experimentalDirectivesOnDirectiveDefinitions` parser option is enabled,
a directive applied directly to a directive definition or extension is
also a reference. If `@a` is annotated with `@b` and `@b` is annotated
with `@a`, that is a cycle: `@a → @b → @a`.

Cycles make it impossible to build a well-defined schema; the spec
already [forbids
them](https://spec.graphql.org/draft/#sec-Type-System.Directives.Type-Validation),
and experimental directive extensions [do the
same](https://github.com/graphql/graphql-spec/pull/1206/changes#diff-30a69c5a5eded8e1aea52e53dad1181e6ec8f549ca2c50570b035153e2de1c43R2342).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant