Skip to content

Strip T | null unions in mutation engine via replace()#73

Merged
FionaBronwen merged 2 commits intofeature/graphqlfrom
fionabronwen/graphql-null-handling
Apr 8, 2026
Merged

Strip T | null unions in mutation engine via replace()#73
FionaBronwen merged 2 commits intofeature/graphqlfrom
fionabronwen/graphql-null-handling

Conversation

@FionaBronwen
Copy link
Copy Markdown

Summary

  • Use MutationNode.replace() to swap T | null wrapper unions with the inner type, so downstream code sees the unwrapped type instead of a two-variant union
  • Track nullability via the setNullable() state map
  • Extract getNullableUnionType() from isNullableWrapper() to support the replace() call

Motivation

Previously, nullable wrapper unions (string | null, Dog | null) were kept structurally intact — the mutation called mutate() and marked the source union as nullable. This meant downstream code had to re-detect T | null structurally. With replace(), the union node is swapped out in the mutation graph and parent edges (e.g. a ModelProperty's type) update automatically. After mutation, property.type is the string scalar, not string | null.

Test plan

  • Updated 3 existing nullable union tests to assert mutatedType.kind is the inner type (Scalar / Model) rather than Union
  • Updated assertions to check isNullable on mutation.mutatedType instead of the source union
  • Added new test: T | null on a model property is unwrapped to the inner type at the property level

@FionaBronwen FionaBronwen force-pushed the fionabronwen/graphql-null-handling branch 2 times, most recently from e5fb312 to 294c410 Compare April 3, 2026 21:22
@FionaBronwen FionaBronwen marked this pull request as ready for review April 3, 2026 21:34
@FionaBronwen FionaBronwen removed the request for review from swatkatz April 3, 2026 21:34
Comment thread packages/graphql/src/mutation-engine/mutations/union.ts
Comment thread packages/graphql/test/mutation-engine/graphql-mutation-engine.test.ts Outdated
Comment thread packages/graphql/src/lib/type-utils.ts Outdated
Replace nullable wrapper unions (T | null) with the inner type using
MutationNode.replace(), so downstream code sees the unwrapped type.
Nullability is tracked via the setNullable() state map.

Extracts getNullableUnionType() from isNullableWrapper() to support
the replace() call.
@FionaBronwen FionaBronwen force-pushed the fionabronwen/graphql-null-handling branch from 294c410 to 2e79dcf Compare April 6, 2026 21:27
@FionaBronwen FionaBronwen requested a review from steverice April 6, 2026 21:53
@FionaBronwen FionaBronwen merged commit cc9d4fb into feature/graphql Apr 8, 2026
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.

2 participants