@graphql-codegen/typescript-operations 6.0.0-alpha-20251228140020-a092ba2d84c819dfbb62365e419f28df54571fbe → 6.0.0-alpha-20260101112751-5609723f4ba2f3da5adf38c7347e2569216e3b5a
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/visitor.js
CHANGED
|
@@ -6,7 +6,6 @@ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common"
|
|
|
6
6
|
const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
|
|
7
7
|
const graphql_1 = require("graphql");
|
|
8
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
9
|
class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVisitor {
|
|
11
10
|
_usedNamedInputTypes = {};
|
|
12
11
|
_outputPath;
|
|
@@ -17,7 +16,6 @@ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVi
|
|
|
17
16
|
avoidOptionals: (0, visitor_plugin_common_1.normalizeAvoidOptionals)((0, visitor_plugin_common_1.getConfigValue)(config.avoidOptionals, false)),
|
|
18
17
|
immutableTypes: (0, visitor_plugin_common_1.getConfigValue)(config.immutableTypes, false),
|
|
19
18
|
nonOptionalTypename: (0, visitor_plugin_common_1.getConfigValue)(config.nonOptionalTypename, false),
|
|
20
|
-
preResolveTypes: (0, visitor_plugin_common_1.getConfigValue)(config.preResolveTypes, true),
|
|
21
19
|
mergeFragmentTypes: (0, visitor_plugin_common_1.getConfigValue)(config.mergeFragmentTypes, false),
|
|
22
20
|
allowUndefinedQueryVariables: (0, visitor_plugin_common_1.getConfigValue)(config.allowUndefinedQueryVariables, false),
|
|
23
21
|
enumType: (0, visitor_plugin_common_1.getConfigValue)(config.enumType, 'string-literal'),
|
|
@@ -30,20 +28,8 @@ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVi
|
|
|
30
28
|
}, schema);
|
|
31
29
|
this._outputPath = outputPath;
|
|
32
30
|
(0, auto_bind_1.default)(this);
|
|
33
|
-
const preResolveTypes = (0, visitor_plugin_common_1.getConfigValue)(config.preResolveTypes, true);
|
|
34
31
|
const defaultMaybeValue = 'T | null';
|
|
35
32
|
const maybeValue = (0, visitor_plugin_common_1.getConfigValue)(config.maybeValue, defaultMaybeValue);
|
|
36
|
-
const wrapOptional = (type) => {
|
|
37
|
-
if (preResolveTypes === true) {
|
|
38
|
-
return maybeValue.replace('T', type);
|
|
39
|
-
}
|
|
40
|
-
const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '';
|
|
41
|
-
return `${prefix}Maybe<${type}>`;
|
|
42
|
-
};
|
|
43
|
-
const wrapArray = (type) => {
|
|
44
|
-
const listModifier = this.config.immutableTypes ? 'ReadonlyArray' : 'Array';
|
|
45
|
-
return `${listModifier}<${type}>`;
|
|
46
|
-
};
|
|
47
33
|
const allFragments = [
|
|
48
34
|
...documentNode.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
49
35
|
node: fragmentDef,
|
|
@@ -63,12 +49,18 @@ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVi
|
|
|
63
49
|
formatNamedField: ({ name, isOptional }) => {
|
|
64
50
|
return (this.config.immutableTypes ? `readonly ${name}` : name) + (isOptional ? '?' : '');
|
|
65
51
|
},
|
|
66
|
-
wrapTypeWithModifiers(baseType, type) {
|
|
67
|
-
return (0, visitor_plugin_common_1.wrapTypeWithModifiers)(baseType, type, {
|
|
52
|
+
wrapTypeWithModifiers: (baseType, type) => {
|
|
53
|
+
return (0, visitor_plugin_common_1.wrapTypeWithModifiers)(baseType, type, {
|
|
54
|
+
wrapOptional: type => maybeValue.replace('T', type),
|
|
55
|
+
wrapArray: type => {
|
|
56
|
+
const listModifier = this.config.immutableTypes ? 'ReadonlyArray' : 'Array';
|
|
57
|
+
return `${listModifier}<${type}>`;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
68
60
|
},
|
|
69
61
|
printFieldsOnNewLines: this.config.printFieldsOnNewLines,
|
|
70
62
|
};
|
|
71
|
-
const processor = new
|
|
63
|
+
const processor = new visitor_plugin_common_1.PreResolveTypesProcessor(processorConfig);
|
|
72
64
|
this.setSelectionSetHandler(new visitor_plugin_common_1.SelectionSetToObject(processor, this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config));
|
|
73
65
|
const enumsNames = Object.keys(schema.getTypeMap()).filter(typeName => (0, graphql_1.isEnumType)(schema.getType(typeName)));
|
|
74
66
|
this.setVariablesTransformer(new ts_operation_variables_to_object_js_1.TypeScriptOperationVariablesToObject(this.scalars, this.convertName.bind(this),
|
package/esm/visitor.js
CHANGED
|
@@ -2,7 +2,6 @@ import { BaseDocumentsVisitor, convertSchemaEnumToDeclarationBlockString, Declar
|
|
|
2
2
|
import autoBind from 'auto-bind';
|
|
3
3
|
import { getNamedType, GraphQLEnumType, GraphQLInputObjectType, GraphQLScalarType, isEnumType, Kind, TypeInfo, visit, visitWithTypeInfo, } from 'graphql';
|
|
4
4
|
import { TypeScriptOperationVariablesToObject, SCALARS } from './ts-operation-variables-to-object.js';
|
|
5
|
-
import { TypeScriptSelectionSetProcessor } from './ts-selection-set-processor.js';
|
|
6
5
|
export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
|
|
7
6
|
_usedNamedInputTypes = {};
|
|
8
7
|
_outputPath;
|
|
@@ -13,7 +12,6 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
|
|
|
13
12
|
avoidOptionals: normalizeAvoidOptionals(getConfigValue(config.avoidOptionals, false)),
|
|
14
13
|
immutableTypes: getConfigValue(config.immutableTypes, false),
|
|
15
14
|
nonOptionalTypename: getConfigValue(config.nonOptionalTypename, false),
|
|
16
|
-
preResolveTypes: getConfigValue(config.preResolveTypes, true),
|
|
17
15
|
mergeFragmentTypes: getConfigValue(config.mergeFragmentTypes, false),
|
|
18
16
|
allowUndefinedQueryVariables: getConfigValue(config.allowUndefinedQueryVariables, false),
|
|
19
17
|
enumType: getConfigValue(config.enumType, 'string-literal'),
|
|
@@ -26,20 +24,8 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
|
|
|
26
24
|
}, schema);
|
|
27
25
|
this._outputPath = outputPath;
|
|
28
26
|
autoBind(this);
|
|
29
|
-
const preResolveTypes = getConfigValue(config.preResolveTypes, true);
|
|
30
27
|
const defaultMaybeValue = 'T | null';
|
|
31
28
|
const maybeValue = getConfigValue(config.maybeValue, defaultMaybeValue);
|
|
32
|
-
const wrapOptional = (type) => {
|
|
33
|
-
if (preResolveTypes === true) {
|
|
34
|
-
return maybeValue.replace('T', type);
|
|
35
|
-
}
|
|
36
|
-
const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '';
|
|
37
|
-
return `${prefix}Maybe<${type}>`;
|
|
38
|
-
};
|
|
39
|
-
const wrapArray = (type) => {
|
|
40
|
-
const listModifier = this.config.immutableTypes ? 'ReadonlyArray' : 'Array';
|
|
41
|
-
return `${listModifier}<${type}>`;
|
|
42
|
-
};
|
|
43
29
|
const allFragments = [
|
|
44
30
|
...documentNode.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
45
31
|
node: fragmentDef,
|
|
@@ -59,12 +45,18 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
|
|
|
59
45
|
formatNamedField: ({ name, isOptional }) => {
|
|
60
46
|
return (this.config.immutableTypes ? `readonly ${name}` : name) + (isOptional ? '?' : '');
|
|
61
47
|
},
|
|
62
|
-
wrapTypeWithModifiers(baseType, type) {
|
|
63
|
-
return wrapTypeWithModifiers(baseType, type, {
|
|
48
|
+
wrapTypeWithModifiers: (baseType, type) => {
|
|
49
|
+
return wrapTypeWithModifiers(baseType, type, {
|
|
50
|
+
wrapOptional: type => maybeValue.replace('T', type),
|
|
51
|
+
wrapArray: type => {
|
|
52
|
+
const listModifier = this.config.immutableTypes ? 'ReadonlyArray' : 'Array';
|
|
53
|
+
return `${listModifier}<${type}>`;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
64
56
|
},
|
|
65
57
|
printFieldsOnNewLines: this.config.printFieldsOnNewLines,
|
|
66
58
|
};
|
|
67
|
-
const processor = new
|
|
59
|
+
const processor = new PreResolveTypesProcessor(processorConfig);
|
|
68
60
|
this.setSelectionSetHandler(new SelectionSetToObject(processor, this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config));
|
|
69
61
|
const enumsNames = Object.keys(schema.getTypeMap()).filter(typeName => isEnumType(schema.getType(typeName)));
|
|
70
62
|
this.setVariablesTransformer(new TypeScriptOperationVariablesToObject(this.scalars, this.convertName.bind(this),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-operations",
|
|
3
|
-
"version": "6.0.0-alpha-
|
|
3
|
+
"version": "6.0.0-alpha-20260101112751-5609723f4ba2f3da5adf38c7347e2569216e3b5a",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments",
|
|
5
5
|
"peerDependenciesMeta": {
|
|
6
6
|
"graphql-sock": {
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@graphql-codegen/plugin-helpers": "^6.0.0",
|
|
16
|
-
"@graphql-codegen/typescript": "6.0.0-alpha-
|
|
16
|
+
"@graphql-codegen/typescript": "6.0.0-alpha-20260101112751-5609723f4ba2f3da5adf38c7347e2569216e3b5a",
|
|
17
17
|
"@graphql-codegen/schema-ast": "^5.0.0",
|
|
18
|
-
"@graphql-codegen/visitor-plugin-common": "7.0.0-alpha-
|
|
18
|
+
"@graphql-codegen/visitor-plugin-common": "7.0.0-alpha-20260101112751-5609723f4ba2f3da5adf38c7347e2569216e3b5a",
|
|
19
19
|
"auto-bind": "~4.0.0",
|
|
20
20
|
"tslib": "~2.6.0"
|
|
21
21
|
},
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${formattedUnionTransform('MakeOptional', resString, escapedConditionalsList)}`;
|
|
30
|
-
}
|
|
31
|
-
return [resString];
|
|
32
|
-
}
|
|
33
|
-
transformTypenameField(type, name) {
|
|
34
|
-
return [`{ ${name}: ${type} }`];
|
|
35
|
-
}
|
|
36
|
-
transformAliasesPrimitiveFields(schemaType, fields) {
|
|
37
|
-
if (fields.length === 0) {
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
40
|
-
const parentName = (this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '') +
|
|
41
|
-
this.config.convertName(schemaType.name, {
|
|
42
|
-
useTypesPrefix: true,
|
|
43
|
-
});
|
|
44
|
-
const selections = fields.map(aliasedField => {
|
|
45
|
-
const value = aliasedField.fieldName === '__typename' ? `'${schemaType.name}'` : `${parentName}['${aliasedField.fieldName}']`;
|
|
46
|
-
return `${aliasedField.alias}: ${value}`;
|
|
47
|
-
});
|
|
48
|
-
return [formatSelections(selections)];
|
|
49
|
-
}
|
|
50
|
-
transformLinkFields(fields) {
|
|
51
|
-
if (fields.length === 0) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
const selections = fields.map(field => `${field.alias || field.name}: ${field.selectionSet}`);
|
|
55
|
-
return [formatSelections(selections)];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.TypeScriptSelectionSetProcessor = TypeScriptSelectionSetProcessor;
|
|
59
|
-
/** Equivalent to `${transformName}<${target}, ${unionElements.join(' | ')}>`, but with line feeds if necessary */
|
|
60
|
-
function formattedUnionTransform(transformName, target, unionElements) {
|
|
61
|
-
if (unionElements.length > 3) {
|
|
62
|
-
return `${transformName}<\n ${target},\n | ${unionElements.join('\n | ')}\n >`;
|
|
63
|
-
}
|
|
64
|
-
return `${transformName}<${target}, ${unionElements.join(' | ')}>`;
|
|
65
|
-
}
|
|
66
|
-
/** Equivalent to `{ ${selections.join(', ')} }`, but with line feeds if necessary */
|
|
67
|
-
function formatSelections(selections) {
|
|
68
|
-
if (selections.length > 1) {
|
|
69
|
-
return `{\n ${selections.map(s => s.replace(/\n/g, '\n ')).join(',\n ')},\n }`;
|
|
70
|
-
}
|
|
71
|
-
return `{ ${selections.join(', ')} }`;
|
|
72
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${formattedUnionTransform('MakeOptional', resString, escapedConditionalsList)}`;
|
|
27
|
-
}
|
|
28
|
-
return [resString];
|
|
29
|
-
}
|
|
30
|
-
transformTypenameField(type, name) {
|
|
31
|
-
return [`{ ${name}: ${type} }`];
|
|
32
|
-
}
|
|
33
|
-
transformAliasesPrimitiveFields(schemaType, fields) {
|
|
34
|
-
if (fields.length === 0) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
const parentName = (this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '') +
|
|
38
|
-
this.config.convertName(schemaType.name, {
|
|
39
|
-
useTypesPrefix: true,
|
|
40
|
-
});
|
|
41
|
-
const selections = fields.map(aliasedField => {
|
|
42
|
-
const value = aliasedField.fieldName === '__typename' ? `'${schemaType.name}'` : `${parentName}['${aliasedField.fieldName}']`;
|
|
43
|
-
return `${aliasedField.alias}: ${value}`;
|
|
44
|
-
});
|
|
45
|
-
return [formatSelections(selections)];
|
|
46
|
-
}
|
|
47
|
-
transformLinkFields(fields) {
|
|
48
|
-
if (fields.length === 0) {
|
|
49
|
-
return [];
|
|
50
|
-
}
|
|
51
|
-
const selections = fields.map(field => `${field.alias || field.name}: ${field.selectionSet}`);
|
|
52
|
-
return [formatSelections(selections)];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/** Equivalent to `${transformName}<${target}, ${unionElements.join(' | ')}>`, but with line feeds if necessary */
|
|
56
|
-
function formattedUnionTransform(transformName, target, unionElements) {
|
|
57
|
-
if (unionElements.length > 3) {
|
|
58
|
-
return `${transformName}<\n ${target},\n | ${unionElements.join('\n | ')}\n >`;
|
|
59
|
-
}
|
|
60
|
-
return `${transformName}<${target}, ${unionElements.join(' | ')}>`;
|
|
61
|
-
}
|
|
62
|
-
/** Equivalent to `{ ${selections.join(', ')} }`, but with line feeds if necessary */
|
|
63
|
-
function formatSelections(selections) {
|
|
64
|
-
if (selections.length > 1) {
|
|
65
|
-
return `{\n ${selections.map(s => s.replace(/\n/g, '\n ')).join(',\n ')},\n }`;
|
|
66
|
-
}
|
|
67
|
-
return `{ ${selections.join(', ')} }`;
|
|
68
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseSelectionSetProcessor, LinkField, PrimitiveAliasedFields, PrimitiveField, ProcessResult, SelectionSetProcessorConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
-
import { GraphQLInterfaceType, GraphQLObjectType } from 'graphql';
|
|
3
|
-
export declare class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor<SelectionSetProcessorConfig> {
|
|
4
|
-
transformPrimitiveFields(schemaType: GraphQLObjectType | GraphQLInterfaceType, fields: PrimitiveField[], unsetTypes?: boolean): ProcessResult;
|
|
5
|
-
transformTypenameField(type: string, name: string): ProcessResult;
|
|
6
|
-
transformAliasesPrimitiveFields(schemaType: GraphQLObjectType | GraphQLInterfaceType, fields: PrimitiveAliasedFields[]): ProcessResult;
|
|
7
|
-
transformLinkFields(fields: LinkField[]): ProcessResult;
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseSelectionSetProcessor, LinkField, PrimitiveAliasedFields, PrimitiveField, ProcessResult, SelectionSetProcessorConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
-
import { GraphQLInterfaceType, GraphQLObjectType } from 'graphql';
|
|
3
|
-
export declare class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor<SelectionSetProcessorConfig> {
|
|
4
|
-
transformPrimitiveFields(schemaType: GraphQLObjectType | GraphQLInterfaceType, fields: PrimitiveField[], unsetTypes?: boolean): ProcessResult;
|
|
5
|
-
transformTypenameField(type: string, name: string): ProcessResult;
|
|
6
|
-
transformAliasesPrimitiveFields(schemaType: GraphQLObjectType | GraphQLInterfaceType, fields: PrimitiveAliasedFields[]): ProcessResult;
|
|
7
|
-
transformLinkFields(fields: LinkField[]): ProcessResult;
|
|
8
|
-
}
|