@depup/graphql-codegen__typescript-operations 5.0.9-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/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @depup/graphql-codegen__typescript-operations
2
+
3
+ > Dependency-bumped version of [@graphql-codegen/typescript-operations](https://www.npmjs.com/package/@graphql-codegen/typescript-operations)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/graphql-codegen__typescript-operations
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [@graphql-codegen/typescript-operations](https://www.npmjs.com/package/@graphql-codegen/typescript-operations) @ 5.0.9 |
17
+ | Processed | 2026-03-17 |
18
+ | Smoke test | passed |
19
+ | Deps updated | 3 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
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 |
28
+
29
+ ---
30
+
31
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@graphql-codegen/typescript-operations
32
+
33
+ License inherited from the original package.
package/changes.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "bumped": {
3
+ "@graphql-codegen/plugin-helpers": {
4
+ "from": "^6.1.1",
5
+ "to": "^6.2.0"
6
+ },
7
+ "auto-bind": {
8
+ "from": "~4.0.0",
9
+ "to": "^5.0.1"
10
+ },
11
+ "tslib": {
12
+ "from": "~2.6.0",
13
+ "to": "^2.8.1"
14
+ }
15
+ },
16
+ "timestamp": "2026-03-17T16:32:40.323Z",
17
+ "totalUpdated": 3
18
+ }
package/cjs/config.js ADDED
File without changes
package/cjs/index.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
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
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.TypeScriptDocumentsVisitor = exports.plugin = void 0;
27
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
28
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
29
+ const graphql_1 = require("graphql");
30
+ const visitor_js_1 = require("./visitor.js");
31
+ 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;
34
+ const documents = config.flattenGeneratedTypes
35
+ ? (0, visitor_plugin_common_1.optimizeOperations)(schema, rawDocuments, {
36
+ includeFragments: config.flattenGeneratedTypesIncludeFragments,
37
+ })
38
+ : 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, {
51
+ leave: visitor,
52
+ });
53
+ let content = visitorResult.definitions.join('\n');
54
+ if (config.addOperationExport) {
55
+ const exportConsts = [];
56
+ for (const d of allAst.definitions) {
57
+ if ('name' in d) {
58
+ exportConsts.push(`export declare const ${d.name.value}: import("graphql").DocumentNode;`);
59
+ }
60
+ }
61
+ content = visitorResult.definitions.concat(exportConsts).join('\n');
62
+ }
63
+ if (config.globalNamespace) {
64
+ content = `
65
+ declare global {
66
+ ${content}
67
+ }`;
68
+ }
69
+ return {
70
+ prepend: [...visitor.getImports(), ...visitor.getGlobalDeclarations(visitor.config.noExport)],
71
+ content,
72
+ };
73
+ };
74
+ exports.plugin = plugin;
75
+ const semanticToStrict = async (schema) => {
76
+ try {
77
+ const sock = await Promise.resolve().then(() => __importStar(require('graphql-sock')));
78
+ return sock.semanticToStrict(schema);
79
+ }
80
+ catch {
81
+ throw new Error("To use the `nullability.errorHandlingClient` option, you must install the 'graphql-sock' package.");
82
+ }
83
+ };
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeScriptOperationVariablesToObject = void 0;
4
+ const typescript_1 = require("@graphql-codegen/typescript");
5
+ class TypeScriptOperationVariablesToObject extends typescript_1.TypeScriptOperationVariablesToObject {
6
+ formatTypeString(fieldType, _isNonNullType, _hasDefaultValue) {
7
+ return fieldType;
8
+ }
9
+ }
10
+ exports.TypeScriptOperationVariablesToObject = TypeScriptOperationVariablesToObject;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeScriptSelectionSetProcessor = void 0;
4
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
5
+ class TypeScriptSelectionSetProcessor extends visitor_plugin_common_1.BaseSelectionSetProcessor {
6
+ transformPrimitiveFields(schemaType, fields, unsetTypes) {
7
+ if (fields.length === 0) {
8
+ return [];
9
+ }
10
+ const parentName = (this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '') +
11
+ this.config.convertName(schemaType.name, {
12
+ useTypesPrefix: true,
13
+ });
14
+ if (unsetTypes) {
15
+ const escapedFieldNames = fields.map(field => `'${field.fieldName}'`);
16
+ return [formattedUnionTransform('MakeEmpty', parentName, escapedFieldNames)];
17
+ }
18
+ let hasConditionals = false;
19
+ const escapedConditionalsList = [];
20
+ const escapedFieldNames = fields.map(field => {
21
+ if (field.isConditional) {
22
+ hasConditionals = true;
23
+ escapedConditionalsList.push(`'${field.fieldName}'`);
24
+ }
25
+ return `'${field.fieldName}'`;
26
+ });
27
+ let resString = formattedUnionTransform('Pick', parentName, escapedFieldNames);
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)}`;
38
+ }
39
+ return [resString];
40
+ }
41
+ transformTypenameField(type, name) {
42
+ return [`{ ${name}: ${type} }`];
43
+ }
44
+ transformAliasesPrimitiveFields(schemaType, fields) {
45
+ if (fields.length === 0) {
46
+ return [];
47
+ }
48
+ const parentName = (this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '') +
49
+ this.config.convertName(schemaType.name, {
50
+ useTypesPrefix: true,
51
+ });
52
+ const selections = fields.map(aliasedField => {
53
+ const value = aliasedField.fieldName === '__typename' ? `'${schemaType.name}'` : `${parentName}['${aliasedField.fieldName}']`;
54
+ return `${aliasedField.alias}: ${value}`;
55
+ });
56
+ return [formatSelections(selections)];
57
+ }
58
+ transformLinkFields(fields) {
59
+ if (fields.length === 0) {
60
+ return [];
61
+ }
62
+ const selections = fields.map(field => `${field.alias || field.name}: ${field.selectionSet}`);
63
+ return [formatSelections(selections)];
64
+ }
65
+ }
66
+ exports.TypeScriptSelectionSetProcessor = TypeScriptSelectionSetProcessor;
67
+ /** Equivalent to `${transformName}<${target}, ${unionElements.join(' | ')}>`, but with line feeds if necessary */
68
+ function formattedUnionTransform(transformName, target, unionElements) {
69
+ if (unionElements.length > 3) {
70
+ return `${transformName}<\n ${target},\n | ${unionElements.join('\n | ')}\n >`;
71
+ }
72
+ return `${transformName}<${target}, ${unionElements.join(' | ')}>`;
73
+ }
74
+ /** Equivalent to `{ ${selections.join(', ')} }`, but with line feeds if necessary */
75
+ function formatSelections(selections) {
76
+ if (selections.length > 1) {
77
+ return `{\n ${selections.map(s => s.replace(/\n/g, '\n ')).join(',\n ')},\n }`;
78
+ }
79
+ return `{ ${selections.join(', ')} }`;
80
+ }
package/cjs/visitor.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeScriptDocumentsVisitor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
+ const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
7
+ const graphql_1 = require("graphql");
8
+ const ts_operation_variables_to_object_js_1 = require("./ts-operation-variables-to-object.js");
9
+ const ts_selection_set_processor_js_1 = require("./ts-selection-set-processor.js");
10
+ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVisitor {
11
+ constructor(schema, config, allFragments) {
12
+ super(config, {
13
+ arrayInputCoercion: (0, visitor_plugin_common_1.getConfigValue)(config.arrayInputCoercion, true),
14
+ noExport: (0, visitor_plugin_common_1.getConfigValue)(config.noExport, false),
15
+ avoidOptionals: (0, visitor_plugin_common_1.normalizeAvoidOptionals)((0, visitor_plugin_common_1.getConfigValue)(config.avoidOptionals, false)),
16
+ immutableTypes: (0, visitor_plugin_common_1.getConfigValue)(config.immutableTypes, false),
17
+ nonOptionalTypename: (0, visitor_plugin_common_1.getConfigValue)(config.nonOptionalTypename, false),
18
+ preResolveTypes: (0, visitor_plugin_common_1.getConfigValue)(config.preResolveTypes, true),
19
+ mergeFragmentTypes: (0, visitor_plugin_common_1.getConfigValue)(config.mergeFragmentTypes, false),
20
+ allowUndefinedQueryVariables: (0, visitor_plugin_common_1.getConfigValue)(config.allowUndefinedQueryVariables, false),
21
+ }, schema);
22
+ (0, auto_bind_1.default)(this);
23
+ const preResolveTypes = (0, visitor_plugin_common_1.getConfigValue)(config.preResolveTypes, true);
24
+ const defaultMaybeValue = 'T | null';
25
+ const maybeValue = (0, visitor_plugin_common_1.getConfigValue)(config.maybeValue, defaultMaybeValue);
26
+ const wrapOptional = (type) => {
27
+ if (preResolveTypes === true) {
28
+ return maybeValue.replace('T', type);
29
+ }
30
+ const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '';
31
+ return `${prefix}Maybe<${type}>`;
32
+ };
33
+ const wrapArray = (type) => {
34
+ const listModifier = this.config.immutableTypes ? 'ReadonlyArray' : 'Array';
35
+ return `${listModifier}<${type}>`;
36
+ };
37
+ const formatNamedField = (name, type, isConditional = false, isOptional = false) => {
38
+ const optional = isOptional || isConditional || (!this.config.avoidOptionals.field && !!type && !(0, graphql_1.isNonNullType)(type));
39
+ return (this.config.immutableTypes ? `readonly ${name}` : name) + (optional ? '?' : '');
40
+ };
41
+ const processorConfig = {
42
+ namespacedImportName: this.config.namespacedImportName,
43
+ convertName: this.convertName.bind(this),
44
+ enumPrefix: this.config.enumPrefix,
45
+ enumSuffix: this.config.enumSuffix,
46
+ scalars: this.scalars,
47
+ formatNamedField,
48
+ wrapTypeWithModifiers(baseType, type) {
49
+ return (0, visitor_plugin_common_1.wrapTypeWithModifiers)(baseType, type, { wrapOptional, wrapArray });
50
+ },
51
+ avoidOptionals: this.config.avoidOptionals,
52
+ printFieldsOnNewLines: this.config.printFieldsOnNewLines,
53
+ };
54
+ const processor = new (preResolveTypes ? visitor_plugin_common_1.PreResolveTypesProcessor : ts_selection_set_processor_js_1.TypeScriptSelectionSetProcessor)(processorConfig);
55
+ this.setSelectionSetHandler(new visitor_plugin_common_1.SelectionSetToObject(processor, this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config));
56
+ const enumsNames = Object.keys(schema.getTypeMap()).filter(typeName => (0, graphql_1.isEnumType)(schema.getType(typeName)));
57
+ this.setVariablesTransformer(new ts_operation_variables_to_object_js_1.TypeScriptOperationVariablesToObject(this.scalars, this.convertName.bind(this), this.config.avoidOptionals, this.config.immutableTypes, this.config.namespacedImportName, enumsNames, this.config.enumPrefix, this.config.enumSuffix, this.config.enumValues, this.config.arrayInputCoercion, undefined, 'InputMaybe'));
58
+ this._declarationBlockConfig = {
59
+ ignoreExport: this.config.noExport,
60
+ };
61
+ }
62
+ getImports() {
63
+ return !this.config.globalNamespace &&
64
+ (this.config.inlineFragmentTypes === 'combine' || this.config.inlineFragmentTypes === 'mask')
65
+ ? this.config.fragmentImports.map(fragmentImport => (0, visitor_plugin_common_1.generateFragmentImportStatement)(fragmentImport, 'type'))
66
+ : [];
67
+ }
68
+ getPunctuation(_declarationKind) {
69
+ return ';';
70
+ }
71
+ applyVariablesWrapper(variablesBlock, operationType) {
72
+ const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '';
73
+ const extraType = this.config.allowUndefinedQueryVariables && operationType === 'Query' ? ' | undefined' : '';
74
+ return `${prefix}Exact<${variablesBlock === '{}' ? `{ [key: string]: never; }` : variablesBlock}>${extraType}`;
75
+ }
76
+ }
77
+ exports.TypeScriptDocumentsVisitor = TypeScriptDocumentsVisitor;
package/esm/config.js ADDED
File without changes
package/esm/index.js ADDED
@@ -0,0 +1,56 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { optimizeOperations } from '@graphql-codegen/visitor-plugin-common';
3
+ import { concatAST, Kind } from 'graphql';
4
+ import { TypeScriptDocumentsVisitor } from './visitor.js';
5
+ export const plugin = async (inputSchema, rawDocuments, config) => {
6
+ const schema = config.nullability?.errorHandlingClient ? await semanticToStrict(inputSchema) : inputSchema;
7
+ const documents = config.flattenGeneratedTypes
8
+ ? optimizeOperations(schema, rawDocuments, {
9
+ includeFragments: config.flattenGeneratedTypesIncludeFragments,
10
+ })
11
+ : rawDocuments;
12
+ const allAst = concatAST(documents.map(v => v.document));
13
+ const allFragments = [
14
+ ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
15
+ node: fragmentDef,
16
+ name: fragmentDef.name.value,
17
+ onType: fragmentDef.typeCondition.name.value,
18
+ isExternal: false,
19
+ })),
20
+ ...(config.externalFragments || []),
21
+ ];
22
+ const visitor = new TypeScriptDocumentsVisitor(schema, config, allFragments);
23
+ const visitorResult = oldVisit(allAst, {
24
+ leave: visitor,
25
+ });
26
+ let content = visitorResult.definitions.join('\n');
27
+ if (config.addOperationExport) {
28
+ const exportConsts = [];
29
+ for (const d of allAst.definitions) {
30
+ if ('name' in d) {
31
+ exportConsts.push(`export declare const ${d.name.value}: import("graphql").DocumentNode;`);
32
+ }
33
+ }
34
+ content = visitorResult.definitions.concat(exportConsts).join('\n');
35
+ }
36
+ if (config.globalNamespace) {
37
+ content = `
38
+ declare global {
39
+ ${content}
40
+ }`;
41
+ }
42
+ return {
43
+ prepend: [...visitor.getImports(), ...visitor.getGlobalDeclarations(visitor.config.noExport)],
44
+ content,
45
+ };
46
+ };
47
+ export { TypeScriptDocumentsVisitor };
48
+ const semanticToStrict = async (schema) => {
49
+ try {
50
+ const sock = await import('graphql-sock');
51
+ return sock.semanticToStrict(schema);
52
+ }
53
+ catch {
54
+ throw new Error("To use the `nullability.errorHandlingClient` option, you must install the 'graphql-sock' package.");
55
+ }
56
+ };
@@ -0,0 +1,6 @@
1
+ import { TypeScriptOperationVariablesToObject as TSOperationVariablesToObject } from '@graphql-codegen/typescript';
2
+ export class TypeScriptOperationVariablesToObject extends TSOperationVariablesToObject {
3
+ formatTypeString(fieldType, _isNonNullType, _hasDefaultValue) {
4
+ return fieldType;
5
+ }
6
+ }
@@ -0,0 +1,76 @@
1
+ import { BaseSelectionSetProcessor, } from '@graphql-codegen/visitor-plugin-common';
2
+ export class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor {
3
+ transformPrimitiveFields(schemaType, fields, unsetTypes) {
4
+ if (fields.length === 0) {
5
+ return [];
6
+ }
7
+ const parentName = (this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '') +
8
+ this.config.convertName(schemaType.name, {
9
+ useTypesPrefix: true,
10
+ });
11
+ if (unsetTypes) {
12
+ const escapedFieldNames = fields.map(field => `'${field.fieldName}'`);
13
+ return [formattedUnionTransform('MakeEmpty', parentName, escapedFieldNames)];
14
+ }
15
+ let hasConditionals = false;
16
+ const escapedConditionalsList = [];
17
+ const escapedFieldNames = fields.map(field => {
18
+ if (field.isConditional) {
19
+ hasConditionals = true;
20
+ escapedConditionalsList.push(`'${field.fieldName}'`);
21
+ }
22
+ return `'${field.fieldName}'`;
23
+ });
24
+ let resString = formattedUnionTransform('Pick', parentName, escapedFieldNames);
25
+ if (hasConditionals) {
26
+ const avoidOptional =
27
+ // TODO: check type and exec only if relevant
28
+ this.config.avoidOptionals === true ||
29
+ (typeof this.config.avoidOptionals === 'object' &&
30
+ (this.config.avoidOptionals.field ||
31
+ this.config.avoidOptionals.inputValue ||
32
+ this.config.avoidOptionals.object));
33
+ const transform = avoidOptional ? 'MakeMaybe' : 'MakeOptional';
34
+ resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${formattedUnionTransform(transform, resString, escapedConditionalsList)}`;
35
+ }
36
+ return [resString];
37
+ }
38
+ transformTypenameField(type, name) {
39
+ return [`{ ${name}: ${type} }`];
40
+ }
41
+ transformAliasesPrimitiveFields(schemaType, fields) {
42
+ if (fields.length === 0) {
43
+ return [];
44
+ }
45
+ const parentName = (this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '') +
46
+ this.config.convertName(schemaType.name, {
47
+ useTypesPrefix: true,
48
+ });
49
+ const selections = fields.map(aliasedField => {
50
+ const value = aliasedField.fieldName === '__typename' ? `'${schemaType.name}'` : `${parentName}['${aliasedField.fieldName}']`;
51
+ return `${aliasedField.alias}: ${value}`;
52
+ });
53
+ return [formatSelections(selections)];
54
+ }
55
+ transformLinkFields(fields) {
56
+ if (fields.length === 0) {
57
+ return [];
58
+ }
59
+ const selections = fields.map(field => `${field.alias || field.name}: ${field.selectionSet}`);
60
+ return [formatSelections(selections)];
61
+ }
62
+ }
63
+ /** Equivalent to `${transformName}<${target}, ${unionElements.join(' | ')}>`, but with line feeds if necessary */
64
+ function formattedUnionTransform(transformName, target, unionElements) {
65
+ if (unionElements.length > 3) {
66
+ return `${transformName}<\n ${target},\n | ${unionElements.join('\n | ')}\n >`;
67
+ }
68
+ return `${transformName}<${target}, ${unionElements.join(' | ')}>`;
69
+ }
70
+ /** Equivalent to `{ ${selections.join(', ')} }`, but with line feeds if necessary */
71
+ function formatSelections(selections) {
72
+ if (selections.length > 1) {
73
+ return `{\n ${selections.map(s => s.replace(/\n/g, '\n ')).join(',\n ')},\n }`;
74
+ }
75
+ return `{ ${selections.join(', ')} }`;
76
+ }
package/esm/visitor.js ADDED
@@ -0,0 +1,72 @@
1
+ import { BaseDocumentsVisitor, generateFragmentImportStatement, getConfigValue, normalizeAvoidOptionals, PreResolveTypesProcessor, SelectionSetToObject, wrapTypeWithModifiers, } from '@graphql-codegen/visitor-plugin-common';
2
+ import autoBind from 'auto-bind';
3
+ import { isEnumType, isNonNullType } from 'graphql';
4
+ import { TypeScriptOperationVariablesToObject } from './ts-operation-variables-to-object.js';
5
+ import { TypeScriptSelectionSetProcessor } from './ts-selection-set-processor.js';
6
+ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
7
+ constructor(schema, config, allFragments) {
8
+ super(config, {
9
+ arrayInputCoercion: getConfigValue(config.arrayInputCoercion, true),
10
+ noExport: getConfigValue(config.noExport, false),
11
+ avoidOptionals: normalizeAvoidOptionals(getConfigValue(config.avoidOptionals, false)),
12
+ immutableTypes: getConfigValue(config.immutableTypes, false),
13
+ nonOptionalTypename: getConfigValue(config.nonOptionalTypename, false),
14
+ preResolveTypes: getConfigValue(config.preResolveTypes, true),
15
+ mergeFragmentTypes: getConfigValue(config.mergeFragmentTypes, false),
16
+ allowUndefinedQueryVariables: getConfigValue(config.allowUndefinedQueryVariables, false),
17
+ }, schema);
18
+ autoBind(this);
19
+ const preResolveTypes = getConfigValue(config.preResolveTypes, true);
20
+ const defaultMaybeValue = 'T | null';
21
+ const maybeValue = getConfigValue(config.maybeValue, defaultMaybeValue);
22
+ const wrapOptional = (type) => {
23
+ if (preResolveTypes === true) {
24
+ return maybeValue.replace('T', type);
25
+ }
26
+ const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '';
27
+ return `${prefix}Maybe<${type}>`;
28
+ };
29
+ const wrapArray = (type) => {
30
+ const listModifier = this.config.immutableTypes ? 'ReadonlyArray' : 'Array';
31
+ return `${listModifier}<${type}>`;
32
+ };
33
+ const formatNamedField = (name, type, isConditional = false, isOptional = false) => {
34
+ const optional = isOptional || isConditional || (!this.config.avoidOptionals.field && !!type && !isNonNullType(type));
35
+ return (this.config.immutableTypes ? `readonly ${name}` : name) + (optional ? '?' : '');
36
+ };
37
+ const processorConfig = {
38
+ namespacedImportName: this.config.namespacedImportName,
39
+ convertName: this.convertName.bind(this),
40
+ enumPrefix: this.config.enumPrefix,
41
+ enumSuffix: this.config.enumSuffix,
42
+ scalars: this.scalars,
43
+ formatNamedField,
44
+ wrapTypeWithModifiers(baseType, type) {
45
+ return wrapTypeWithModifiers(baseType, type, { wrapOptional, wrapArray });
46
+ },
47
+ avoidOptionals: this.config.avoidOptionals,
48
+ printFieldsOnNewLines: this.config.printFieldsOnNewLines,
49
+ };
50
+ const processor = new (preResolveTypes ? PreResolveTypesProcessor : TypeScriptSelectionSetProcessor)(processorConfig);
51
+ this.setSelectionSetHandler(new SelectionSetToObject(processor, this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config));
52
+ const enumsNames = Object.keys(schema.getTypeMap()).filter(typeName => isEnumType(schema.getType(typeName)));
53
+ this.setVariablesTransformer(new TypeScriptOperationVariablesToObject(this.scalars, this.convertName.bind(this), this.config.avoidOptionals, this.config.immutableTypes, this.config.namespacedImportName, enumsNames, this.config.enumPrefix, this.config.enumSuffix, this.config.enumValues, this.config.arrayInputCoercion, undefined, 'InputMaybe'));
54
+ this._declarationBlockConfig = {
55
+ ignoreExport: this.config.noExport,
56
+ };
57
+ }
58
+ getImports() {
59
+ return !this.config.globalNamespace &&
60
+ (this.config.inlineFragmentTypes === 'combine' || this.config.inlineFragmentTypes === 'mask')
61
+ ? this.config.fragmentImports.map(fragmentImport => generateFragmentImportStatement(fragmentImport, 'type'))
62
+ : [];
63
+ }
64
+ getPunctuation(_declarationKind) {
65
+ return ';';
66
+ }
67
+ applyVariablesWrapper(variablesBlock, operationType) {
68
+ const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '';
69
+ const extraType = this.config.allowUndefinedQueryVariables && operationType === 'Query' ? ' | undefined' : '';
70
+ return `${prefix}Exact<${variablesBlock === '{}' ? `{ [key: string]: never; }` : variablesBlock}>${extraType}`;
71
+ }
72
+ }
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@depup/graphql-codegen__typescript-operations",
3
+ "version": "5.0.9-depup.0",
4
+ "description": "[DepUp] GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments",
5
+ "peerDependenciesMeta": {
6
+ "graphql-sock": {
7
+ "optional": true
8
+ }
9
+ },
10
+ "peerDependencies": {
11
+ "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",
12
+ "graphql-sock": "^1.0.0"
13
+ },
14
+ "dependencies": {
15
+ "@graphql-codegen/plugin-helpers": "^6.2.0",
16
+ "@graphql-codegen/typescript": "^5.0.9",
17
+ "@graphql-codegen/visitor-plugin-common": "^6.2.4",
18
+ "auto-bind": "^5.0.1",
19
+ "tslib": "^2.8.1"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/dotansimha/graphql-code-generator.git",
24
+ "directory": "packages/plugins/typescript/operations"
25
+ },
26
+ "license": "MIT",
27
+ "engines": {
28
+ "node": ">=16"
29
+ },
30
+ "main": "cjs/index.js",
31
+ "module": "esm/index.js",
32
+ "typings": "typings/index.d.ts",
33
+ "typescript": {
34
+ "definition": "typings/index.d.ts"
35
+ },
36
+ "type": "module",
37
+ "exports": {
38
+ ".": {
39
+ "require": {
40
+ "types": "./typings/index.d.cts",
41
+ "default": "./cjs/index.js"
42
+ },
43
+ "import": {
44
+ "types": "./typings/index.d.ts",
45
+ "default": "./esm/index.js"
46
+ },
47
+ "default": {
48
+ "types": "./typings/index.d.ts",
49
+ "default": "./esm/index.js"
50
+ }
51
+ },
52
+ "./package.json": "./package.json"
53
+ },
54
+ "keywords": [
55
+ "depup",
56
+ "dependency-bumped",
57
+ "updated-deps",
58
+ "@graphql-codegen/typescript-operations"
59
+ ],
60
+ "depup": {
61
+ "changes": {
62
+ "@graphql-codegen/plugin-helpers": {
63
+ "from": "^6.1.1",
64
+ "to": "^6.2.0"
65
+ },
66
+ "auto-bind": {
67
+ "from": "~4.0.0",
68
+ "to": "^5.0.1"
69
+ },
70
+ "tslib": {
71
+ "from": "~2.6.0",
72
+ "to": "^2.8.1"
73
+ }
74
+ },
75
+ "depsUpdated": 3,
76
+ "originalPackage": "@graphql-codegen/typescript-operations",
77
+ "originalVersion": "5.0.9",
78
+ "processedAt": "2026-03-17T16:32:45.868Z",
79
+ "smokeTest": "passed"
80
+ }
81
+ }