Skip to content
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

fix(visitor-plugin-common): avoid reading from null values #9709

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-forks-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/visitor-plugin-common': patch
---

Avoid reading from null values when selection sets only contain fragments.
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
return (
Object.keys(grouped)
.map(typeName => {
const hasUnions = grouped[typeName].filter(s => typeof s !== 'string' && s.union).length > 0;
const relevant = grouped[typeName].filter(Boolean);

if (relevant.length === 0) {
Comment on lines -717 to 719
Copy link
Contributor Author

@frandiox frandiox Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relevant.length === 0 will be true for [null] so it exits before declaring hasUnions.

Expand All @@ -729,6 +728,8 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
})
.join(' & ');

const hasUnions = grouped[typeName].filter(s => typeof s !== 'string' && s.union).length > 0;

return relevant.length > 1 && !hasUnions ? `( ${res} )` : res;
})
.filter(Boolean)
Expand Down
Loading