@graphql-codegen/visitor-plugin-common 5.7.0 → 5.7.1-alpha-20250221120941-a01a9a425c7b5284592b7e1cfdf2cb663fa9e736
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -359,6 +359,7 @@ class SelectionSetToObject {
|
|
|
359
359
|
selectionNodes = [...selectionNodes];
|
|
360
360
|
let inlineFragmentConditional = false;
|
|
361
361
|
for (const selectionNode of selectionNodes) {
|
|
362
|
+
// 1. Handle Field or Directtives selection nodes
|
|
362
363
|
if ('kind' in selectionNode) {
|
|
363
364
|
if (selectionNode.kind === 'Field') {
|
|
364
365
|
if (selectionNode.selectionSet) {
|
|
@@ -410,15 +411,21 @@ class SelectionSetToObject {
|
|
|
410
411
|
}
|
|
411
412
|
continue;
|
|
412
413
|
}
|
|
414
|
+
// 2. Handle Fragment selection nodes
|
|
415
|
+
// 2a. If `inlineFragmentTypes` is 'combine' or 'mask', the fragment is masked i.e. do not generate inline types
|
|
416
|
+
// In some cases like Apollo `@unmask`, the fragment would be generated inline.
|
|
413
417
|
if (this._config.inlineFragmentTypes === 'combine' || this._config.inlineFragmentTypes === 'mask') {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
+
let isMasked = true;
|
|
419
|
+
if (this._config.customDirectives.apolloUnmask &&
|
|
420
|
+
selectionNode.fragmentDirectives.some(d => d.name.value === 'unmask')) {
|
|
421
|
+
isMasked = false;
|
|
422
|
+
}
|
|
423
|
+
if (isMasked) {
|
|
424
|
+
fragmentsSpreadUsages.push(selectionNode.typeName);
|
|
418
425
|
continue;
|
|
419
426
|
}
|
|
420
427
|
}
|
|
421
|
-
//
|
|
428
|
+
// 2b. If the Fragment is not masked, handle Fragment Spreads by generating inline types.
|
|
422
429
|
const fragmentType = this._schema.getType(selectionNode.onType);
|
|
423
430
|
if (fragmentType == null) {
|
|
424
431
|
throw new TypeError(`Unexpected error: Type ${selectionNode.onType} does not exist within schema.`);
|
|
@@ -355,6 +355,7 @@ export class SelectionSetToObject {
|
|
|
355
355
|
selectionNodes = [...selectionNodes];
|
|
356
356
|
let inlineFragmentConditional = false;
|
|
357
357
|
for (const selectionNode of selectionNodes) {
|
|
358
|
+
// 1. Handle Field or Directtives selection nodes
|
|
358
359
|
if ('kind' in selectionNode) {
|
|
359
360
|
if (selectionNode.kind === 'Field') {
|
|
360
361
|
if (selectionNode.selectionSet) {
|
|
@@ -406,15 +407,21 @@ export class SelectionSetToObject {
|
|
|
406
407
|
}
|
|
407
408
|
continue;
|
|
408
409
|
}
|
|
410
|
+
// 2. Handle Fragment selection nodes
|
|
411
|
+
// 2a. If `inlineFragmentTypes` is 'combine' or 'mask', the fragment is masked i.e. do not generate inline types
|
|
412
|
+
// In some cases like Apollo `@unmask`, the fragment would be generated inline.
|
|
409
413
|
if (this._config.inlineFragmentTypes === 'combine' || this._config.inlineFragmentTypes === 'mask') {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
+
let isMasked = true;
|
|
415
|
+
if (this._config.customDirectives.apolloUnmask &&
|
|
416
|
+
selectionNode.fragmentDirectives.some(d => d.name.value === 'unmask')) {
|
|
417
|
+
isMasked = false;
|
|
418
|
+
}
|
|
419
|
+
if (isMasked) {
|
|
420
|
+
fragmentsSpreadUsages.push(selectionNode.typeName);
|
|
414
421
|
continue;
|
|
415
422
|
}
|
|
416
423
|
}
|
|
417
|
-
//
|
|
424
|
+
// 2b. If the Fragment is not masked, handle Fragment Spreads by generating inline types.
|
|
418
425
|
const fragmentType = this._schema.getType(selectionNode.onType);
|
|
419
426
|
if (fragmentType == null) {
|
|
420
427
|
throw new TypeError(`Unexpected error: Type ${selectionNode.onType} does not exist within schema.`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.1-alpha-20250221120941-a01a9a425c7b5284592b7e1cfdf2cb663fa9e736",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
6
6
|
},
|