@graphql-codegen/visitor-plugin-common 7.2.4 → 7.2.5-alpha-20260811142941-5fa2e89de326711c5f36a5322e803bf3849db10e

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.
@@ -55,6 +55,27 @@ class SelectionSetToObject {
55
55
  * traverse the inline fragment nodes recursively for collecting the selectionSets on each type
56
56
  */
57
57
  _collectInlineFragments(parentType, nodes, types) {
58
+ /**
59
+ * When we collect the selection sets of inline fragments we need to
60
+ * make sure directives on the inline fragments are stored in a way
61
+ * that can be associated back to the fields in the fragment i.e. `fragmentDirectives`
62
+ *
63
+ * This helps support things like making those fields optional when deferring a
64
+ * fragment (using @defer).
65
+ */
66
+ const enrichFieldWithDirectives = ({ node, fields, }) => {
67
+ const directives = node.directives || undefined;
68
+ return {
69
+ fieldsWithFragmentDirectives: fields.map(field => ({
70
+ ...field,
71
+ // A field may already carry `fragmentDirectives` from an enclosing
72
+ // conditional fragment spread; keep those in addition to the
73
+ // directives on this inline fragment, instead of overwriting them.
74
+ fragmentDirectives: [...(field.fragmentDirectives || []), ...(directives || [])],
75
+ })),
76
+ directives,
77
+ };
78
+ };
58
79
  if ((0, graphql_1.isListType)(parentType) || (0, graphql_1.isNonNullType)(parentType)) {
59
80
  return this._collectInlineFragments(parentType.ofType, nodes, types);
60
81
  }
@@ -64,20 +85,11 @@ class SelectionSetToObject {
64
85
  ? this._schema.getType(node.typeCondition.name.value)
65
86
  : parentType;
66
87
  const { fields, inlines, spreads } = (0, utils_js_1.separateSelectionSet)(node.selectionSet.selections);
88
+ const { fieldsWithFragmentDirectives, directives } = enrichFieldWithDirectives({
89
+ node,
90
+ fields,
91
+ });
67
92
  const spreadsUsage = this.buildFragmentSpreadsUsage(spreads);
68
- const directives = node.directives || undefined;
69
- // When we collect the selection sets of inline fragments we need to
70
- // make sure directives on the inline fragments are stored in a way
71
- // that can be associated back to the fields in the fragment, to
72
- // support things like making those fields optional when deferring a
73
- // fragment (using @defer).
74
- const fieldsWithFragmentDirectives = fields.map(field => ({
75
- ...field,
76
- // A field may already carry `fragmentDirectives` from an enclosing
77
- // conditional fragment spread; keep those in addition to the
78
- // directives on this inline fragment, instead of overwriting them.
79
- fragmentDirectives: [...(field.fragmentDirectives || []), ...(directives || [])],
80
- }));
81
93
  if ((0, graphql_1.isObjectType)(typeOnSchema)) {
82
94
  this._appendToTypeMap(types, typeOnSchema.name, fieldsWithFragmentDirectives);
83
95
  this._appendToTypeMap(types, typeOnSchema.name, spreadsUsage[typeOnSchema.name]);
@@ -137,9 +149,11 @@ class SelectionSetToObject {
137
149
  ? this._schema.getType(node.typeCondition.name.value)
138
150
  : parentType;
139
151
  const { fields, inlines, spreads } = (0, utils_js_1.separateSelectionSet)(node.selectionSet.selections);
152
+ const { fieldsWithFragmentDirectives } = enrichFieldWithDirectives({ node, fields });
140
153
  const spreadsUsage = this.buildFragmentSpreadsUsage(spreads);
141
154
  if ((0, graphql_1.isObjectType)(schemaType) &&
142
155
  possibleTypes.find(possibleType => possibleType.name === schemaType.name)) {
156
+ this._appendToTypeMap(types, schemaType.name, fieldsWithFragmentDirectives);
143
157
  this._appendToTypeMap(types, schemaType.name, fields);
144
158
  this._appendToTypeMap(types, schemaType.name, spreadsUsage[schemaType.name]);
145
159
  this._collectInlineFragments(schemaType, inlines, types);
@@ -51,6 +51,27 @@ export class SelectionSetToObject {
51
51
  * traverse the inline fragment nodes recursively for collecting the selectionSets on each type
52
52
  */
53
53
  _collectInlineFragments(parentType, nodes, types) {
54
+ /**
55
+ * When we collect the selection sets of inline fragments we need to
56
+ * make sure directives on the inline fragments are stored in a way
57
+ * that can be associated back to the fields in the fragment i.e. `fragmentDirectives`
58
+ *
59
+ * This helps support things like making those fields optional when deferring a
60
+ * fragment (using @defer).
61
+ */
62
+ const enrichFieldWithDirectives = ({ node, fields, }) => {
63
+ const directives = node.directives || undefined;
64
+ return {
65
+ fieldsWithFragmentDirectives: fields.map(field => ({
66
+ ...field,
67
+ // A field may already carry `fragmentDirectives` from an enclosing
68
+ // conditional fragment spread; keep those in addition to the
69
+ // directives on this inline fragment, instead of overwriting them.
70
+ fragmentDirectives: [...(field.fragmentDirectives || []), ...(directives || [])],
71
+ })),
72
+ directives,
73
+ };
74
+ };
54
75
  if (isListType(parentType) || isNonNullType(parentType)) {
55
76
  return this._collectInlineFragments(parentType.ofType, nodes, types);
56
77
  }
@@ -60,20 +81,11 @@ export class SelectionSetToObject {
60
81
  ? this._schema.getType(node.typeCondition.name.value)
61
82
  : parentType;
62
83
  const { fields, inlines, spreads } = separateSelectionSet(node.selectionSet.selections);
84
+ const { fieldsWithFragmentDirectives, directives } = enrichFieldWithDirectives({
85
+ node,
86
+ fields,
87
+ });
63
88
  const spreadsUsage = this.buildFragmentSpreadsUsage(spreads);
64
- const directives = node.directives || undefined;
65
- // When we collect the selection sets of inline fragments we need to
66
- // make sure directives on the inline fragments are stored in a way
67
- // that can be associated back to the fields in the fragment, to
68
- // support things like making those fields optional when deferring a
69
- // fragment (using @defer).
70
- const fieldsWithFragmentDirectives = fields.map(field => ({
71
- ...field,
72
- // A field may already carry `fragmentDirectives` from an enclosing
73
- // conditional fragment spread; keep those in addition to the
74
- // directives on this inline fragment, instead of overwriting them.
75
- fragmentDirectives: [...(field.fragmentDirectives || []), ...(directives || [])],
76
- }));
77
89
  if (isObjectType(typeOnSchema)) {
78
90
  this._appendToTypeMap(types, typeOnSchema.name, fieldsWithFragmentDirectives);
79
91
  this._appendToTypeMap(types, typeOnSchema.name, spreadsUsage[typeOnSchema.name]);
@@ -133,9 +145,11 @@ export class SelectionSetToObject {
133
145
  ? this._schema.getType(node.typeCondition.name.value)
134
146
  : parentType;
135
147
  const { fields, inlines, spreads } = separateSelectionSet(node.selectionSet.selections);
148
+ const { fieldsWithFragmentDirectives } = enrichFieldWithDirectives({ node, fields });
136
149
  const spreadsUsage = this.buildFragmentSpreadsUsage(spreads);
137
150
  if (isObjectType(schemaType) &&
138
151
  possibleTypes.find(possibleType => possibleType.name === schemaType.name)) {
152
+ this._appendToTypeMap(types, schemaType.name, fieldsWithFragmentDirectives);
139
153
  this._appendToTypeMap(types, schemaType.name, fields);
140
154
  this._appendToTypeMap(types, schemaType.name, spreadsUsage[schemaType.name]);
141
155
  this._collectInlineFragments(schemaType, inlines, types);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/visitor-plugin-common",
3
- "version": "7.2.4",
3
+ "version": "7.2.5-alpha-20260811142941-5fa2e89de326711c5f36a5322e803bf3849db10e",
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 || ^17.0.0"
6
6
  },