Repository navigation
fix(graphql): align SDL nullability with introspection for nullable annotations - #321
Merged
Merged
Conversation
…nnotations - compose: _render_struct_type_sdl decided the ! suffix via _is_optional alone and missed Literal[..., None], which its sibling _build_type_ref does handle — SDL and introspection disagreed within the same module. - entity: map_to_sdl no longer forces NON_NULL on output for nullable annotations (Optional[T] / T | None / Literal[..., None]); output SDL now matches map_to_introspection and the Python annotation (#320 option A; behavioral change — such fields lose the ! suffix). - extract annotation_is_nullable as the single predicate for NON_NULL decisions; dedup the Optional-unwrap step shared by literal_info and _literal_constraint (_optional_core); drop literal_allowed_values (no library callers since #318). Fixes #320 Co-Authored-By: Claude Code <noreply@anthropic.com>
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.
Fixes #320
What changed
1. compose SDL render (defect 1) —
_render_struct_type_sdldecided the!suffix with_is_optionalalone, which cannot see aNonemember inside aLiteral(verified:_is_optional(Literal["draft", None])isFalse— theLiteralbranch in_is_optionalcomparestype(None)against the member values, so it never fires). Its sibling_build_type_refin the same module already handled this vialiteral_info. Both renderers now agree:2. entity output SDL (defect 2, option A) —
map_to_sdlno longer forces NON_NULL on output for nullable annotations (Optional[T]/T | None/Literal[..., None]). Output SDL now matchesmap_to_introspectionand the Python annotation itself:!suffix. Introspection output was already nullable for all of these (entity introspection never emitted NON_NULL), so this aligns the two renderers rather than changing what clients execute against.3. Cleanup (from the issue) —
annotation_is_nullable(annotation)ingraphql/type_mapping.pyis the single predicate for NON_NULL decisions; all formernot _is_optional(...)force_non_null computations incompose_schema.pynow use it so SDL and type-ref renders cannot drift again._optional_corededups the Optional-unwrap step previously copied inliteral_infoand_literal_constraint.literal_allowed_valuesremoved — no library callers since fix: preserve nullability in Literal descriptions #318 (tests updated; its coverage is subsumed by the fix: preserve nullability in Literal descriptions #318 parametrized description tests).Verification
pytest tests/: 1005 passed, 1 skipped;pytest demo/(CI also runs it): 92 passed.ruff check: passed.method_sdl, compose introspection (unchanged, was already correct), input side (unchanged) — all consistent; non-nullable literals (status: String!,enabled: Boolean!) keep their!.🤖 Generated with Claude Code