@vladimirdev635/gql-codegen 0.0.109 → 0.0.111
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/actors/text-diff.d.ts +2 -0
- package/actors/text-diff.js +113 -0
- package/actors/ts/gql-client/actor.d.ts +8 -2
- package/actors/ts/gql-client/actor.js +5 -5
- package/actors/ts/gql-client/generators/help-nodes/build-subscription-callback-function.d.ts +4 -0
- package/actors/ts/gql-client/generators/help-nodes/build-subscription-callback-function.js +35 -0
- package/actors/ts/gql-client/generators/help-nodes/build-sync-callback-function.d.ts +4 -0
- package/actors/ts/gql-client/generators/help-nodes/build-sync-callback-function.js +35 -0
- package/actors/ts/gql-client/generators/help-nodes/callback-arrow-func.d.ts +3 -0
- package/actors/ts/gql-client/generators/help-nodes/callback-arrow-func.js +15 -0
- package/actors/ts/gql-client/generators/help-nodes/index.d.ts +9 -0
- package/actors/ts/gql-client/generators/help-nodes/index.js +71 -0
- package/actors/ts/gql-client/generators/help-nodes/sdk-operations-type-node.d.ts +4 -0
- package/actors/ts/gql-client/generators/help-nodes/sdk-operations-type-node.js +17 -0
- package/actors/ts/gql-client/generators/help-nodes/sdk-type.d.ts +7 -0
- package/actors/ts/gql-client/generators/help-nodes/sdk-type.js +21 -0
- package/actors/ts/gql-client/generators/help-nodes/subscription-method-func-alias.d.ts +3 -0
- package/actors/ts/gql-client/generators/help-nodes/subscription-method-func-alias.js +14 -0
- package/actors/ts/gql-client/generators/help-nodes/sync-method-func-alias.d.ts +3 -0
- package/actors/ts/gql-client/generators/help-nodes/sync-method-func-alias.js +13 -0
- package/actors/ts/gql-client/generators/main.d.ts +1 -1
- package/actors/ts/gql-client/generators/main.js +41 -71
- package/actors/ts/gql-client/generators/operation-function-block.d.ts +3 -0
- package/actors/ts/gql-client/generators/operation-function-block.js +21 -0
- package/actors/ts/gql-client/generators/operation-return-type.d.ts +4 -0
- package/actors/ts/gql-client/generators/operation-return-type.js +16 -0
- package/actors/ts/gql-client-framework/actor.d.ts +42 -0
- package/actors/ts/gql-client-framework/actor.js +11 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/index.d.ts +8 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/index.js +55 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/lazy-hook-builder.d.ts +4 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/lazy-hook-builder.js +44 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/sdk-operations-type-node.d.ts +4 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/sdk-operations-type-node.js +45 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/sdk-type.d.ts +7 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/sdk-type.js +21 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/subscription-hook-builders.d.ts +4 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/subscription-hook-builders.js +52 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/sync-hook-builders.d.ts +4 -0
- package/actors/ts/gql-client-framework/generators/help-nodes/sync-hook-builders.js +52 -0
- package/actors/ts/gql-client-framework/generators/main.js +88 -0
- package/actors/ts/gql-client-framework/index.d.ts +1 -0
- package/actors/ts/gql-client-framework/index.js +1 -0
- package/actors/ts/gql-client-react/actor.d.ts +5 -11
- package/actors/ts/gql-client-react/actor.js +10 -9
- package/actors/ts/gql-client-react/index.d.ts +1 -1
- package/actors/ts/gql-client-vue/actor.d.ts +5 -11
- package/actors/ts/gql-client-vue/actor.js +27 -9
- package/actors/ts/gql-client-vue/index.d.ts +1 -1
- package/actors/ts/graphql/actor.d.ts +5 -4
- package/actors/ts/graphql/actor.js +6 -6
- package/actors/ts/graphql/generators/client/fragments/document.d.ts +5 -0
- package/actors/ts/graphql/generators/client/fragments/document.js +10 -0
- package/actors/ts/graphql/generators/client/fragments/index.d.ts +4 -0
- package/actors/ts/graphql/generators/client/fragments/index.js +24 -0
- package/actors/ts/graphql/generators/client/fragments/schema.d.ts +6 -0
- package/actors/ts/graphql/generators/client/fragments/schema.js +12 -0
- package/actors/ts/graphql/generators/client/fragments/spec/index.d.ts +5 -0
- package/actors/ts/graphql/generators/client/fragments/spec/index.js +8 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/field_selection.d.ts +7 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/field_selection.js +27 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/index.d.ts +8 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/index.js +23 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/selection.d.ts +8 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/selection.js +25 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/spread_selection.d.ts +2 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/spread_selection.js +13 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/typename_field.d.ts +5 -0
- package/actors/ts/graphql/generators/client/fragments/spec/object/typename_field.js +13 -0
- package/actors/ts/graphql/generators/client/{fragments.d.ts → fragments/spec/shared.d.ts} +5 -10
- package/actors/ts/graphql/generators/client/fragments/spec/shared.js +59 -0
- package/actors/ts/graphql/generators/client/fragments/spec/union/index.d.ts +6 -0
- package/actors/ts/graphql/generators/client/fragments/spec/union/index.js +28 -0
- package/actors/ts/graphql/generators/client/fragments/spec/union/selections.d.ts +7 -0
- package/actors/ts/graphql/generators/client/fragments/spec/union/selections.js +21 -0
- package/actors/ts/graphql/generators/client/main.d.ts +3 -3
- package/actors/ts/graphql/generators/client/main.js +5 -21
- package/actors/ts/graphql/generators/client/operations/index.d.ts +8 -0
- package/actors/ts/graphql/generators/client/operations/index.js +33 -0
- package/actors/ts/graphql/generators/client/operations/input-schema.d.ts +5 -0
- package/actors/ts/graphql/generators/client/operations/input-schema.js +16 -0
- package/actors/ts/graphql/generators/client/operations/node.d.ts +6 -0
- package/actors/ts/graphql/generators/client/operations/node.js +20 -0
- package/actors/ts/graphql/generators/client/operations/output-schema.d.ts +6 -0
- package/actors/ts/graphql/generators/client/operations/output-schema.js +8 -0
- package/actors/ts/graphql/generators/main.d.ts +2 -2
- package/actors/ts/graphql/generators/main.js +1 -1
- package/actors/ts/graphql/generators/server/inputs.d.ts +1 -1
- package/actors/ts/graphql/generators/server/inputs.js +6 -6
- package/actors/ts/graphql/generators/server/main.d.ts +2 -2
- package/actors/ts/graphql/generators/server/objects.js +2 -2
- package/actors/ts/graphql/generators/server/scalars/additional.d.ts +1 -0
- package/actors/ts/graphql/generators/server/scalars/additional.js +2 -1
- package/actors/ts/graphql/generators/server/shared.d.ts +3 -2
- package/actors/ts/graphql/generators/server/shared.js +10 -1
- package/actors/ts/graphql/generators/server/unions.js +2 -2
- package/actors/ts/graphql/index.d.ts +1 -1
- package/actors/ts/graphql/index.js +1 -1
- package/actors/ts/index.d.ts +2 -1
- package/actors/ts/index.js +1 -0
- package/actors/ts/shared.d.ts +5 -0
- package/actors/ts/utils.d.ts +2 -4
- package/actors/ts/utils.js +4 -3
- package/actors/utils.d.ts +3 -0
- package/actors/utils.js +22 -0
- package/config.d.ts +6 -1
- package/config.js +18 -1
- package/index.d.ts +1 -1
- package/index.js +1 -0
- package/main.d.ts +2 -2
- package/main.js +2 -2
- package/package.json +5 -1
- package/schema/client/operation.d.ts +3 -0
- package/actors/ts/gql-client-react/generators/main.d.ts +0 -4
- package/actors/ts/gql-client-react/generators/main.js +0 -121
- package/actors/ts/gql-client-vue/generators/main.js +0 -135
- package/actors/ts/graphql/generators/client/fragments.js +0 -195
- package/actors/ts/graphql/generators/client/operations.d.ts +0 -7
- package/actors/ts/graphql/generators/client/operations.js +0 -68
- /package/actors/ts/{gql-client-vue → gql-client-framework}/generators/main.d.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { getScalarSpecFromMapping } from './scalars/index.js';
|
|
3
3
|
import { invokeMethod } from '../../../shared.js';
|
|
4
|
-
import { generateSchemaName,
|
|
4
|
+
import { generateSchemaName, generateZodInferInterfaceType } from './shared.js';
|
|
5
5
|
function generateZodInputTypeSpec(scalarsMapping, type) {
|
|
6
6
|
switch (type._type) {
|
|
7
7
|
case 'Enum': {
|
|
@@ -41,26 +41,26 @@ function isFieldLazy(spec) {
|
|
|
41
41
|
return isFieldLazy(spec.type);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
export function generateInputTypeDefinitionFields(scalarsMapping, fields) {
|
|
44
|
+
export function generateInputTypeDefinitionFields(scalarsMapping, fields, insideLazy) {
|
|
45
45
|
return Object.entries(fields).map(([name, field]) => {
|
|
46
46
|
const fieldSpec = generateZodInputField(scalarsMapping, field);
|
|
47
|
-
if (isFieldLazy(field.spec)) {
|
|
47
|
+
if (isFieldLazy(field.spec) && !insideLazy) {
|
|
48
48
|
return ts.factory.createGetAccessorDeclaration([], name, [], undefined, ts.factory.createBlock([ts.factory.createReturnStatement(fieldSpec)], true));
|
|
49
49
|
}
|
|
50
50
|
return ts.factory.createPropertyAssignment(name, fieldSpec);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
function generateZodInputTypeDefinition(scalarsMapping, name, fields) {
|
|
53
|
+
function generateZodInputTypeDefinition(scalarsMapping, name, fields, insideLazy = false) {
|
|
54
54
|
return ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
55
55
|
ts.factory.createVariableDeclaration(generateSchemaName(name), undefined, undefined, ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), ts.factory.createIdentifier('object')), undefined, [
|
|
56
|
-
ts.factory.createObjectLiteralExpression(generateInputTypeDefinitionFields(scalarsMapping, fields), true),
|
|
56
|
+
ts.factory.createObjectLiteralExpression(generateInputTypeDefinitionFields(scalarsMapping, fields, insideLazy), true),
|
|
57
57
|
])),
|
|
58
58
|
], ts.NodeFlags.Const));
|
|
59
59
|
}
|
|
60
60
|
export function generateInputTypeDefinitions(scalarsMapping, input) {
|
|
61
61
|
return [
|
|
62
62
|
generateZodInputTypeDefinition(scalarsMapping, input.name, input.fields),
|
|
63
|
-
|
|
63
|
+
generateZodInferInterfaceType('input', input.name, generateSchemaName(input.name)),
|
|
64
64
|
ts.factory.createIdentifier('\n'),
|
|
65
65
|
];
|
|
66
66
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { Config } from '../../actor.js';
|
|
3
3
|
import { ActorContext } from '../../../../../config.js';
|
|
4
|
-
export declare function generateServerNodes(config:
|
|
4
|
+
export declare function generateServerNodes(config: Config, context: ActorContext): ts.Node[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import { getScalarSpecFromMapping } from './scalars/mapping.js';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
import { generateSchemaName,
|
|
4
|
+
import { generateSchemaName, generateZodInferInterfaceType } from './shared.js';
|
|
5
5
|
import { assertUnreachable } from '../../../../../utils.js';
|
|
6
6
|
import { invokeMethod } from '../../../shared.js';
|
|
7
7
|
function generateZodObjectTypeSpec(scalarsMapping, type) {
|
|
@@ -101,7 +101,7 @@ export function generateZodObjectTypeNode(scalarsMapping, object) {
|
|
|
101
101
|
export function generateObjectTypeNodes(scalarsMapping, object) {
|
|
102
102
|
return [
|
|
103
103
|
generateZodObjectTypeNode(scalarsMapping, object),
|
|
104
|
-
|
|
104
|
+
generateZodInferInterfaceType('output', object.name, generateSchemaName(object.name)),
|
|
105
105
|
ts.factory.createIdentifier('\n'),
|
|
106
106
|
];
|
|
107
107
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import { buildSymmetricScalarSpec } from './mapping.js';
|
|
4
3
|
import { invokeMethod } from '../../../../shared.js';
|
|
5
4
|
import { builtinScalarsMapping } from './builtin.js';
|
|
5
|
+
import { buildSymmetricScalarSpec } from './mapping.js';
|
|
6
6
|
export const additionalScalarsMapping = {
|
|
7
7
|
Int64: builtinScalarsMapping.Int,
|
|
8
8
|
UUID: builtinScalarsMapping.String,
|
|
@@ -40,4 +40,5 @@ export const additionalScalarsMapping = {
|
|
|
40
40
|
], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createNewExpression(ts.factory.createIdentifier('Date'), [], [ts.factory.createIdentifier('v')])),
|
|
41
41
|
]),
|
|
42
42
|
},
|
|
43
|
+
Duration: buildSymmetricScalarSpec(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), 'iso'), 'duration'), undefined, [])),
|
|
43
44
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import { z } from 'zod/v4';
|
|
3
1
|
import { objectNonCallableFieldSpecSchema } from '../../../../../schema/server.js';
|
|
4
2
|
import { inputFieldSpecSchema } from '../../../../../schema/shared.js';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
5
|
export declare function generateNonCallableFieldSpec(scalars: string[], spec: z.infer<typeof objectNonCallableFieldSpecSchema> | z.infer<typeof inputFieldSpecSchema>): ts.TypeNode;
|
|
6
6
|
export declare function wrapInMaybeIfNullable(spec: ts.TypeNode, nullable: boolean): ts.TypeNode;
|
|
7
7
|
export declare function generateZodInferTypeAlias(inferType: 'input' | 'output', name: string, typeName: string): ts.TypeAliasDeclaration;
|
|
8
|
+
export declare function generateZodInferInterfaceType(inferType: 'input' | 'output', name: string, typeName: string): ts.InterfaceDeclaration;
|
|
8
9
|
export declare function generateSchemaName(name: string): string;
|
|
@@ -14,10 +14,19 @@ export function wrapInMaybeIfNullable(spec, nullable) {
|
|
|
14
14
|
: spec;
|
|
15
15
|
}
|
|
16
16
|
export function generateZodInferTypeAlias(inferType, name, typeName) {
|
|
17
|
-
return ts.factory.createTypeAliasDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), name, undefined, ts.factory.
|
|
17
|
+
return ts.factory.createTypeAliasDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), name, undefined, ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier('z.' + inferType), [
|
|
18
18
|
ts.factory.createTypeQueryNode(ts.factory.createIdentifier(typeName), undefined),
|
|
19
19
|
]));
|
|
20
20
|
}
|
|
21
|
+
export function generateZodInferInterfaceType(inferType, name, typeName) {
|
|
22
|
+
return ts.factory.createInterfaceDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), name, undefined, [
|
|
23
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
|
24
|
+
ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier('z.' + inferType), [
|
|
25
|
+
ts.factory.createTypeQueryNode(ts.factory.createIdentifier(typeName), undefined),
|
|
26
|
+
]),
|
|
27
|
+
]),
|
|
28
|
+
], []);
|
|
29
|
+
}
|
|
21
30
|
export function generateSchemaName(name) {
|
|
22
31
|
return name[0].toLowerCase() + name.slice(1) + 'Schema';
|
|
23
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { generateSchemaName,
|
|
2
|
+
import { generateSchemaName, generateZodInferInterfaceType } from './shared.js';
|
|
3
3
|
import { generateZodObjectTypeExpression } from './objects.js';
|
|
4
4
|
function generateZodUnionTypeNode(scalarsMapping, objects, union) {
|
|
5
5
|
return ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
@@ -12,7 +12,7 @@ function generateZodUnionTypeNode(scalarsMapping, objects, union) {
|
|
|
12
12
|
export function generateUnionTypeDefinitions(scalarsMapping, objects, union) {
|
|
13
13
|
return [
|
|
14
14
|
generateZodUnionTypeNode(scalarsMapping, objects, union),
|
|
15
|
-
|
|
15
|
+
generateZodInferInterfaceType('output', union.name, generateSchemaName(union.name)),
|
|
16
16
|
ts.factory.createIdentifier('\n'),
|
|
17
17
|
];
|
|
18
18
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { build, Config } from './actor.js';
|
|
2
2
|
export { builtinScalarsMapping, additionalScalarsMapping, type BuiltinScalarName, type ScalarSpec, type ScalarsMapping, buildSymmetricScalarSpec, getScalarSpecFromMapping, } from './generators/server/scalars/index.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { build } from './actor.js';
|
|
2
2
|
export { builtinScalarsMapping, additionalScalarsMapping, buildSymmetricScalarSpec, getScalarSpecFromMapping, } from './generators/server/scalars/index.js';
|
package/actors/ts/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * as gqlClient from './gql-client/index.js';
|
|
2
2
|
export * as gqlClientReact from './gql-client-react/index.js';
|
|
3
3
|
export * as gqlClientVue from './gql-client-vue/index.js';
|
|
4
|
+
export * as gqlClientFramework from './gql-client-framework/index.js';
|
|
4
5
|
export * as graphql from './graphql/index.js';
|
|
5
|
-
export { type Formatter, type TSActorConfig, renderNodes, loadTsConfigCompilerOptions, addNewLineBetweenNodes, invokeMethod, } from './shared.js';
|
|
6
|
+
export { type Formatter, type TSActorConfig, type ClientTypeNameBuilders, renderNodes, loadTsConfigCompilerOptions, addNewLineBetweenNodes, invokeMethod, } from './shared.js';
|
|
6
7
|
export { generateImportDeclaration } from './utils.js';
|
|
7
8
|
export * as formatters from './formatters/index.js';
|
package/actors/ts/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * as gqlClient from './gql-client/index.js';
|
|
2
2
|
export * as gqlClientReact from './gql-client-react/index.js';
|
|
3
3
|
export * as gqlClientVue from './gql-client-vue/index.js';
|
|
4
|
+
export * as gqlClientFramework from './gql-client-framework/index.js';
|
|
4
5
|
export * as graphql from './graphql/index.js';
|
|
5
6
|
export { renderNodes, loadTsConfigCompilerOptions, addNewLineBetweenNodes, invokeMethod, } from './shared.js';
|
|
6
7
|
export { generateImportDeclaration } from './utils.js';
|
package/actors/ts/shared.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
export interface ClientTypeNameBuilders {
|
|
3
|
+
operationTypeName: (operationName: string) => string;
|
|
4
|
+
variablesTypeName: (operationName: string) => string;
|
|
5
|
+
resultTypeName: (operationName: string) => string;
|
|
6
|
+
}
|
|
2
7
|
export type Formatter = (code: string) => Promise<string> | string;
|
|
3
8
|
export interface TSActorConfig {
|
|
4
9
|
tsconfigCompilerOptions: ts.CompilerOptions;
|
package/actors/ts/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
4
|
-
alias: string;
|
|
5
|
-
})[]): ts.ImportDeclaration;
|
|
2
|
+
export declare function generateImportSpecifier(name: string, typeOnly?: boolean, alias?: string | null): ts.ImportSpecifier;
|
|
3
|
+
export declare function generateImportDeclaration(modulePath: string, imports: ts.ImportSpecifier[]): ts.ImportDeclaration;
|
package/actors/ts/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
export function generateImportSpecifier(name, typeOnly = false, alias = null) {
|
|
3
|
+
return ts.factory.createImportSpecifier(typeOnly, alias === null ? undefined : ts.factory.createIdentifier(alias), ts.factory.createIdentifier(name));
|
|
4
|
+
}
|
|
2
5
|
export function generateImportDeclaration(modulePath, imports) {
|
|
3
|
-
return ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(imports
|
|
4
|
-
? undefined
|
|
5
|
-
: ts.factory.createIdentifier(i.alias), ts.factory.createIdentifier(typeof i === 'string' ? i : i.name))))), ts.factory.createStringLiteral(modulePath));
|
|
6
|
+
return ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(imports)), ts.factory.createStringLiteral(modulePath));
|
|
6
7
|
}
|
package/actors/utils.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import { RunAction } from '../config.js';
|
|
5
|
+
import { diffLines } from 'diff';
|
|
6
|
+
import { printChanges } from './text-diff.js';
|
|
7
|
+
export function executeRunAction(outPath, action, code) {
|
|
8
|
+
switch (action) {
|
|
9
|
+
case RunAction.Generate: {
|
|
10
|
+
fs.writeFileSync(outPath, code);
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case RunAction.Validate: {
|
|
14
|
+
const fileCode = fs.readFileSync(outPath).toString();
|
|
15
|
+
if (fileCode !== code) {
|
|
16
|
+
const changes = diffLines(fileCode, code);
|
|
17
|
+
process.stdout.write(pc.blue(`${path.relative(process.cwd(), outPath.toString())}:\n`));
|
|
18
|
+
printChanges(changes);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
package/config.d.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { RootSchema } from './schema/root.js';
|
|
|
2
2
|
export interface ActorContext {
|
|
3
3
|
readonly schema: RootSchema;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export declare enum RunAction {
|
|
6
|
+
Generate = 0,
|
|
7
|
+
Validate = 1
|
|
8
|
+
}
|
|
9
|
+
export declare function runActionFromArgv(argv: string[]): RunAction;
|
|
10
|
+
export type Actor<T extends ActorContext> = (c: T, action: RunAction) => Promise<void> | void;
|
|
6
11
|
export interface Config<T extends ActorContext> {
|
|
7
12
|
context: T;
|
|
8
13
|
actors: Actor<T>[];
|
package/config.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var RunAction;
|
|
2
|
+
(function (RunAction) {
|
|
3
|
+
RunAction[RunAction["Generate"] = 0] = "Generate";
|
|
4
|
+
RunAction[RunAction["Validate"] = 1] = "Validate";
|
|
5
|
+
})(RunAction || (RunAction = {}));
|
|
6
|
+
export function runActionFromArgv(argv) {
|
|
7
|
+
if (argv.length < 3) {
|
|
8
|
+
throw new Error('argv length is less than 3, action is not provided, valid actions are: "generate" and "validate"');
|
|
9
|
+
}
|
|
10
|
+
switch (argv[2]) {
|
|
11
|
+
case 'validate':
|
|
12
|
+
return RunAction.Validate;
|
|
13
|
+
case 'generate':
|
|
14
|
+
return RunAction.Generate;
|
|
15
|
+
default:
|
|
16
|
+
throw new Error(`Unknown action: ${argv[2]}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Actor, ActorContext, Config } from './config.js';
|
|
1
|
+
export { type Actor, type ActorContext, type Config, type RunAction, runActionFromArgv, } from './config.js';
|
|
2
2
|
export { run } from './main.js';
|
|
3
3
|
export { loadClientSchemaFromFile, loadServerSchemaFromFile, loadRootSchemaFromGQLSubprocess, } from './schema/utils.js';
|
|
4
4
|
export * as actors from './actors/index.js';
|
package/index.js
CHANGED
package/main.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ActorContext, Config } from './config.js';
|
|
2
|
-
export declare function run<TContext extends ActorContext>(config: Config<TContext
|
|
1
|
+
import { ActorContext, Config, RunAction } from './config.js';
|
|
2
|
+
export declare function run<TContext extends ActorContext>(config: Config<TContext>, action: RunAction): Promise<void>;
|
package/main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vladimirdev635/gql-codegen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.111",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/Voldemat/graphql-plus-plus#readme",
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"test": "vitest",
|
|
26
26
|
"build": "tsc && tsc-alias && cp package.json ./dist/package.json"
|
|
27
27
|
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"diff": "^9.0.0",
|
|
30
|
+
"picocolors": "^1.1.1"
|
|
31
|
+
},
|
|
28
32
|
"devDependencies": {
|
|
29
33
|
"@types/node": "^24.0.1",
|
|
30
34
|
"assert": "^2.1.0",
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
function generateFunctionBlock(operationName, type) {
|
|
3
|
-
switch (type) {
|
|
4
|
-
case 'SYNC':
|
|
5
|
-
return ts.factory.createCallExpression(ts.factory.createIdentifier('useOperation'), undefined, [
|
|
6
|
-
ts.factory.createIdentifier('executor'),
|
|
7
|
-
ts.factory.createIdentifier(operationName),
|
|
8
|
-
ts.factory.createIdentifier('variables'),
|
|
9
|
-
ts.factory.createIdentifier('requestContext'),
|
|
10
|
-
]);
|
|
11
|
-
case 'LAZY':
|
|
12
|
-
return ts.factory.createCallExpression(ts.factory.createIdentifier('useLazyOperation'), undefined, [
|
|
13
|
-
ts.factory.createIdentifier('executor'),
|
|
14
|
-
ts.factory.createIdentifier(operationName),
|
|
15
|
-
]);
|
|
16
|
-
case 'SUBSCRIPTION':
|
|
17
|
-
return ts.factory.createCallExpression(ts.factory.createIdentifier('useSubscription'), undefined, [
|
|
18
|
-
ts.factory.createIdentifier('executor'),
|
|
19
|
-
ts.factory.createIdentifier(operationName),
|
|
20
|
-
ts.factory.createIdentifier('variables'),
|
|
21
|
-
ts.factory.createIdentifier('requestContext'),
|
|
22
|
-
]);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function generateArrowFunction(operationName, variablesName, resultName, type) {
|
|
26
|
-
const parameters = [];
|
|
27
|
-
let resultType;
|
|
28
|
-
switch (type) {
|
|
29
|
-
case 'LAZY':
|
|
30
|
-
resultType = ts.factory.createTypeReferenceNode('UseLazyOperationReturnType', [
|
|
31
|
-
ts.factory.createTypeReferenceNode(variablesName),
|
|
32
|
-
ts.factory.createTypeReferenceNode(resultName),
|
|
33
|
-
ts.factory.createTypeReferenceNode('TRequestContext'),
|
|
34
|
-
]);
|
|
35
|
-
break;
|
|
36
|
-
case 'SYNC': {
|
|
37
|
-
resultType = ts.factory.createTypeReferenceNode('OperationState', [
|
|
38
|
-
ts.factory.createTypeReferenceNode(resultName),
|
|
39
|
-
]);
|
|
40
|
-
parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, 'variables', undefined, ts.factory.createTypeReferenceNode(variablesName)), ts.factory.createParameterDeclaration(undefined, undefined, 'requestContext', undefined, ts.factory.createTypeReferenceNode('TRequestContext')));
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case 'SUBSCRIPTION': {
|
|
44
|
-
resultType = ts.factory.createTypeReferenceNode('OperationState', [
|
|
45
|
-
ts.factory.createTypeReferenceNode('SubOpAsyncIterable', [
|
|
46
|
-
ts.factory.createTypeReferenceNode(resultName),
|
|
47
|
-
]),
|
|
48
|
-
]);
|
|
49
|
-
parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, 'variables', undefined, ts.factory.createTypeReferenceNode(variablesName)), ts.factory.createParameterDeclaration(undefined, undefined, 'requestContext', undefined, ts.factory.createTypeReferenceNode('TRequestContext')));
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return ts.factory.createArrowFunction(undefined, undefined, parameters, resultType, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), generateFunctionBlock(operationName, type));
|
|
54
|
-
}
|
|
55
|
-
export function generateNodes(config, context) {
|
|
56
|
-
const graphqlImports = [];
|
|
57
|
-
const queryNodes = [];
|
|
58
|
-
const mutationNodes = [];
|
|
59
|
-
const subscriptionNodes = [];
|
|
60
|
-
for (const operation of Object.values(context.schema.client.operations)) {
|
|
61
|
-
const operationName = operation.name + 'Operation';
|
|
62
|
-
const variablesName = operation.name + 'Variables';
|
|
63
|
-
const resultName = operation.name + 'Result';
|
|
64
|
-
graphqlImports.push(operationName, variablesName, resultName);
|
|
65
|
-
switch (operation.type) {
|
|
66
|
-
case 'SUBSCRIPTION': {
|
|
67
|
-
subscriptionNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'SUBSCRIPTION')));
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case 'MUTATION': {
|
|
71
|
-
mutationNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'LAZY')));
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case 'QUERY': {
|
|
75
|
-
queryNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'SYNC')), ts.factory.createPropertyAssignment('useLazy' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'LAZY')));
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const gqlClientReactImports = [
|
|
81
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useOperation')),
|
|
82
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useLazyOperation')),
|
|
83
|
-
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('OperationState')),
|
|
84
|
-
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('UseLazyOperationReturnType')),
|
|
85
|
-
];
|
|
86
|
-
const gqlClientImports = [
|
|
87
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('IExecutor')),
|
|
88
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('RequestContext')),
|
|
89
|
-
];
|
|
90
|
-
if (subscriptionNodes.length !== 0) {
|
|
91
|
-
gqlClientReactImports.push(ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useSubscription')));
|
|
92
|
-
gqlClientImports.push(ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('SubOpAsyncIterable')));
|
|
93
|
-
}
|
|
94
|
-
const returnObjectNodes = [];
|
|
95
|
-
if (queryNodes.length !== 0) {
|
|
96
|
-
returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.queriesKey, ts.factory.createObjectLiteralExpression(queryNodes, true)));
|
|
97
|
-
}
|
|
98
|
-
if (mutationNodes.length !== 0) {
|
|
99
|
-
returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.mutationsKey, ts.factory.createObjectLiteralExpression(mutationNodes, true)));
|
|
100
|
-
}
|
|
101
|
-
if (subscriptionNodes.length !== 0) {
|
|
102
|
-
returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.subscriptionsKey, ts.factory.createObjectLiteralExpression(subscriptionNodes, true)));
|
|
103
|
-
}
|
|
104
|
-
return [
|
|
105
|
-
ts.factory.createIdentifier('// @ts-nocheck'),
|
|
106
|
-
...config.importDeclarations,
|
|
107
|
-
ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(gqlClientReactImports)), ts.factory.createStringLiteral('@vladimirdev635/gql-client-react')),
|
|
108
|
-
ts.factory.createImportDeclaration([], ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports(gqlClientImports)), ts.factory.createStringLiteral('@vladimirdev635/gql-client/types')),
|
|
109
|
-
ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(graphqlImports.map((i) => ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(i))))), ts.factory.createStringLiteral(config.graphqlModulePath)),
|
|
110
|
-
ts.factory.createIdentifier('\n'),
|
|
111
|
-
ts.factory.createFunctionDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), undefined, 'createSdk', [
|
|
112
|
-
ts.factory.createTypeParameterDeclaration(undefined, 'TRequestContext', ts.factory.createTypeReferenceNode('RequestContext')),
|
|
113
|
-
], [
|
|
114
|
-
ts.factory.createParameterDeclaration(undefined, undefined, 'executor', undefined, ts.factory.createTypeReferenceNode('IExecutor', [
|
|
115
|
-
ts.factory.createTypeReferenceNode('TRequestContext'),
|
|
116
|
-
])),
|
|
117
|
-
], undefined, ts.factory.createBlock([
|
|
118
|
-
ts.factory.createReturnStatement(ts.factory.createObjectLiteralExpression(returnObjectNodes, true)),
|
|
119
|
-
], true)),
|
|
120
|
-
];
|
|
121
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
function generateFunctionBlock(operationName, type) {
|
|
3
|
-
switch (type) {
|
|
4
|
-
case 'SYNC':
|
|
5
|
-
return ts.factory.createCallExpression(ts.factory.createIdentifier('useOperation'), undefined, [
|
|
6
|
-
ts.factory.createIdentifier('executor'),
|
|
7
|
-
ts.factory.createIdentifier(operationName),
|
|
8
|
-
ts.factory.createIdentifier('variables'),
|
|
9
|
-
ts.factory.createIdentifier('requestContext'),
|
|
10
|
-
]);
|
|
11
|
-
case 'LAZY':
|
|
12
|
-
return ts.factory.createCallExpression(ts.factory.createIdentifier('useLazyOperation'), undefined, [
|
|
13
|
-
ts.factory.createIdentifier('executor'),
|
|
14
|
-
ts.factory.createIdentifier(operationName),
|
|
15
|
-
]);
|
|
16
|
-
case 'SUBSCRIPTION':
|
|
17
|
-
return ts.factory.createCallExpression(ts.factory.createIdentifier('useSubscription'), undefined, [
|
|
18
|
-
ts.factory.createIdentifier('executor'),
|
|
19
|
-
ts.factory.createIdentifier(operationName),
|
|
20
|
-
ts.factory.createIdentifier('variables'),
|
|
21
|
-
ts.factory.createIdentifier('requestContext'),
|
|
22
|
-
]);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function createTypeOrRefTypeNode(innerType) {
|
|
26
|
-
return ts.factory.createUnionTypeNode([
|
|
27
|
-
innerType,
|
|
28
|
-
ts.factory.createTypeReferenceNode('Ref', [innerType]),
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
function generateArrowFunction(operationName, variablesName, resultName, type) {
|
|
32
|
-
const parameters = [];
|
|
33
|
-
let resultType;
|
|
34
|
-
switch (type) {
|
|
35
|
-
case 'LAZY':
|
|
36
|
-
resultType = ts.factory.createTypeReferenceNode('UseLazyOperationReturnType', [
|
|
37
|
-
ts.factory.createTypeReferenceNode(variablesName),
|
|
38
|
-
ts.factory.createTypeReferenceNode(resultName),
|
|
39
|
-
ts.factory.createTypeReferenceNode('TRequestContext'),
|
|
40
|
-
]);
|
|
41
|
-
break;
|
|
42
|
-
case 'SYNC': {
|
|
43
|
-
resultType = ts.factory.createTypeReferenceNode('ShallowRef', [
|
|
44
|
-
ts.factory.createTypeReferenceNode('OperationState', [
|
|
45
|
-
ts.factory.createTypeReferenceNode(resultName),
|
|
46
|
-
]),
|
|
47
|
-
]);
|
|
48
|
-
parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, 'variables', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode(variablesName))), ts.factory.createParameterDeclaration(undefined, undefined, 'requestContext', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode('TRequestContext'))));
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case 'SUBSCRIPTION': {
|
|
52
|
-
resultType = ts.factory.createTypeReferenceNode('ShallowRef', [
|
|
53
|
-
ts.factory.createTypeReferenceNode('OperationState', [
|
|
54
|
-
ts.factory.createTypeReferenceNode('SubOpAsyncIterable', [
|
|
55
|
-
ts.factory.createTypeReferenceNode(resultName),
|
|
56
|
-
]),
|
|
57
|
-
]),
|
|
58
|
-
]);
|
|
59
|
-
parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, 'variables', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode(variablesName))), ts.factory.createParameterDeclaration(undefined, undefined, 'requestContext', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode('TRequestContext'))));
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return ts.factory.createArrowFunction(undefined, undefined, parameters, resultType, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), generateFunctionBlock(operationName, type));
|
|
64
|
-
}
|
|
65
|
-
export function generateNodes(config, context) {
|
|
66
|
-
const graphqlImports = [];
|
|
67
|
-
const queryNodes = [];
|
|
68
|
-
const mutationNodes = [];
|
|
69
|
-
const subscriptionNodes = [];
|
|
70
|
-
for (const operation of Object.values(context.schema.client.operations)) {
|
|
71
|
-
const operationName = operation.name + 'Operation';
|
|
72
|
-
const variablesName = operation.name + 'Variables';
|
|
73
|
-
const resultName = operation.name + 'Result';
|
|
74
|
-
graphqlImports.push(operationName, variablesName, resultName);
|
|
75
|
-
switch (operation.type) {
|
|
76
|
-
case 'SUBSCRIPTION': {
|
|
77
|
-
subscriptionNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'SUBSCRIPTION')));
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
case 'MUTATION': {
|
|
81
|
-
mutationNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'LAZY')));
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case 'QUERY': {
|
|
85
|
-
queryNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'SYNC')), ts.factory.createPropertyAssignment('useLazy' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'LAZY')));
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const gqlClientVueImports = [
|
|
91
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useOperation')),
|
|
92
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useLazyOperation')),
|
|
93
|
-
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('OperationState')),
|
|
94
|
-
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('UseLazyOperationReturnType')),
|
|
95
|
-
];
|
|
96
|
-
const gqlClientImports = [
|
|
97
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('IExecutor')),
|
|
98
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('RequestContext')),
|
|
99
|
-
];
|
|
100
|
-
if (subscriptionNodes.length !== 0) {
|
|
101
|
-
gqlClientVueImports.push(ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useSubscription')));
|
|
102
|
-
gqlClientImports.push(ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('SubOpAsyncIterable')));
|
|
103
|
-
}
|
|
104
|
-
const returnObjectNodes = [];
|
|
105
|
-
if (queryNodes.length !== 0) {
|
|
106
|
-
returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.queriesKey, ts.factory.createObjectLiteralExpression(queryNodes, true)));
|
|
107
|
-
}
|
|
108
|
-
if (mutationNodes.length !== 0) {
|
|
109
|
-
returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.mutationsKey, ts.factory.createObjectLiteralExpression(mutationNodes, true)));
|
|
110
|
-
}
|
|
111
|
-
if (subscriptionNodes.length !== 0) {
|
|
112
|
-
returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.subscriptionsKey, ts.factory.createObjectLiteralExpression(subscriptionNodes, true)));
|
|
113
|
-
}
|
|
114
|
-
return [
|
|
115
|
-
ts.factory.createIdentifier('// @ts-nocheck'),
|
|
116
|
-
...config.importDeclarations,
|
|
117
|
-
ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
118
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('Ref')),
|
|
119
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('ShallowRef')),
|
|
120
|
-
])), ts.factory.createStringLiteral('vue')),
|
|
121
|
-
ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(gqlClientVueImports)), ts.factory.createStringLiteral('@vladimirdev635/gql-client-vue')),
|
|
122
|
-
ts.factory.createImportDeclaration([], ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports(gqlClientImports)), ts.factory.createStringLiteral('@vladimirdev635/gql-client/types')),
|
|
123
|
-
ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(graphqlImports.map((i) => ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(i))))), ts.factory.createStringLiteral(config.graphqlModulePath)),
|
|
124
|
-
ts.factory.createIdentifier('\n'),
|
|
125
|
-
ts.factory.createFunctionDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), undefined, 'createSdk', [
|
|
126
|
-
ts.factory.createTypeParameterDeclaration(undefined, 'TRequestContext', ts.factory.createTypeReferenceNode('RequestContext')),
|
|
127
|
-
], [
|
|
128
|
-
ts.factory.createParameterDeclaration(undefined, undefined, 'executor', undefined, ts.factory.createTypeReferenceNode('IExecutor', [
|
|
129
|
-
ts.factory.createTypeReferenceNode('TRequestContext'),
|
|
130
|
-
])),
|
|
131
|
-
], undefined, ts.factory.createBlock([
|
|
132
|
-
ts.factory.createReturnStatement(ts.factory.createObjectLiteralExpression(returnObjectNodes, true)),
|
|
133
|
-
], true)),
|
|
134
|
-
];
|
|
135
|
-
}
|