Skip to content

Use @DefaultValue when a primitive argument is explicitly null - #2787

Open
phillip-kruger wants to merge 1 commit into
smallrye:mainfrom
phillip-kruger:fix-1565-e8e95db
Open

phillip-kruger wants to merge 1 commit into
smallrye:mainfrom
phillip-kruger:fix-1565-e8e95db

Conversation

@phillip-kruger

Copy link
Copy Markdown
Member

A primitive argument with @DefaultValue is nullable in the schema (the TCK requires @DefaultValue fields to be nullable), so a client can legally send i: null. ArgumentHelper passed that null on to the method, and reflection failed with an IllegalArgumentException.

When a primitive argument with a default value gets an explicit null, ArgumentHelper now uses the schema default, coerced by graphql-java the same way as when the argument is left out. Wrapped arguments, non-primitives and the generated schema are unchanged.

This covers query and mutation arguments only. Primitive fields in @Input types go through input deserialization and are not part of this change.

PrimitiveDefaultValueTest checks both the absent and the explicit-null case. The explicit-null case fails without the fix.

Fixes #1565

Written with an AI coding agent. I approved the plan and I review this change.

This branch has not been deployed

No deployments
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.

@DefaultValue("0") int x fails with null

2 participants