Skip to content

Build the read-only schema with the code registry and schema directives - #898

Merged
oryan-block merged 2 commits into
masterfrom
bugfix/896
Oct 22, 2026
Merged

oryan-block merged 2 commits into
masterfrom
bugfix/896

Conversation

@oryan-block

Copy link
Copy Markdown
Collaborator

Fixes #896

Checklist

  • Pull requests follows the contribution guide
  • New or modified functionality is covered by tests

Description

SchemaObjects#toReadOnlySchema() failed on any schema with an interface or a union:

graphql.AssertException: There must be a type resolver for interface Animal

It repeated the builder calls of toSchema() without the mutation and subscription, and over time toSchema() got the code registry (where the type resolvers live since graphql-java 13) and the directives applied to the schema, but toReadOnlySchema() didn't. #894 already added the directive definitions, so a custom directive on a field works on master. The code registry and the schema directives were still missing.

So both now start from one private newSchema() builder, and toSchema() only adds the mutation and subscription on top. That way the two can't drift again.

Added ReadOnlySchemaTest, which builds a read-only schema with an interface, a union, a field directive and extend schema @contact(...), queries every field and checks there's no mutation type. It failed with the error above before the fix. mvn clean verify passes on graphql-java 26.1 and 25.1. Also checked through the public API: a schema with an interface and a union failed to build on master, and with this change returns the Cat and Dog values for both on graphql-java 26.1 and 25.1, with mutationType null.

oryan-block and others added 2 commits October 22, 2026 18:10
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ectives

toReadOnlySchema() repeated the builder calls of toSchema() and missed the code registry, so interfaces and unions had no type resolver, and the directives applied to the schema.

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

Copy link
Copy Markdown

@oryan-block
oryan-block merged commit 65d320c into master Oct 22, 2026
7 checks passed
@oryan-block
oryan-block deleted the bugfix/896 branch October 22, 2026 22:16
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.

toReadOnlySchema() fails on schemas with interfaces, unions or custom directives

1 participant