Skip to content

Resolvers: accept null and absence for every nullable argument - #1881

Open
keenbeen32 wants to merge 1 commit into
kv/custom-resolvers-3.17.1-extrasfrom
kv/resolvers-null-args
Open

keenbeen32 wants to merge 1 commit into
kv/custom-resolvers-3.17.1-extrasfrom
kv/resolvers-null-args

Conversation

@keenbeen32

Copy link
Copy Markdown
Contributor

Problem

A resolver argument declared S.optional(x) is published as a nullable GraphQL type (to: Int), but its schema accepts only undefined. An explicit null failed the call:

Invalid arguments for 'x': Failed parsing at ["to"]. Reason: Expected int32 | undefined, received null

A client cannot always avoid sending null. Against Hasura v2.43.0, a variable that is declared but not provided reaches the action handler as null, 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.js rewrites the spelling a position's schema refuses into the one it accepts:

  • optional position, value null → absent
  • null-typed position, absent → null

It follows the positions the manifest publishes (arguments, defineInput fields, array elements), so what is accepted matches what is published. The declared schema still does all the parsing.

Behaviour

Case Before After
S.optional(S.int32), null rejected handler gets undefined
optional field in a defineInput, null rejected undefined
optional input object / array / enum / BigInt, null rejected undefined
S.optional(S.int32, 7), null rejected 7
S.array(S.optional(x)), [1, null] rejected [1, undefined]
null-typed argument, omitted rejected accepted
required argument or field, null or omitted rejected rejected
optional scalar over unknown (JSON), null handler gets null handler gets null
value inside a defineScalar type not inspected not inspected

No change to the manifest, SDL, wire contract or Hasura metadata. Declarations that already use nullish keep working.

Tests

  • New 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.
  • A property test walks the published manifest and sends null, nothing and a value to every position (61 positions): nullable ones accept all three, required ones refuse null and absence.
  • One case through /hasura-action over HTTP.
  • Resolver suite: 132 passing (116 before, 16 added).
  • Each branch of the walker was disabled in turn; a test fails for every one except the shortcut that skips resolvers with nothing nullable, which has no observable behaviour.
  • Checked end to end behind a real Hasura v2.43.0: 21 query shapes, 13 failed before, the 2 that must fail (required argument) are the only failures after.

Performance

Dispatch time per request, handler doing nothing (median of 7 runs of 300k):

Arguments Before After
none nullable ~141 ns ~150 ns (within noise)
nested input, 10 nullable positions, all present ~157 ns ~256 ns
nested input, optional fields absent ~117 ns ~183 ns

The walk plan is built once per resolver on its first request.

Wiki impact: none.

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b95cc759-3774-46b2-9348-4511036f0b40

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

This branch was previously deployed

1 inactive deployment
internal — baa27cc4 Deployed Nov 25, 2026 by keenbeen32 via authorize #4404
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.

1 participant