Consolidate built-in directive handling and move helpers to Directives class by andimarek · Pull Request #4229 · graphql-java/graphql-java

@andimarek @claude

…y in SchemaPrinter

Remove GraphQLSchema.Builder.clearDirectives() as it allows removing
spec-required built-in directives, which arguably violates the spec.
All 7 built-in directives are now always present.

Change SchemaPrinter to synthesize @specifiedBy from the first-class
specifiedByUrl property on GraphQLScalarType, matching how @deprecated
already uses the first-class deprecationReason property. This ensures
both directives rely on their first-class properties as the source of
truth rather than applied directives.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

and others added 3 commits

January 28, 2026 13:19
…s class

All 7 built-in directives are now handled uniformly in buildImpl() via
ensureBuiltInDirectives(), fixing the inconsistency where @include/@Skip
were pre-populated in the Builder field initializer while the other 5
were force-added in buildImpl(). This eliminates a potential duplicate
directive bug when SchemaTransformer replaces a built-in directive.

Add BUILT_IN_DIRECTIVES set, BUILT_IN_DIRECTIVES_MAP, and
isBuiltInDirective() methods to the Directives class. Deprecate
DirectiveInfo in favor of these new Directives methods. Update all
internal callers to use Directives directly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
DirectiveInfo is fully replaced by methods in Directives:
BUILT_IN_DIRECTIVES, BUILT_IN_DIRECTIVES_MAP, isBuiltInDirective().

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Instead of creating a synthetic applied directive object just to feed
it into the directive printing pipeline, print @specifiedBy directly
from the first-class specifiedByUrl property as a simple string.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@andimarek andimarek changed the title Remove clearDirectives and fix @specifiedBy in SchemaPrinter Consolidate built-in directive handling and move helpers to Directives class

Jan 28, 2026

@andimarek @claude

Verifies that a built-in directive (e.g. @deprecated) can be modified
by adding a new argument through SchemaTransformer, and that all other
built-in directives remain unchanged after the transformation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

rstata pushed a commit to rstata/graphql-java that referenced this pull request

Mar 2, 2026
PR graphql-java#4229 removed `clearDirectives()` from `GraphQLSchema.Builder` as
part of unifying built-in directive handling. However, as noted in
issue graphql-java#4259, this method is useful when using `GraphQLSchema.transform`
to replace all non-built-in directives: the typical pattern is to
collect the non-built-in directives from the source schema, call
`clearDirectives()` on the builder, then add back transformed versions
of those directives.

The new implementation clears `additionalDirectives` entirely.
Built-in directives are always re-added automatically at build time by
`ensureBuiltInDirectives()`, so they cannot be permanently removed
through this method. This treats all built-ins uniformly, consistent
with the approach introduced in graphql-java#4229.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>