@graphql-codegen/visitor-plugin-common 5.7.0 → 5.7.1-alpha-20250221122145-5ef68e775c396313780244f87714d33191a46522

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,25 @@ class SelectionSetToObject {
410
411
  }
411
412
  continue;
412
413
  }
414
+ // 2. Handle Fragment Spread nodes
415
+ // A Fragment Spread can be:
416
+ // - masked: the fields declared in the Fragment do not appear in the operation types
417
+ // - inline: the fields declared in the Fragment appear in the operation types
418
+ // 2a. If `inlineFragmentTypes` is 'combine' or 'mask', the Fragment Spread is masked by default
419
+ // In some cases, a masked node could be unmasked (i.e. treated as inline):
420
+ // - Fragment spread node is marked with Apollo `@unmask`, e.g. `...User @unmask`
413
421
  if (this._config.inlineFragmentTypes === 'combine' || this._config.inlineFragmentTypes === 'mask') {
414
- fragmentsSpreadUsages.push(selectionNode.typeName);
415
- const isApolloUnmaskEnabled = this._config.customDirectives.apolloUnmask;
416
- if (!isApolloUnmaskEnabled ||
417
- (isApolloUnmaskEnabled && !selectionNode.fragmentDirectives?.some(d => d.name.value === 'unmask'))) {
422
+ let isMasked = true;
423
+ if (this._config.customDirectives.apolloUnmask &&
424
+ selectionNode.fragmentDirectives.some(d => d.name.value === 'unmask')) {
425
+ isMasked = false;
426
+ }
427
+ if (isMasked) {
428
+ fragmentsSpreadUsages.push(selectionNode.typeName);
418
429
  continue;
419
430
  }
420
431
  }
421
- // Handle Fragment Spreads by generating inline types.
432
+ // 2b. If the Fragment Spread is not masked, generate inline types.
422
433
  const fragmentType = this._schema.getType(selectionNode.onType);
423
434
  if (fragmentType == null) {
424
435
  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,25 @@ export class SelectionSetToObject {
406
407
  }
407
408
  continue;
408
409
  }
410
+ // 2. Handle Fragment Spread nodes
411
+ // A Fragment Spread can be:
412
+ // - masked: the fields declared in the Fragment do not appear in the operation types
413
+ // - inline: the fields declared in the Fragment appear in the operation types
414
+ // 2a. If `inlineFragmentTypes` is 'combine' or 'mask', the Fragment Spread is masked by default
415
+ // In some cases, a masked node could be unmasked (i.e. treated as inline):
416
+ // - Fragment spread node is marked with Apollo `@unmask`, e.g. `...User @unmask`
409
417
  if (this._config.inlineFragmentTypes === 'combine' || this._config.inlineFragmentTypes === 'mask') {
410
- fragmentsSpreadUsages.push(selectionNode.typeName);
411
- const isApolloUnmaskEnabled = this._config.customDirectives.apolloUnmask;
412
- if (!isApolloUnmaskEnabled ||
413
- (isApolloUnmaskEnabled && !selectionNode.fragmentDirectives?.some(d => d.name.value === 'unmask'))) {
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);
414
425
  continue;
415
426
  }
416
427
  }
417
- // Handle Fragment Spreads by generating inline types.
428
+ // 2b. If the Fragment Spread is not masked, generate inline types.
418
429
  const fragmentType = this._schema.getType(selectionNode.onType);
419
430
  if (fragmentType == null) {
420
431
  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.0",
3
+ "version": "5.7.1-alpha-20250221122145-5ef68e775c396313780244f87714d33191a46522",
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
  },