-
Notifications
You must be signed in to change notification settings - Fork 58
feat: support fragment parsing in parseFieldNodes #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughIntroduces an inlineFragments helper that recursively resolves and inlines fragment spreads (honoring @include/@Skip) using Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as parseFieldNodes
participant AST as FieldNodes AST
participant Frags as resolveInfo.fragments
participant Inline as inlineFragments
participant Tree as Reduction / Tree Builder
Caller->>AST: receive fieldNodes selections
Caller->>Inline: inlineFragments(selections, resolveInfo)
Inline->>AST: inspect each selection
alt selection is FRAGMENT_SPREAD
Inline->>Frags: lookup fragment by name
alt directives include fragment
Frags-->>Inline: fragment.selectionSet
Inline->>Inline: recursively inline nested spreads
else directives exclude fragment
Frags-->>Inline: []
end
else selection is FIELD / INLINE_FRAGMENT
AST-->>Inline: keep selection (apply directive checks)
end
Inline-->>Caller: return expanded selections
Caller->>Tree: reduce expanded selections into resolve-info tree
Tree-->>Caller: built resolve-info structure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (1)
packages/query-graphql/src/decorators/graphql-resolve-info.utils.ts (1)
73-77: Consider adding error handling for missing fragments.When a fragment reference is not found in
resolveInfo.fragments, the code silently returns an empty array. While this might be intentional, it could hide configuration errors or typos in fragment names. Consider logging a warning in development mode to help with debugging.if (ast.kind === Kind.FRAGMENT_SPREAD) { const fragment = resolveInfo.fragments[ast.name.value] if (fragment) { return fragment.selectionSet.selections + } else { + // Optional: log warning for missing fragment + console.warn(`Fragment "${ast.name.value}" not found in resolveInfo.fragments`) } return [] }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/query-graphql/src/decorators/graphql-resolve-info.utils.ts(1 hunks)
🧰 Additional context used
🪛 ESLint
packages/query-graphql/src/decorators/graphql-resolve-info.utils.ts
[error] 71-71: Replace ast with (ast)
(prettier/prettier)
[error] 73-73: Delete ;
(prettier/prettier)
[error] 75-75: Delete ;
(prettier/prettier)
[error] 77-77: Delete ;
(prettier/prettier)
[error] 79-79: Delete ;
(prettier/prettier)
🔇 Additional comments (1)
packages/query-graphql/src/decorators/graphql-resolve-info.utils.ts (1)
82-82: Good: Reduce loop now operates on inlined fragments.This change correctly processes the inlined fragment selections instead of the original ASTs. Once the fragment inlining logic is fixed to handle nested spreads and directives (see previous comments), this will properly include all fragment fields in the resolve info.
packages/query-graphql/src/decorators/graphql-resolve-info.utils.ts
Outdated
Show resolved
Hide resolved
|
View your CI Pipeline Execution ↗ for commit f8625da
☁️ Nx Cloud last updated this comment at |
|
Sorry, seems this topic is a little more complicated. |
e602d6d to
f8625da
Compare
|
The PR should be ready 🙂 |
|
@SoerenLinkFides small code sample here would be appreciated to explain what it fixes :) |
This PR adds fragment support to nestjs-query-graphql's
simplifyResolveInfomethod.Previously, fields only included in a fragment were missing from the QueryService
opts.resolveInfofield.This does not affect inline fragments, as those are defined using a different
Kind(Kind.INLINE_FRAGMENT).There is no open issue for this PR.
Summary by CodeRabbit