Skip to content

Re-add GraphQLSchema.Builder.clearDirectives()#4276

Merged
andimarek merged 1 commit intographql-java:masterfrom
rstata:is-4259
Mar 2, 2026
Merged

Re-add GraphQLSchema.Builder.clearDirectives()#4276
andimarek merged 1 commit intographql-java:masterfrom
rstata:is-4259

Conversation

@rstata
Copy link

@rstata rstata commented Mar 2, 2026

Summary

PR #4229 removed clearDirectives() from GraphQLSchema.Builder as part of unifying built-in directive handling. As noted in issue #4259, this method is useful in practice: a common pattern when using GraphQLSchema.transform is to collect the non-built-in directives from the source schema, call clearDirectives() on the builder, and then add back transformed versions of those directives.

This PR re-adds clearDirectives() with semantics that are consistent with the approach introduced in #4229:

  • Clears additionalDirectives entirely (including any explicitly-added built-ins)
  • Built-in directives are always re-added automatically at build time by ensureBuiltInDirectives(), so they cannot be permanently removed — all built-ins are treated uniformly

Changes

  • Re-adds Builder.clearDirectives() to GraphQLSchema with Javadoc illustrating the transform use case
  • Adds tests covering:
    • clearDirectives() followed by build() still yields all 7 built-in directives
    • clearDirectives() followed by adding a custom directive yields the expected set
    • The primary use case: using clearDirectives() in a schema.transform() to replace non-built-in directives
    • Ordering behavior: unoverridden built-ins sort first, then user-supplied directives in insertion order; customized built-ins retain their custom properties

Related

Fixes #4259. See also #4229.

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>
@andimarek
Copy link
Member

Thanks

@andimarek andimarek merged commit bae794f into graphql-java:master Mar 2, 2026
7 checks passed
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.

Did PR #4229 go too far?

2 participants