Skip to content

Conversation

@vertex451
Copy link
Contributor

@vertex451 vertex451 commented Oct 8, 2025

The panic occurred because the code used nil as a cache placeholder to prevent infinite recursion when processing circular type references, but failed to check for nil when retrieving cached types.
It was fixed by adding exists && existingType != nil checks in three cache retrieval locations (convertSwaggerTypeToGraphQL, handleObjectFieldSpecType, and findRelationTarget).

Summary by CodeRabbit

  • Bug Fixes

    • Improved stability in schema generation for recursive and self-referencing definitions, preventing crashes and handling in-progress type resolution more safely.
    • Enhanced relation resolution to skip invalid or nil types, reducing errors during schema building.
  • Tests

    • Added comprehensive unit tests covering recursive, self-referencing, and cross-referenced schema scenarios to ensure reliable Swagger/OpenAPI to GraphQL conversion.
  • Chores

    • Updated test CRD metadata to a newer controller-gen version and streamlined condition descriptions in test data.

@vertex451 vertex451 requested a review from a team as a code owner October 8, 2025 08:30
@coderabbitai
Copy link

coderabbitai bot commented Oct 8, 2025

Walkthrough

Adds recursion-safe handling in schema generation and relation resolution by introducing nil and in-progress checks for cached GraphQL types. Introduces a new test suite targeting recursive/self-referencing OpenAPI definitions. Updates a CRD test data file with revised controller-gen version and shortened condition descriptions.

Changes

Cohort / File(s) Summary of Changes
Schema recursion handling
gateway/schema/relations.go, gateway/schema/schema.go
Added nil-safety around cached type retrieval and early-continue when computed field types are nil. Introduced in-progress type placeholders (returning graphql.String) to break recursive loops. Ensured caches are checked for non-nil entries before reuse; coordinated between output and input type caches. Minor formatting cleanup.
New recursion tests
gateway/schema/recursion_test.go
Added unit tests covering recursive refs, nested nil-in-cache scenarios, self-referencing objects, and cross-references (Parent/Child). Implemented a mock resolver provider satisfying resolver.Provider to decouple from backend behavior and assert schema creation without panics and non-nil schema results.
CRD testdata update
tests/gateway_test/testdata/crd/core.platform-mesh.io_accounts.yaml
Updated controller-gen version to v0.19.0. Simplified descriptions for status.conditions.items and its type field to concise text.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “Fix/relations nil pointer” only references one part of the change and does not capture the broader nil-safety updates in schema.go and circular reference handling, and the slash makes its intent unclear. Consequently it fails to clearly summarize the main fix implemented in this PR. Please rename the title to clearly summarize the addition of nil-safety checks across both schema and relations—for example, “Fix nil pointer panic in circular type reference caching.”
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/relations-nil-pointer

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea9e399 and db7db1d.

📒 Files selected for processing (4)
  • gateway/schema/recursion_test.go (1 hunks)
  • gateway/schema/relations.go (2 hunks)
  • gateway/schema/schema.go (3 hunks)
  • tests/gateway_test/testdata/crd/core.platform-mesh.io_accounts.yaml (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
gateway/schema/recursion_test.go (3)
gateway/schema/schema.go (3)
  • New (39-54)
  • Gateway (24-37)
  • Provider (20-22)
listener/pkg/apischema/builder.go (1)
  • GroupVersionKind (78-82)
gateway/resolver/custom_queries.go (1)
  • TypeByCategory (7-12)
⏰ 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). (4)
  • GitHub Check: pipe / dockerBuild / docker
  • GitHub Check: pipe / lint / lint
  • GitHub Check: pipe / testSource / test
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
gateway/schema/relations.go (1)

99-111: Nil guard avoids reusing placeholders.

Checking for a cached type being both present and non-nil keeps the relation enhancer from wiring in placeholder entries, and the subsequent nil fallback protects the resolver path. Nice tightening of the cache handling.

gateway/schema/schema.go (1)

355-360: Recursion guard now skips incomplete cache entries.

The (exists && existingType != nil) gate ensures we never hand back an in-progress placeholder, and the placeholder fallback keeps self-referential $refs from blowing up the stack. Solid fix.

gateway/schema/recursion_test.go (1)

16-312: Great coverage for recursive edge cases.

These scenarios pin the cache placeholders, self-ref recursion, and cross-reference flows, so we won’t regress the nil-guard fixes. Nicely thorough.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vertex451 vertex451 requested a review from aaronschweig October 8, 2025 09:04
@vertex451 vertex451 self-assigned this Oct 8, 2025
@vertex451 vertex451 merged commit 43b45f3 into main Oct 9, 2025
12 checks passed
@vertex451 vertex451 deleted the fix/relations-nil-pointer branch October 9, 2025 06:52
vertex451 added a commit that referenced this pull request Oct 10, 2025
* added nil checks in relation resovling

On-behalf-of: @SAP [email protected]
Signed-off-by: Artem Shcherbatiuk <[email protected]>
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.

3 participants