Skip to content

Commit

Permalink
fix(visitor-plugin-common): avoid reading from null values
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Oct 17, 2023
1 parent 04d8781 commit ea66985
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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) {
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

0 comments on commit ea66985

Please sign in to comment.