@vladimirdev635/gql-codegen 0.0.107 → 0.0.108
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/ts/formatters/eslint/formatter.d.ts +1 -1
- package/actors/ts/formatters/eslint/formatter.js +1 -1
- package/actors/ts/formatters/eslint/index.d.ts +1 -1
- package/actors/ts/formatters/eslint/index.js +1 -1
- package/actors/ts/formatters/oxfmt/formatter.d.ts +1 -1
- package/actors/ts/formatters/oxfmt/formatter.js +1 -1
- package/actors/ts/formatters/oxfmt/index.d.ts +1 -1
- package/actors/ts/formatters/oxfmt/index.js +1 -1
- package/actors/ts/gql-client/actor.d.ts +2 -2
- package/actors/ts/gql-client/actor.js +3 -3
- package/actors/ts/gql-client/generators/main.d.ts +2 -2
- package/actors/ts/gql-client/index.d.ts +1 -1
- package/actors/ts/gql-client/index.js +1 -1
- package/actors/ts/gql-client-react/actor.d.ts +2 -2
- package/actors/ts/gql-client-react/actor.js +3 -3
- package/actors/ts/gql-client-react/generators/main.d.ts +2 -2
- package/actors/ts/gql-client-react/index.d.ts +1 -1
- package/actors/ts/gql-client-react/index.js +1 -1
- package/actors/ts/gql-client-vue/actor.d.ts +15 -0
- package/actors/ts/gql-client-vue/actor.js +11 -0
- package/actors/ts/gql-client-vue/generators/main.d.ts +4 -0
- package/actors/ts/gql-client-vue/generators/main.js +135 -0
- package/actors/ts/gql-client-vue/index.d.ts +1 -0
- package/actors/ts/gql-client-vue/index.js +1 -0
- package/actors/ts/index.d.ts +1 -0
- package/actors/ts/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Formatter } from '../../shared.js';
|
|
2
2
|
import { LoadESLintFuncType } from './types.js';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function build(loadFunc: LoadESLintFuncType): Promise<Formatter>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { LintResult, ESLintClass, ESLintClassConstructor, LoadESLintFuncType, } from './types.js';
|
|
2
|
-
export {
|
|
2
|
+
export { build } from './formatter.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { build } from './formatter.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Formatter } from '../../shared.js';
|
|
2
2
|
import { FormatFunc } from './types.js';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function build<T>(formatFunc: FormatFunc<T>, options: T): Promise<Formatter>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { ErrorLabel, OxcError, Severity, FormatResult, FormatFunc, } from './types.js';
|
|
2
|
-
export {
|
|
2
|
+
export { build } from './formatter.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { build } from './formatter.js';
|
|
@@ -10,10 +10,10 @@ export interface SDKConfig {
|
|
|
10
10
|
mutationsKey: string;
|
|
11
11
|
subscriptionsKey: string;
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface Config extends TSActorConfig {
|
|
14
14
|
outPath: PathOrFileDescriptor;
|
|
15
15
|
importDeclarations: ts.ImportDeclaration[];
|
|
16
16
|
sdk: SDKConfig;
|
|
17
17
|
graphqlModulePath: string;
|
|
18
18
|
}
|
|
19
|
-
export declare function
|
|
19
|
+
export declare function build(config: Config): Actor<ActorContext>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { writeFileSync } from 'fs';
|
|
2
2
|
import { renderNodes } from '../shared.js';
|
|
3
3
|
import { generateNodes } from './generators/main.js';
|
|
4
|
-
async function
|
|
4
|
+
async function actor(config, context) {
|
|
5
5
|
const nodes = generateNodes(config, context);
|
|
6
6
|
const code = await renderNodes(config, nodes);
|
|
7
7
|
writeFileSync(config.outPath, code);
|
|
8
8
|
}
|
|
9
|
-
export function
|
|
10
|
-
return (context) =>
|
|
9
|
+
export function build(config) {
|
|
10
|
+
return (context) => actor(config, context);
|
|
11
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ActorContext } from '../../../../config.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Config } from '../actor.js';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
export declare function generateNodes(config:
|
|
4
|
+
export declare function generateNodes(config: Config, context: ActorContext): ts.Node[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type OperationReturnType, type SDKConfig, type
|
|
1
|
+
export { type OperationReturnType, type SDKConfig, type Config, build, } from './actor.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { build, } from './actor.js';
|
|
@@ -2,7 +2,7 @@ import { PathOrFileDescriptor } from 'fs';
|
|
|
2
2
|
import { Actor, ActorContext } from '../../../config.js';
|
|
3
3
|
import { TSActorConfig } from '../shared.js';
|
|
4
4
|
import ts from 'typescript';
|
|
5
|
-
export interface
|
|
5
|
+
export interface Config extends TSActorConfig {
|
|
6
6
|
outPath: PathOrFileDescriptor;
|
|
7
7
|
importDeclarations: ts.ImportDeclaration[];
|
|
8
8
|
graphqlModulePath: string;
|
|
@@ -12,4 +12,4 @@ export interface GQLClientReactActorConfig extends TSActorConfig {
|
|
|
12
12
|
subscriptionsKey: string;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function build(config: Config): Actor<ActorContext>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { writeFileSync } from 'fs';
|
|
2
2
|
import { renderNodes } from '../shared.js';
|
|
3
3
|
import { generateNodes } from './generators/main.js';
|
|
4
|
-
async function
|
|
4
|
+
async function actor(config, context) {
|
|
5
5
|
const nodes = generateNodes(config, context);
|
|
6
6
|
const code = await renderNodes(config, nodes);
|
|
7
7
|
writeFileSync(config.outPath, code);
|
|
8
8
|
}
|
|
9
|
-
export function
|
|
10
|
-
return (context) =>
|
|
9
|
+
export function build(config) {
|
|
10
|
+
return (context) => actor(config, context);
|
|
11
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ActorContext } from '../../../../config.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Config } from '../actor.js';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
export declare function generateNodes(config:
|
|
4
|
+
export declare function generateNodes(config: Config, context: ActorContext): ts.Node[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type
|
|
1
|
+
export { type Config, build } from './actor.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { build } from './actor.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Actor, ActorContext } from '../../../config.js';
|
|
2
|
+
import { PathOrFileDescriptor } from 'fs';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { TSActorConfig } from '../shared.js';
|
|
5
|
+
export interface Config extends TSActorConfig {
|
|
6
|
+
outPath: PathOrFileDescriptor;
|
|
7
|
+
importDeclarations: ts.ImportDeclaration[];
|
|
8
|
+
graphqlModulePath: string;
|
|
9
|
+
sdk: {
|
|
10
|
+
queriesKey: string;
|
|
11
|
+
mutationsKey: string;
|
|
12
|
+
subscriptionsKey: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare function build(config: Config): Actor<ActorContext>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { writeFileSync } from 'fs';
|
|
2
|
+
import { renderNodes } from '../shared.js';
|
|
3
|
+
import { generateNodes } from './generators/main.js';
|
|
4
|
+
async function actor(config, context) {
|
|
5
|
+
const nodes = generateNodes(config, context);
|
|
6
|
+
const code = await renderNodes(config, nodes);
|
|
7
|
+
writeFileSync(config.outPath, code);
|
|
8
|
+
}
|
|
9
|
+
export function build(config) {
|
|
10
|
+
return (context) => actor(config, context);
|
|
11
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type Config, build } from './actor.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { build } from './actor.js';
|
package/actors/ts/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as gqlClient from './gql-client/index.js';
|
|
2
2
|
export * as gqlClientReact from './gql-client-react/index.js';
|
|
3
|
+
export * as gqlClientVue from './gql-client-vue/index.js';
|
|
3
4
|
export * as graphql from './graphql/index.js';
|
|
4
5
|
export { type Formatter, type TSActorConfig, renderNodes, loadTsConfigCompilerOptions, addNewLineBetweenNodes, invokeMethod, } from './shared.js';
|
|
5
6
|
export { generateImportDeclaration } from './utils.js';
|
package/actors/ts/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as gqlClient from './gql-client/index.js';
|
|
2
2
|
export * as gqlClientReact from './gql-client-react/index.js';
|
|
3
|
+
export * as gqlClientVue from './gql-client-vue/index.js';
|
|
3
4
|
export * as graphql from './graphql/index.js';
|
|
4
5
|
export { renderNodes, loadTsConfigCompilerOptions, addNewLineBetweenNodes, invokeMethod, } from './shared.js';
|
|
5
6
|
export { generateImportDeclaration } from './utils.js';
|