@vladimirdev635/gql-codegen 0.0.26 → 0.0.27

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.
@@ -0,0 +1,10 @@
1
+ import { PathOrFileDescriptor } from 'fs';
2
+ import { Actor, ActorContext } from '@/config.js';
3
+ import { TSActorConfig } from '../shared.js';
4
+ import ts from 'typescript';
5
+ export interface GQLClientReactActorConfig extends TSActorConfig {
6
+ outPath: PathOrFileDescriptor;
7
+ importDeclarations: ts.ImportDeclaration[];
8
+ graphqlModulePath: string;
9
+ }
10
+ export declare function buildGQLClientReactActor(config: GQLClientReactActorConfig): 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 gqlClientReactActor(config, context) {
5
+ const nodes = generateNodes(config, context);
6
+ const code = await renderNodes(config, nodes);
7
+ writeFileSync(config.outPath, code);
8
+ }
9
+ export function buildGQLClientReactActor(config) {
10
+ return context => gqlClientReactActor(config, context);
11
+ }
@@ -0,0 +1,4 @@
1
+ import { ActorContext } from '@/config.js';
2
+ import { GQLClientReactActorConfig } from '../actor.js';
3
+ import ts from 'typescript';
4
+ export declare function generateNodes(config: GQLClientReactActorConfig, context: ActorContext): ts.Node[];
@@ -0,0 +1,60 @@
1
+ import ts from 'typescript';
2
+ function generateVariablesTypeNode(operationName) {
3
+ return ts.factory.createTypeReferenceNode('z.infer', [
4
+ ts.factory.createIndexedAccessTypeNode(ts.factory.createParenthesizedType(ts.factory.createTypeQueryNode(ts.factory.createIdentifier(operationName))), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral('variablesSchema')))
5
+ ]);
6
+ }
7
+ function generateFunctionBlock(operationName, lazy) {
8
+ if (!lazy) {
9
+ return ts.factory.createCallExpression(ts.factory.createIdentifier('useOperation'), undefined, [
10
+ ts.factory.createIdentifier('executor'),
11
+ ts.factory.createIdentifier(operationName),
12
+ ts.factory.createIdentifier('variables'),
13
+ ts.factory.createIdentifier('requestContext')
14
+ ]);
15
+ }
16
+ return ts.factory.createCallExpression(ts.factory.createIdentifier('useLazyOperation'), undefined, [
17
+ ts.factory.createIdentifier('executor'),
18
+ ts.factory.createIdentifier(operationName)
19
+ ]);
20
+ }
21
+ function generateArrowFunction(operationName, lazy) {
22
+ const parameters = [];
23
+ if (!lazy) {
24
+ parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, 'variables', undefined, generateVariablesTypeNode(operationName)), ts.factory.createParameterDeclaration(undefined, undefined, 'requestContext', undefined, ts.factory.createTypeReferenceNode('TRequestContext')));
25
+ }
26
+ return ts.factory.createArrowFunction(undefined, undefined, parameters, undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), generateFunctionBlock(operationName, lazy));
27
+ }
28
+ export function generateNodes(config, context) {
29
+ const graphqlImports = [];
30
+ const nodes = Object.values(context.schema.client.operations)
31
+ .map(operation => {
32
+ const operationName = operation.name + 'Operation';
33
+ graphqlImports.push(operationName);
34
+ return [
35
+ ts.factory.createPropertyAssignment('use' + operationName, generateArrowFunction(operationName, false)),
36
+ ts.factory.createPropertyAssignment('useLazy' + operationName, generateArrowFunction(operationName, true))
37
+ ];
38
+ }).flat();
39
+ return [
40
+ ...config.importDeclarations,
41
+ ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
42
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useOperation')),
43
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useLazyOperation'))
44
+ ])), ts.factory.createStringLiteral('@vladimirdev635/gql-client-react')),
45
+ ts.factory.createImportDeclaration([], ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([
46
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('Executor')),
47
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('RequestContext'))
48
+ ])), ts.factory.createStringLiteral('@vladimirdev635/gql-client')),
49
+ ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
50
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('z'))
51
+ ])), ts.factory.createStringLiteral('zod/v4')),
52
+ 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)),
53
+ ts.factory.createIdentifier('\n'),
54
+ ts.factory.createFunctionDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), undefined, 'createSdk', [ts.factory.createTypeParameterDeclaration(undefined, 'TRequestContext', ts.factory.createTypeReferenceNode('RequestContext'))], [ts.factory.createParameterDeclaration(undefined, undefined, 'executor', undefined, ts.factory.createTypeReferenceNode('Executor', [
55
+ ts.factory.createTypeReferenceNode('TRequestContext')
56
+ ]))], undefined, ts.factory.createBlock([
57
+ ts.factory.createReturnStatement(ts.factory.createAsExpression(ts.factory.createObjectLiteralExpression(nodes, true), ts.factory.createTypeReferenceNode('const')))
58
+ ], true))
59
+ ];
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vladimirdev635/gql-codegen",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -25,7 +25,8 @@
25
25
  "description": "",
26
26
  "dependencies": {
27
27
  "pino": "^9.7.0",
28
- "typescript": "^5.8.3"
28
+ "typescript": "^5.8.3",
29
+ "zod": "^3.25.76"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@babel/eslint-parser": "^7.27.5",
@@ -35,7 +36,6 @@
35
36
  "@typescript-eslint/eslint-plugin": "^8.34.0",
36
37
  "eslint": "^9.28.0",
37
38
  "jiti": "^2.4.2",
38
- "vitest": "^3.2.4",
39
- "zod": "^3.25.74"
39
+ "vitest": "^3.2.4"
40
40
  }
41
41
  }