Repository navigation
Resolvers: accept null and absence for every nullable argument - #1881
Open
keenbeen32 wants to merge 1 commit into
Open
keenbeen32 wants to merge 1 commit into
keenbeen32 wants to merge 1 commit into
Conversation
An argument declared `S.optional(x)` is published as a nullable GraphQL type, but its schema takes only `undefined`, so an explicit `null` failed the whole call with "Expected int32 | undefined, received null". A client cannot always avoid sending one: Hasura delivers a variable the caller did not provide as `null`, including one used inside an input object. The mirror case failed too: a null-typed argument, also published as nullable, refused being left out. Before parsing, the spelling a position's schema refuses is now rewritten to the one it accepts: null to absent for an optional, absent to null for a null-typed schema. This follows the positions the manifest publishes -- arguments, `defineInput` fields and array elements -- and the declared schema still does the parsing, so defaults, refinements and conversions are unchanged, and a default applies to null as it does to absence. Left as they were: required positions still refuse both, a schema that already takes null (a JSON scalar) still hands the handler that null, and the value inside a named scalar is not looked into. A resolver with no nullable argument is not walked at all. Co-authored-by: claude <noreply@anthropic.com>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A resolver argument declared
S.optional(x)is published as a nullable GraphQL type (to: Int), but its schema accepts onlyundefined. An explicitnullfailed the call:A client cannot always avoid sending
null. Against Hasura v2.43.0, a variable that is declared but not provided reaches the action handler asnull, both as an argument and inside an input object (where: { to: $to }). The mirror case failed as well: a null-typed argument, also published as nullable, rejected being left out.Change
Before parsing,
dispatch.jsrewrites the spelling a position's schema refuses into the one it accepts:null→ absentnullIt follows the positions the manifest publishes (arguments,
defineInputfields, array elements), so what is accepted matches what is published. The declared schema still does all the parsing.Behaviour
S.optional(S.int32),nullundefineddefineInput,nullundefinednullundefinedS.optional(S.int32, 7),null7S.array(S.optional(x)),[1, null][1, undefined]nullor omittedunknown(JSON),nullnullnulldefineScalartypeNo change to the manifest, SDL, wire contract or Hasura metadata. Declarations that already use
nullishkeep working.Tests
ResolverNullArgs.test.ts(15 tests): each row above, nested inputs, an input type that lists itself, defaults, refinements, conversions, and that the request's own arguments are not mutated.null, nothing and a value to every position (61 positions): nullable ones accept all three, required ones refusenulland absence./hasura-actionover HTTP.Performance
Dispatch time per request, handler doing nothing (median of 7 runs of 300k):
The walk plan is built once per resolver on its first request.
Wiki impact: none.
🤖 Generated with Claude Code