@depup/graphql-codegen__typescript-operations 5.0.9-depup.0 → 6.1.1-depup.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dotan Simha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -13,18 +13,17 @@ npm install @depup/graphql-codegen__typescript-operations
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [@graphql-codegen/typescript-operations](https://www.npmjs.com/package/@graphql-codegen/typescript-operations) @ 5.0.9 |
17
- | Processed | 2026-03-17 |
16
+ | Original | [@graphql-codegen/typescript-operations](https://www.npmjs.com/package/@graphql-codegen/typescript-operations) @ 6.1.1 |
17
+ | Processed | 2026-07-21 |
18
18
  | Smoke test | passed |
19
- | Deps updated | 3 |
19
+ | Deps updated | 2 |
20
20
 
21
21
  ## Dependency Changes
22
22
 
23
23
  | Dependency | From | To |
24
24
  |------------|------|-----|
25
- | @graphql-codegen/plugin-helpers | ^6.1.1 | ^6.2.0 |
26
- | auto-bind | ~4.0.0 | ^5.0.1 |
27
- | tslib | ~2.6.0 | ^2.8.1 |
25
+ | auto-bind | ^5.0.0 | ^5.0.1 |
26
+ | tslib | ^2.8.0 | ^2.8.1 |
28
27
 
29
28
  ---
30
29
 
package/changes.json CHANGED
@@ -1,18 +1,14 @@
1
1
  {
2
2
  "bumped": {
3
- "@graphql-codegen/plugin-helpers": {
4
- "from": "^6.1.1",
5
- "to": "^6.2.0"
6
- },
7
3
  "auto-bind": {
8
- "from": "~4.0.0",
4
+ "from": "^5.0.0",
9
5
  "to": "^5.0.1"
10
6
  },
11
7
  "tslib": {
12
- "from": "~2.6.0",
8
+ "from": "^2.8.0",
13
9
  "to": "^2.8.1"
14
10
  }
15
11
  },
16
- "timestamp": "2026-03-17T16:32:40.323Z",
17
- "totalUpdated": 3
12
+ "timestamp": "2026-07-21T16:04:46.562Z",
13
+ "totalUpdated": 2
18
14
  }
package/cjs/index.js CHANGED
@@ -15,51 +15,80 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.TypeScriptDocumentsVisitor = exports.plugin = void 0;
37
+ const graphql_1 = require("graphql");
27
38
  const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
39
+ const schema_ast_1 = require("@graphql-codegen/schema-ast");
28
40
  const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
29
- const graphql_1 = require("graphql");
30
41
  const visitor_js_1 = require("./visitor.js");
31
42
  Object.defineProperty(exports, "TypeScriptDocumentsVisitor", { enumerable: true, get: function () { return visitor_js_1.TypeScriptDocumentsVisitor; } });
32
- const plugin = async (inputSchema, rawDocuments, config) => {
33
- const schema = config.nullability?.errorHandlingClient ? await semanticToStrict(inputSchema) : inputSchema;
43
+ const plugin = async (inputSchema, rawDocuments, config, { outputFile }) => {
44
+ const schema = config.nullability?.errorHandlingClient
45
+ ? await semanticToStrict(inputSchema)
46
+ : inputSchema;
34
47
  const documents = config.flattenGeneratedTypes
35
48
  ? (0, visitor_plugin_common_1.optimizeOperations)(schema, rawDocuments, {
36
49
  includeFragments: config.flattenGeneratedTypesIncludeFragments,
37
50
  })
38
51
  : rawDocuments;
39
- const allAst = (0, graphql_1.concatAST)(documents.map(v => v.document));
40
- const allFragments = [
41
- ...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
42
- node: fragmentDef,
43
- name: fragmentDef.name.value,
44
- onType: fragmentDef.typeCondition.name.value,
45
- isExternal: false,
46
- })),
47
- ...(config.externalFragments || []),
48
- ];
49
- const visitor = new visitor_js_1.TypeScriptDocumentsVisitor(schema, config, allFragments);
50
- const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, {
52
+ const parsedDocuments = documents.reduce((prev, document) => {
53
+ prev.all.documentFiles.push(document);
54
+ prev.all.documentNodes.push(document.document);
55
+ // `!document.type` case could happen in a few scenarios:
56
+ // - the plugin is programmatically triggered
57
+ // - in existing tests
58
+ if (!document.type || document.type === 'standard') {
59
+ prev.standard.documentFiles.push(document);
60
+ prev.standard.documentNodes.push(document.document);
61
+ }
62
+ return prev;
63
+ }, {
64
+ all: { documentFiles: [], documentNodes: [] },
65
+ standard: { documentFiles: [], documentNodes: [] },
66
+ });
67
+ // For Fragment types to resolve correctly, we must get read all docs (`standard` and `external`)
68
+ // Fragment types are usually (but not always) in `external` files in certain setup, like a monorepo.
69
+ const allDocumentsAST = (0, graphql_1.concatAST)(parsedDocuments.all.documentNodes);
70
+ const visitor = new visitor_js_1.TypeScriptDocumentsVisitor(schema, config, allDocumentsAST, outputFile);
71
+ // We only visit `standard` documents to generate types.
72
+ // `external` documents are included as references for typechecking and completeness i.e. only used for reading purposes, no writing.
73
+ const documentsToVisitAST = (0, graphql_1.concatAST)(parsedDocuments.standard.documentNodes);
74
+ const operationsResult = (0, plugin_helpers_1.oldVisit)(documentsToVisitAST, {
51
75
  leave: visitor,
52
76
  });
53
- let content = visitorResult.definitions.join('\n');
77
+ const operationsDefinitions = operationsResult.definitions;
54
78
  if (config.addOperationExport) {
55
- const exportConsts = [];
56
- for (const d of allAst.definitions) {
79
+ for (const d of allDocumentsAST.definitions) {
57
80
  if ('name' in d) {
58
- exportConsts.push(`export declare const ${d.name.value}: import("graphql").DocumentNode;`);
81
+ operationsDefinitions.push(`export declare const ${d.name.value}: import("graphql").DocumentNode;`);
59
82
  }
60
83
  }
61
- content = visitorResult.definitions.concat(exportConsts).join('\n');
62
84
  }
85
+ const schemaTypes = (0, plugin_helpers_1.oldVisit)((0, schema_ast_1.transformSchemaAST)(schema, config).ast, { leave: visitor });
86
+ // IMPORTANT: when a visitor leaves a node with no transformation logic,
87
+ // It will leave the node as an object.
88
+ // Here, we filter in nodes that have been turned into strings, i.e. they have been transformed
89
+ // This way, we do not have to explicitly declare a method for every node type to convert them to null
90
+ const schemaTypesDefinitions = schemaTypes.definitions.filter(def => typeof def === 'string');
91
+ let content = [...schemaTypesDefinitions, ...operationsDefinitions].join('\n');
63
92
  if (config.globalNamespace) {
64
93
  content = `
65
94
  declare global {
@@ -67,7 +96,15 @@ const plugin = async (inputSchema, rawDocuments, config) => {
67
96
  }`;
68
97
  }
69
98
  return {
70
- prepend: [...visitor.getImports(), ...visitor.getGlobalDeclarations(visitor.config.noExport)],
99
+ prepend: [
100
+ ...visitor.getImports(),
101
+ ...visitor.getExternalSchemaTypeImports(),
102
+ ...visitor.getEnumsImports(),
103
+ ...visitor.getScalarsImports(),
104
+ ...visitor.getGlobalDeclarations(visitor.config.noExport),
105
+ visitor.getExactUtilityType(),
106
+ visitor.getIncrementalUtilityType(),
107
+ ],
71
108
  content,
72
109
  };
73
110
  };
@@ -1,10 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TypeScriptOperationVariablesToObject = void 0;
4
- const typescript_1 = require("@graphql-codegen/typescript");
5
- class TypeScriptOperationVariablesToObject extends typescript_1.TypeScriptOperationVariablesToObject {
4
+ const graphql_1 = require("graphql");
5
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
+ class TypeScriptOperationVariablesToObject extends visitor_plugin_common_1.OperationVariablesToObject {
7
+ _config;
8
+ constructor(_config, _scalars, _convertName, _namespacedImportName, _enumNames, _enumPrefix, _enumSuffix, _enumValues, _applyCoercion) {
9
+ super(_scalars, _convertName, _namespacedImportName, _enumNames, _enumPrefix, _enumSuffix, _enumValues, _applyCoercion, {});
10
+ this._config = _config;
11
+ }
12
+ formatFieldString(fieldName, isNonNullType, hasDefaultValue) {
13
+ return `${fieldName}${this.getAvoidOption(isNonNullType, hasDefaultValue) ? '?' : ''}`;
14
+ }
6
15
  formatTypeString(fieldType, _isNonNullType, _hasDefaultValue) {
7
16
  return fieldType;
8
17
  }
18
+ clearOptional(str) {
19
+ const maybeSuffix = this._config.inputMaybeValue.replace('T', ''); // e.g. turns `T | null | undefined` to ` | null | undefined`
20
+ if (str.endsWith(maybeSuffix)) {
21
+ return (str = str.substring(0, str.length - maybeSuffix.length));
22
+ }
23
+ return str;
24
+ }
25
+ getAvoidOption(isNonNullType, hasDefaultValue) {
26
+ const options = this._config.avoidOptionals;
27
+ return (((options.variableValue || !options.defaultValue) && hasDefaultValue) ||
28
+ (!options.variableValue && !isNonNullType));
29
+ }
30
+ getScalar(name) {
31
+ return this._scalars[name]?.input ?? visitor_plugin_common_1.DEFAULT_INPUT_SCALARS[name].input ?? 'unknown';
32
+ }
33
+ getPunctuation() {
34
+ return ';';
35
+ }
36
+ wrapAstTypeWithModifiers(baseType, typeNode, applyCoercion = false) {
37
+ if (typeNode.kind === graphql_1.Kind.NON_NULL_TYPE) {
38
+ const type = this.wrapAstTypeWithModifiers(baseType, typeNode.type, applyCoercion);
39
+ return this.clearOptional(type);
40
+ }
41
+ if (typeNode.kind === graphql_1.Kind.LIST_TYPE) {
42
+ const innerType = this.wrapAstTypeWithModifiers(baseType, typeNode.type, applyCoercion);
43
+ const listInputCoercionExtension = applyCoercion ? ` | ${innerType}` : '';
44
+ return this.wrapMaybe(`${this._config.immutableTypes ? 'ReadonlyArray' : 'Array'}<${innerType}>${listInputCoercionExtension}`);
45
+ }
46
+ return this.wrapMaybe(baseType);
47
+ }
48
+ wrapMaybe(type) {
49
+ return (0, visitor_plugin_common_1.printTypeScriptMaybeType)({
50
+ type,
51
+ pattern: this._config.inputMaybeValue,
52
+ });
53
+ }
9
54
  }
10
55
  exports.TypeScriptOperationVariablesToObject = TypeScriptOperationVariablesToObject;
@@ -26,15 +26,7 @@ class TypeScriptSelectionSetProcessor extends visitor_plugin_common_1.BaseSelect
26
26
  });
27
27
  let resString = formattedUnionTransform('Pick', parentName, escapedFieldNames);
28
28
  if (hasConditionals) {
29
- const avoidOptional =
30
- // TODO: check type and exec only if relevant
31
- this.config.avoidOptionals === true ||
32
- (typeof this.config.avoidOptionals === 'object' &&
33
- (this.config.avoidOptionals.field ||
34
- this.config.avoidOptionals.inputValue ||
35
- this.config.avoidOptionals.object));
36
- const transform = avoidOptional ? 'MakeMaybe' : 'MakeOptional';
37
- resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${formattedUnionTransform(transform, resString, escapedConditionalsList)}`;
29
+ resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${formattedUnionTransform('MakeOptional', resString, escapedConditionalsList)}`;
38
30
  }
39
31
  return [resString];
40
32
  }
@@ -50,7 +42,9 @@ class TypeScriptSelectionSetProcessor extends visitor_plugin_common_1.BaseSelect
50
42
  useTypesPrefix: true,
51
43
  });
52
44
  const selections = fields.map(aliasedField => {
53
- const value = aliasedField.fieldName === '__typename' ? `'${schemaType.name}'` : `${parentName}['${aliasedField.fieldName}']`;
45
+ const value = aliasedField.fieldName === '__typename'
46
+ ? `'${schemaType.name}'`
47
+ : `${parentName}['${aliasedField.fieldName}']`;
54
48
  return `${aliasedField.alias}: ${value}`;
55
49
  });
56
50
  return [formatSelections(selections)];