@graphql-codegen/graphql-modules-preset 5.0.0 → 5.0.1-alpha-20250923134201-d3256d9fcce8c6b3042fddbb280ab439609d2992

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.
package/cjs/builder.js CHANGED
@@ -6,10 +6,12 @@ const graphql_1 = require("graphql");
6
6
  const utils_js_1 = require("./utils.js");
7
7
  const registryKeys = ['objects', 'inputs', 'interfaces', 'scalars', 'unions', 'enums'];
8
8
  const resolverKeys = ['scalars', 'objects', 'enums'];
9
+ const withIsTypeOfKeys = ['objects'];
9
10
  function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports = false, }) {
10
11
  const picks = (0, utils_js_1.createObject)(registryKeys, () => ({}));
11
12
  const defined = (0, utils_js_1.createObject)(registryKeys, () => []);
12
13
  const extended = (0, utils_js_1.createObject)(registryKeys, () => []);
14
+ const withIsTypeOf = (0, utils_js_1.createObject)(withIsTypeOfKeys, () => []);
13
15
  // List of types used in objects, fields, arguments etc
14
16
  const usedTypes = (0, utils_js_1.collectUsedTypes)(doc);
15
17
  (0, graphql_1.visit)(doc, {
@@ -137,7 +139,9 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
137
139
  [...registry.objects, ...registry.interfaces]
138
140
  .map(name => printResolverType(name, 'DefinedFields',
139
141
  // In case of enabled `requireRootResolvers` flag, the preset has to produce a non-optional properties.
140
- requireRootResolvers && rootTypes.includes(name), !rootTypes.includes(name) && defined.objects.includes(name) ? ` | '__isTypeOf'` : ''))
142
+ requireRootResolvers && rootTypes.includes(name), !rootTypes.includes(name) && defined.objects.includes(name) && withIsTypeOf.objects.includes(name)
143
+ ? ` | '__isTypeOf'`
144
+ : ''))
141
145
  .join('\n'),
142
146
  ].join('\n');
143
147
  }
@@ -279,6 +283,9 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
279
283
  case graphql_1.Kind.OBJECT_TYPE_DEFINITION: {
280
284
  defined.objects.push(name);
281
285
  collectFields(node, picks.objects);
286
+ if (node.interfaces?.length > 0) {
287
+ withIsTypeOf.objects.push(name);
288
+ }
282
289
  break;
283
290
  }
284
291
  case graphql_1.Kind.ENUM_TYPE_DEFINITION: {
@@ -302,6 +309,9 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
302
309
  }
303
310
  case graphql_1.Kind.UNION_TYPE_DEFINITION: {
304
311
  defined.unions.push(name);
312
+ for (const namedType of node.types || []) {
313
+ (0, utils_js_1.pushUnique)(withIsTypeOf.objects, namedType.name.value);
314
+ }
305
315
  break;
306
316
  }
307
317
  }
@@ -318,6 +328,9 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
318
328
  return;
319
329
  }
320
330
  (0, utils_js_1.pushUnique)(extended.objects, name);
331
+ if (node.interfaces?.length > 0) {
332
+ (0, utils_js_1.pushUnique)(withIsTypeOf.objects, name);
333
+ }
321
334
  break;
322
335
  }
323
336
  case graphql_1.Kind.ENUM_TYPE_EXTENSION: {
package/esm/builder.js CHANGED
@@ -3,10 +3,12 @@ import { isScalarType, Kind, visit, } from 'graphql';
3
3
  import { buildBlock, collectUsedTypes, concatByKey, createObject, indent, pushUnique, unique, uniqueByKey, withQuotes, } from './utils.js';
4
4
  const registryKeys = ['objects', 'inputs', 'interfaces', 'scalars', 'unions', 'enums'];
5
5
  const resolverKeys = ['scalars', 'objects', 'enums'];
6
+ const withIsTypeOfKeys = ['objects'];
6
7
  export function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports = false, }) {
7
8
  const picks = createObject(registryKeys, () => ({}));
8
9
  const defined = createObject(registryKeys, () => []);
9
10
  const extended = createObject(registryKeys, () => []);
11
+ const withIsTypeOf = createObject(withIsTypeOfKeys, () => []);
10
12
  // List of types used in objects, fields, arguments etc
11
13
  const usedTypes = collectUsedTypes(doc);
12
14
  visit(doc, {
@@ -134,7 +136,9 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
134
136
  [...registry.objects, ...registry.interfaces]
135
137
  .map(name => printResolverType(name, 'DefinedFields',
136
138
  // In case of enabled `requireRootResolvers` flag, the preset has to produce a non-optional properties.
137
- requireRootResolvers && rootTypes.includes(name), !rootTypes.includes(name) && defined.objects.includes(name) ? ` | '__isTypeOf'` : ''))
139
+ requireRootResolvers && rootTypes.includes(name), !rootTypes.includes(name) && defined.objects.includes(name) && withIsTypeOf.objects.includes(name)
140
+ ? ` | '__isTypeOf'`
141
+ : ''))
138
142
  .join('\n'),
139
143
  ].join('\n');
140
144
  }
@@ -276,6 +280,9 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
276
280
  case Kind.OBJECT_TYPE_DEFINITION: {
277
281
  defined.objects.push(name);
278
282
  collectFields(node, picks.objects);
283
+ if (node.interfaces?.length > 0) {
284
+ withIsTypeOf.objects.push(name);
285
+ }
279
286
  break;
280
287
  }
281
288
  case Kind.ENUM_TYPE_DEFINITION: {
@@ -299,6 +306,9 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
299
306
  }
300
307
  case Kind.UNION_TYPE_DEFINITION: {
301
308
  defined.unions.push(name);
309
+ for (const namedType of node.types || []) {
310
+ pushUnique(withIsTypeOf.objects, namedType.name.value);
311
+ }
302
312
  break;
303
313
  }
304
314
  }
@@ -315,6 +325,9 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
315
325
  return;
316
326
  }
317
327
  pushUnique(extended.objects, name);
328
+ if (node.interfaces?.length > 0) {
329
+ pushUnique(withIsTypeOf.objects, name);
330
+ }
318
331
  break;
319
332
  }
320
333
  case Kind.ENUM_TYPE_EXTENSION: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/graphql-modules-preset",
3
- "version": "5.0.0",
3
+ "version": "5.0.1-alpha-20250923134201-d3256d9fcce8c6b3042fddbb280ab439609d2992",
4
4
  "description": "GraphQL Code Generator preset for modularized schema",
5
5
  "peerDependencies": {
6
6
  "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"