fix: Always merge multiple GraphQL schemas before parsing#2873
fix: Always merge multiple GraphQL schemas before parsing#2873koxudaxi merged 5 commits intokoxudaxi:mainfrom
Conversation
📝 WalkthroughWalkthroughAggregate multiple GraphQL source texts into a single unified schema before parsing; remove the per-source path-context helper Changes
Sequence Diagram(s)(omitted — changes consolidate internal parser behavior; no multi-component sequential flow meeting diagram criteria) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2873 +/- ##
==========================================
- Coverage 99.38% 99.38% -0.01%
==========================================
Files 91 91
Lines 15648 15643 -5
Branches 1849 1848 -1
==========================================
- Hits 15552 15547 -5
Misses 50 50
Partials 46 46
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/datamodel_code_generator/parser/graphql.py (1)
1-1: Pipeline failure: Commit the auto-fixed lint changes.The Ruff linter auto-fixed 5 import-related issues. Please commit these changes to pass CI.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
tests/data/graphql/split/a.graphqlis excluded by!tests/data/**/*.graphqland included by nonetests/data/graphql/split/b.graphqlis excluded by!tests/data/**/*.graphqland included by nonetests/data/graphql/split/c.graphqlis excluded by!tests/data/**/*.graphqland included by none
📒 Files selected for processing (3)
src/datamodel_code_generator/parser/graphql.pytests/data/expected/main/graphql/split_graphql_schemas.pytests/main/graphql/test_main_graphql.py
🧰 Additional context used
🧬 Code graph analysis (3)
src/datamodel_code_generator/parser/graphql.py (1)
src/datamodel_code_generator/parser/base.py (1)
iter_source(1033-1056)
tests/main/graphql/test_main_graphql.py (2)
tests/test_main_kr.py (1)
output_file(44-46)tests/main/conftest.py (2)
output_file(98-100)run_main_and_assert(244-408)
tests/data/expected/main/graphql/split_graphql_schemas.py (1)
src/datamodel_code_generator/model/type_alias.py (1)
TypeAlias(37-42)
🪛 GitHub Actions: Lint
src/datamodel_code_generator/parser/graphql.py
[error] 1-1: Ruff linting failed (legacy alias) with exit code 1 after auto-fixing 5 issues. Some imports were adjusted to satisfy lint rules (ruff: 5 fixes, 0 remaining). Run 'prek run --all-files' to reproduce locally or commit the changes and re-run CI.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.10 on Windows
- GitHub Check: benchmarks
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.14 on Windows
- GitHub Check: Analyze (python)
🔇 Additional comments (6)
src/datamodel_code_generator/parser/graphql.py (2)
700-702: LGTM! Schema merging approach is correct.Combining all GraphQL sources into a single unified schema before parsing is the right approach for handling cross-file type references and resolving forward references.
704-704: The unusual path format[]/SCALAR/Booleanis semantically odd but doesn't cause functional issues.Passing an empty list
[]to_resolve_typesat line 704 results in reference paths like"[]/SCALAR/Boolean"(see line 353). While this format is unusual and doesn't match the intended path structure, it doesn't break path parsing or reference resolution since paths are used only as string keys, set members, and comparisons—not parsed or validated for structure. However, the empty list should be replaced with a meaningful initial path segment or removed entirely if the path shouldn't be nested, as the[]prefix is semantically misleading for GraphQL type resolution.tests/main/graphql/test_main_graphql.py (1)
777-785: LGTM! Test follows established patterns.The new test properly exercises the split GraphQL schema scenario and follows the same structure as existing tests in this file.
tests/data/expected/main/graphql/split_graphql_schemas.py (3)
11-26: LGTM! Scalar type aliases are correctly defined.The TypeAlias definitions for GraphQL scalar types (Boolean, Int, String) properly map to Python built-in types with appropriate docstrings.
29-43: LGTM! Model definitions with circular dependencies are correct.The Pydantic models correctly represent the GraphQL types with proper forward references. The circular dependency between
BarandFoois a valid GraphQL pattern, and thetypename__fields withLiteraltypes and__typenamealiases are correctly implemented.
46-46: LGTM! Forward reference resolution is correctly applied.Only
Bar.update_forward_refs()is needed becauseBarreferencesFoobeforeFoois defined, whileFoo.baz: Barcan referenceBardirectly sinceBaris already defined at that point. This is the correct approach.
CodSpeed Performance ReportMerging #2873 will not alter performanceComparing
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/datamodel_code_generator/parser/graphql.py
🧰 Additional context used
🧬 Code graph analysis (1)
src/datamodel_code_generator/parser/graphql.py (1)
src/datamodel_code_generator/parser/base.py (2)
parse(3050-3130)iter_source(988-1011)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: 3.10 on Windows
- GitHub Check: py312-isort6 on Ubuntu
- GitHub Check: py312-black22 on Ubuntu
- GitHub Check: py312-black24 on Ubuntu
- GitHub Check: 3.14 on Windows
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.11 on Windows
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (2)
src/datamodel_code_generator/parser/graphql.py (2)
39-45: LGTM!The
PathandParseResulttype imports are correctly placed underTYPE_CHECKINGfor type annotation purposes without runtime overhead.
505-508: LGTM!The parsing loop correctly processes all GraphQL types from the unified schema in the defined order. The fix properly addresses the issue where cross-file type extensions failed by merging schemas before parsing.
|
🎉 Released in 0.51.0 This PR is now available in the latest release. See the release notes for details. |
Summary
Fixes: #2872
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.