@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,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { renderNodes, } from '../shared.js';
|
|
2
|
+
import { executeRunAction } from '../../utils.js';
|
|
3
3
|
import { generateNodes } from './generators/main.js';
|
|
4
|
-
async function
|
|
4
|
+
async function actor(config, context, action) {
|
|
5
5
|
const nodes = generateNodes(config, context);
|
|
6
6
|
const code = await renderNodes(config, nodes);
|
|
7
|
-
|
|
7
|
+
executeRunAction(config.outPath, action, code);
|
|
8
8
|
}
|
|
9
|
-
export function
|
|
10
|
-
return (context) =>
|
|
9
|
+
export function build(config) {
|
|
10
|
+
return (context, action) => actor(config, context, action);
|
|
11
11
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { RootSchema } from '../../../../../../schema/root.js';
|
|
3
|
+
import { fragmentSchema } from '../../../../../../schema/client/fragment.js';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
export declare function generateFragmentDocumentNode(schema: RootSchema, name: string, fragment: z.infer<typeof fragmentSchema>): ts.VariableStatement;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { extractFragmentSourceTextsInSpec } from './spec/shared.js';
|
|
3
|
+
export function generateFragmentDocumentNode(schema, name, fragment) {
|
|
4
|
+
return ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
5
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(name + 'FragmentDocument'), undefined, undefined, ts.factory.createStringLiteral([
|
|
6
|
+
fragment.sourceText,
|
|
7
|
+
...extractFragmentSourceTextsInSpec(schema, fragment.spec),
|
|
8
|
+
].join(' '))),
|
|
9
|
+
], ts.NodeFlags.Const));
|
|
10
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RootSchema } from '../../../../../../schema/root.js';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { ScalarsMapping } from '../../server/scalars/mapping.js';
|
|
4
|
+
export declare function generateFragmentTypes(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>): ts.Node[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { generateSchemaName, generateZodInferInterfaceType, generateZodInferTypeAlias, } from '../../server/shared.js';
|
|
2
|
+
import { generateFragmentDocumentNode } from './document.js';
|
|
3
|
+
import { generateZodFragmentSchema } from './schema.js';
|
|
4
|
+
function generateFragmentDeclarations(scalarsMapping, schema, lazyFragmentsSet, fragmentName, fragment) {
|
|
5
|
+
const fName = fragmentName + 'Fragment';
|
|
6
|
+
const [fragmentSchemaNode, isLazy] = generateZodFragmentSchema(scalarsMapping, schema, lazyFragmentsSet, fragmentName, fragment);
|
|
7
|
+
if (isLazy) {
|
|
8
|
+
lazyFragmentsSet.add(fragmentName);
|
|
9
|
+
}
|
|
10
|
+
return [
|
|
11
|
+
generateFragmentDocumentNode(schema, fragmentName, fragment),
|
|
12
|
+
fragmentSchemaNode,
|
|
13
|
+
fragment.spec._type === 'ObjectFragmentSpec'
|
|
14
|
+
? generateZodInferInterfaceType('output', fName, generateSchemaName(fName))
|
|
15
|
+
: generateZodInferTypeAlias('output', fName, generateSchemaName(fName)),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
export function generateFragmentTypes(scalarsMapping, schema, lazyFragmentsSet) {
|
|
19
|
+
return Object.entries(schema.client.fragments)
|
|
20
|
+
.map(([name, fragment]) => {
|
|
21
|
+
return generateFragmentDeclarations(scalarsMapping, schema, lazyFragmentsSet, name, fragment);
|
|
22
|
+
})
|
|
23
|
+
.flat();
|
|
24
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { fragmentSchema } from '../../../../../../schema/client/fragment.js';
|
|
2
|
+
import { RootSchema } from '../../../../../../schema/root.js';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
|
+
import { ScalarsMapping } from '../../server/scalars/mapping.js';
|
|
6
|
+
export declare function generateZodFragmentSchema(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>, fragmentName: string, fragment: z.infer<typeof fragmentSchema>): [ts.VariableStatement, boolean];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { generateSchemaName } from '../../server/shared.js';
|
|
3
|
+
import { generateZodFragmentSpecCallExpression } from './spec/index.js';
|
|
4
|
+
export function generateZodFragmentSchema(scalarsMapping, schema, lazyFragmentsSet, fragmentName, fragment) {
|
|
5
|
+
const [expression, isLazy] = generateZodFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, fragment.spec);
|
|
6
|
+
return [
|
|
7
|
+
ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
8
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(generateSchemaName(fragmentName + 'Fragment')), undefined, undefined, expression),
|
|
9
|
+
], ts.NodeFlags.Const)),
|
|
10
|
+
isLazy,
|
|
11
|
+
];
|
|
12
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RootSchema } from '../../../../../../../schema/root.js';
|
|
2
|
+
import { ScalarsMapping } from '../../../server/scalars/mapping.js';
|
|
3
|
+
import { FragmentSpecSchemaType } from '../../../../../../../schema/client/fragment.js';
|
|
4
|
+
import { resolveSelections } from './shared.js';
|
|
5
|
+
export declare function generateZodFragmentSpecCallExpression(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>, spec: FragmentSpecSchemaType, typenameConfig?: Parameters<typeof resolveSelections>[1], insideLazy?: boolean): [import("typescript").CallExpression, boolean];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { generateZodObjectFragmentSpecCallExpression } from './object/index.js';
|
|
2
|
+
import { generateZodUnionFragmentSpecCallExpression } from './union/index.js';
|
|
3
|
+
export function generateZodFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, spec, typenameConfig, insideLazy = false) {
|
|
4
|
+
if (spec._type === 'ObjectFragmentSpec') {
|
|
5
|
+
return generateZodObjectFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, schema.server.objects[spec.name], spec.selections, insideLazy, typenameConfig || { ensurePresent: true, optional: true });
|
|
6
|
+
}
|
|
7
|
+
return generateZodUnionFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, spec, insideLazy);
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { fieldSelection } from '../../../../../../../../schema/client/fragment.js';
|
|
2
|
+
import { RootSchema } from '../../../../../../../../schema/root.js';
|
|
3
|
+
import { objectSchema } from '../../../../../../../../schema/server.js';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
import { ScalarsMapping } from '../../../../server/scalars/mapping.js';
|
|
7
|
+
export declare function generateFieldSelection(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>, insideLazy: boolean, objectType: z.infer<typeof objectSchema>, selection: z.infer<typeof fieldSelection>): ts.PropertyAssignment;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { invokeMethod } from '../../../../../../shared.js';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { generateZodObjectFieldSpec } from '../../../../server/objects.js';
|
|
4
|
+
import { generateZodFragmentSpecCallExpression } from '../index.js';
|
|
5
|
+
export function generateFieldSelection(scalarsMapping, schema, lazyFragmentsSet, insideLazy, objectType, selection) {
|
|
6
|
+
const fieldSpec = objectType.fields[selection.name];
|
|
7
|
+
let expression;
|
|
8
|
+
if (selection.selection == null) {
|
|
9
|
+
expression = generateZodObjectFieldSpec(scalarsMapping, fieldSpec);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
const optional = fieldSpec.spec._type !== 'callable' ||
|
|
13
|
+
!selection.selection.selections.every((s) => s._type === 'TypenameField') ||
|
|
14
|
+
!fieldSpec.nullable;
|
|
15
|
+
// eslint-disable-next-line no-use-before-define
|
|
16
|
+
[expression] = generateZodFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, selection.selection, { ensurePresent: true, optional }, insideLazy);
|
|
17
|
+
if (fieldSpec.spec._type === 'array' ||
|
|
18
|
+
(fieldSpec.spec._type === 'callable' &&
|
|
19
|
+
fieldSpec.spec.returnType._type === 'array')) {
|
|
20
|
+
expression = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), 'array'), undefined, [expression]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (fieldSpec.nullable) {
|
|
24
|
+
expression = invokeMethod(invokeMethod(expression, 'nullable', []), 'optional', []);
|
|
25
|
+
}
|
|
26
|
+
return ts.factory.createPropertyAssignment(selection.alias, expression);
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { objectSelection } from '../../../../../../../../schema/client/fragment.js';
|
|
2
|
+
import { RootSchema } from '../../../../../../../../schema/root.js';
|
|
3
|
+
import { objectSchema } from '../../../../../../../../schema/server.js';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
import { ScalarsMapping } from '../../../../server/scalars/mapping.js';
|
|
7
|
+
import { resolveSelections } from '../shared.js';
|
|
8
|
+
export declare function generateZodObjectFragmentSpecCallExpression(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>, object: z.infer<typeof objectSchema>, specSelections: z.infer<typeof objectSelection>[], insideLazy: boolean, typenameConfig: Parameters<typeof resolveSelections>[1]): [ts.CallExpression, boolean];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { resolveSelections } from '../shared.js';
|
|
3
|
+
import { generateZodObjectSelection } from './selection.js';
|
|
4
|
+
export function generateZodObjectFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, object, specSelections, insideLazy, typenameConfig) {
|
|
5
|
+
const selections = resolveSelections(specSelections, typenameConfig);
|
|
6
|
+
let needsLazy = false;
|
|
7
|
+
const properties = selections
|
|
8
|
+
.map((s) => {
|
|
9
|
+
const [property, pNeedsLazy] = generateZodObjectSelection(scalarsMapping, schema, lazyFragmentsSet, object, s, insideLazy, typenameConfig);
|
|
10
|
+
if (needsLazy === false && pNeedsLazy) {
|
|
11
|
+
needsLazy = true;
|
|
12
|
+
}
|
|
13
|
+
return property;
|
|
14
|
+
})
|
|
15
|
+
.filter((s) => s !== null);
|
|
16
|
+
let expression = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), 'object'), undefined, [ts.factory.createObjectLiteralExpression(properties, true)]);
|
|
17
|
+
if (needsLazy) {
|
|
18
|
+
expression = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), 'lazy'), undefined, [
|
|
19
|
+
ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), expression),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
return [expression, needsLazy];
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { objectSelection } from '../../../../../../../../schema/client/fragment.js';
|
|
2
|
+
import { RootSchema } from '../../../../../../../../schema/root.js';
|
|
3
|
+
import { objectSchema } from '../../../../../../../../schema/server.js';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
import { ScalarsMapping } from '../../../../server/scalars/mapping.js';
|
|
7
|
+
import { resolveSelections } from '../shared.js';
|
|
8
|
+
export declare function generateZodObjectSelection(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>, objectType: z.infer<typeof objectSchema>, selection: z.infer<typeof objectSelection>, insideLazy: boolean, typenameConfig: Parameters<typeof resolveSelections>[1]): [ts.PropertyAssignment | ts.SpreadAssignment | null, boolean];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { generateFieldSelection } from './field_selection.js';
|
|
2
|
+
import { generateSpreadSelection } from './spread_selection.js';
|
|
3
|
+
import { generateTypenameFieldSelection } from './typename_field.js';
|
|
4
|
+
export function generateZodObjectSelection(scalarsMapping, schema, lazyFragmentsSet, objectType, selection, insideLazy, typenameConfig) {
|
|
5
|
+
switch (selection._type) {
|
|
6
|
+
case 'TypenameField': {
|
|
7
|
+
return [
|
|
8
|
+
generateTypenameFieldSelection(typenameConfig, objectType.name, selection),
|
|
9
|
+
false,
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
case 'FieldSelection': {
|
|
13
|
+
return [
|
|
14
|
+
generateFieldSelection(scalarsMapping, schema, lazyFragmentsSet, insideLazy, objectType, selection),
|
|
15
|
+
false,
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
case 'SpreadSelection': {
|
|
19
|
+
return [
|
|
20
|
+
generateSpreadSelection(selection.fragment, lazyFragmentsSet.has(selection.fragment)),
|
|
21
|
+
true,
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { invokeMethod } from '../../../../../../shared.js';
|
|
3
|
+
import { generateSchemaName } from '../../../../server/shared.js';
|
|
4
|
+
function constructObjectWithShape(fragmentName, isLazy) {
|
|
5
|
+
const schemaName = generateSchemaName(fragmentName + 'Fragment');
|
|
6
|
+
const identifier = ts.factory.createIdentifier(schemaName);
|
|
7
|
+
if (!isLazy)
|
|
8
|
+
return identifier;
|
|
9
|
+
return invokeMethod(ts.factory.createPropertyAccessExpression(identifier, 'def'), 'getter', []);
|
|
10
|
+
}
|
|
11
|
+
export function generateSpreadSelection(fragmentName, isLazy) {
|
|
12
|
+
return ts.factory.createSpreadAssignment(ts.factory.createPropertyAccessExpression(constructObjectWithShape(fragmentName, isLazy), ts.factory.createIdentifier('shape')));
|
|
13
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { resolveSelections } from '../shared.js';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { typenameSelection } from '../../../../../../../../schema/client/fragment.js';
|
|
5
|
+
export declare function generateTypenameFieldSelection(typenameConfig: Parameters<typeof resolveSelections>[1], objectTypeName: string, selection: z.infer<typeof typenameSelection>): ts.PropertyAssignment | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { invokeMethod } from '../../../../../../shared.js';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
export function generateTypenameFieldSelection(typenameConfig, objectTypeName, selection) {
|
|
4
|
+
if ('ignore' in typenameConfig)
|
|
5
|
+
return null;
|
|
6
|
+
let expression = invokeMethod(ts.factory.createIdentifier('z'), 'literal', [
|
|
7
|
+
ts.factory.createStringLiteral(objectTypeName),
|
|
8
|
+
]);
|
|
9
|
+
if (selection.alias === null && typenameConfig.optional) {
|
|
10
|
+
expression = invokeMethod(invokeMethod(expression, 'nullable', []), 'optional', []);
|
|
11
|
+
}
|
|
12
|
+
return ts.factory.createPropertyAssignment(selection.alias || '__typename', expression);
|
|
13
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import { RootSchema } from '../../../../../schema/root.js';
|
|
3
|
-
import { FragmentSpecSchemaType, objectSelection } from '../../../../../schema/client/fragment.js';
|
|
4
1
|
import { z } from 'zod/v4';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
8
|
-
declare function resolveSelections(specSelections: z.infer<typeof objectSelection>[], typenameConfig: {
|
|
2
|
+
import { FragmentSpecSchemaType, objectSelection } from '../../../../../../../schema/client/fragment.js';
|
|
3
|
+
import { RootSchema } from '../../../../../../../schema/root.js';
|
|
4
|
+
export declare function resolveSelections(specSelections: z.infer<typeof objectSelection>[], typenameConfig: {
|
|
9
5
|
ensurePresent: boolean;
|
|
10
6
|
optional: boolean;
|
|
11
7
|
} | {
|
|
@@ -90,6 +86,5 @@ declare function resolveSelections(specSelections: z.infer<typeof objectSelectio
|
|
|
90
86
|
})[];
|
|
91
87
|
} | null;
|
|
92
88
|
})[];
|
|
93
|
-
export declare function
|
|
94
|
-
export declare function
|
|
95
|
-
export {};
|
|
89
|
+
export declare function extractFragmentNamesInSpec(schema: RootSchema, fragmentSpec: FragmentSpecSchemaType): string[];
|
|
90
|
+
export declare function extractFragmentSourceTextsInSpec(schema: RootSchema, fragmentSpec: FragmentSpecSchemaType): string[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
export function resolveSelections(specSelections, typenameConfig) {
|
|
3
|
+
const ignoreTypename = 'ignore' in typenameConfig;
|
|
4
|
+
const selections = specSelections
|
|
5
|
+
.filter((s) => s._type !== 'TypenameField' || !ignoreTypename)
|
|
6
|
+
.toSorted((s1, s2) => s1._type.localeCompare(s2._type));
|
|
7
|
+
if (ignoreTypename)
|
|
8
|
+
return selections;
|
|
9
|
+
const hasTypename = specSelections.some((s) => s._type === 'TypenameField');
|
|
10
|
+
const hasSpreadSelection = specSelections.some((s) => s._type === 'SpreadSelection');
|
|
11
|
+
if (!hasTypename) {
|
|
12
|
+
if (hasSpreadSelection) {
|
|
13
|
+
selections.push({ _type: 'TypenameField', alias: null });
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
selections.unshift({ _type: 'TypenameField', alias: null });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return selections;
|
|
20
|
+
}
|
|
21
|
+
export function extractFragmentNamesInSpec(schema, fragmentSpec) {
|
|
22
|
+
if (fragmentSpec._type === 'UnionFragmentSpec') {
|
|
23
|
+
return fragmentSpec.selections
|
|
24
|
+
.map((s) => {
|
|
25
|
+
if (s._type === 'SpreadSelection') {
|
|
26
|
+
const fragment = schema.client.fragments[s.fragment];
|
|
27
|
+
return [
|
|
28
|
+
s.fragment,
|
|
29
|
+
...extractFragmentNamesInSpec(schema, fragment.spec),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
if (s._type === 'ObjectConditionalSpreadSelection') {
|
|
33
|
+
return extractFragmentNamesInSpec(schema, s.spec);
|
|
34
|
+
}
|
|
35
|
+
return [];
|
|
36
|
+
})
|
|
37
|
+
.flat();
|
|
38
|
+
}
|
|
39
|
+
return fragmentSpec.selections
|
|
40
|
+
.map((s) => {
|
|
41
|
+
if (s._type === 'SpreadSelection') {
|
|
42
|
+
const fragment = schema.client.fragments[s.fragment];
|
|
43
|
+
assert(fragment.spec !== undefined);
|
|
44
|
+
return [
|
|
45
|
+
s.fragment,
|
|
46
|
+
...extractFragmentNamesInSpec(schema, fragment.spec),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
if (s._type === 'FieldSelection' && s.selection != null) {
|
|
50
|
+
assert(s.selection !== undefined);
|
|
51
|
+
return extractFragmentNamesInSpec(schema, s.selection);
|
|
52
|
+
}
|
|
53
|
+
return [];
|
|
54
|
+
})
|
|
55
|
+
.flat();
|
|
56
|
+
}
|
|
57
|
+
export function extractFragmentSourceTextsInSpec(schema, fragmentSpec) {
|
|
58
|
+
return Array.from(new Set(extractFragmentNamesInSpec(schema, fragmentSpec))).map((f) => schema.client.fragments[f].sourceText);
|
|
59
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { unionFragmentSpec } from '../../../../../../../../schema/client/fragment.js';
|
|
2
|
+
import { RootSchema } from '../../../../../../../../schema/root.js';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
|
+
import { ScalarsMapping } from '../../../../server/scalars/mapping.js';
|
|
6
|
+
export declare function generateZodUnionFragmentSpecCallExpression(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>, spec: z.infer<typeof unionFragmentSpec>, insideLazy: boolean): [ts.CallExpression, boolean];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { generateZodObjectFragmentSpecCallExpression } from '../object/index.js';
|
|
3
|
+
import { resolveUnionSelections } from './selections.js';
|
|
4
|
+
export function generateZodUnionFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, spec, insideLazy) {
|
|
5
|
+
const [objectSelections, typenameSelections] = resolveUnionSelections(schema, spec.selections);
|
|
6
|
+
for (const item of Object.keys(schema.server.unions[spec.name].items)) {
|
|
7
|
+
if (!objectSelections.some((s) => s.object === item)) {
|
|
8
|
+
objectSelections.push({
|
|
9
|
+
_type: 'ObjectConditionalSpreadSelection',
|
|
10
|
+
object: item,
|
|
11
|
+
spec: {
|
|
12
|
+
_type: 'ObjectFragmentSpec',
|
|
13
|
+
name: item,
|
|
14
|
+
selections: [],
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let expression = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), 'union'), undefined, [
|
|
20
|
+
ts.factory.createArrayLiteralExpression(objectSelections.map((s) => generateZodObjectFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, schema.server.objects[s.object], [...s.spec.selections, ...typenameSelections], true, { ensurePresent: true, optional: false })[0]), true),
|
|
21
|
+
]);
|
|
22
|
+
if (!insideLazy) {
|
|
23
|
+
expression = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), 'lazy'), undefined, [
|
|
24
|
+
ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), expression),
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
return [expression, !insideLazy];
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { objectConditionalSpreadSelection, typenameSelection, UnionSelection } from '../../../../../../../../schema/client/fragment.js';
|
|
3
|
+
import { RootSchema } from '../../../../../../../../schema/root.js';
|
|
4
|
+
export declare function resolveUnionSelections(schema: RootSchema, specSelections: UnionSelection[]): [
|
|
5
|
+
z.infer<typeof objectConditionalSpreadSelection>[],
|
|
6
|
+
z.infer<typeof typenameSelection>[]
|
|
7
|
+
];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
export function resolveUnionSelections(schema, specSelections) {
|
|
3
|
+
const typenameSelections = [];
|
|
4
|
+
const objectSelections = specSelections
|
|
5
|
+
.map((s) => {
|
|
6
|
+
assert(s._type !== 'UnionConditionalSpreadSelection');
|
|
7
|
+
if (s._type === 'TypenameField') {
|
|
8
|
+
typenameSelections.push(s);
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
if (s._type === 'ObjectConditionalSpreadSelection')
|
|
12
|
+
return [s];
|
|
13
|
+
const fragmentSpec = schema.client.fragments[s.fragment].spec;
|
|
14
|
+
assert(fragmentSpec._type === 'UnionFragmentSpec');
|
|
15
|
+
const [selections, tSelections] = resolveUnionSelections(schema, fragmentSpec.selections);
|
|
16
|
+
typenameSelections.push(...tSelections);
|
|
17
|
+
return selections;
|
|
18
|
+
})
|
|
19
|
+
.flat();
|
|
20
|
+
return [objectSelections, typenameSelections];
|
|
21
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
1
|
import { ActorContext } from '../../../../../config.js';
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { Config } from '../../actor.js';
|
|
4
|
+
export declare function generateClientNodes(config: Config, context: ActorContext): ts.Node[];
|
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { generateOperationsNodes } from './operations.js';
|
|
4
|
-
const operationTypeNode = ts.factory.createInterfaceDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), 'Operation', [
|
|
5
|
-
ts.factory.createTypeParameterDeclaration(undefined, 'V'),
|
|
6
|
-
ts.factory.createTypeParameterDeclaration(undefined, 'R'),
|
|
7
|
-
], [], [
|
|
8
|
-
ts.factory.createPropertySignature(undefined, 'name', undefined, ts.factory.createTypeReferenceNode('string')),
|
|
9
|
-
ts.factory.createPropertySignature(undefined, 'type', undefined, ts.factory.createUnionTypeNode(['QUERY', 'MUTATION', 'SUBSCRIPTION'].map((v) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(v))))),
|
|
10
|
-
ts.factory.createPropertySignature(undefined, 'document', undefined, ts.factory.createTypeReferenceNode('string')),
|
|
11
|
-
ts.factory.createPropertySignature(undefined, 'variablesSchema', undefined, ts.factory.createTypeReferenceNode('z.ZodType', [
|
|
12
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),
|
|
13
|
-
ts.factory.createTypeReferenceNode('V'),
|
|
14
|
-
])),
|
|
15
|
-
ts.factory.createPropertySignature(undefined, 'resultSchema', undefined, ts.factory.createTypeReferenceNode('z.ZodType', [
|
|
16
|
-
ts.factory.createTypeReferenceNode('R'),
|
|
17
|
-
])),
|
|
18
|
-
]);
|
|
1
|
+
import { generateFragmentTypes } from './fragments/index.js';
|
|
2
|
+
import { generateOperationsNodes } from './operations/index.js';
|
|
19
3
|
export function generateClientNodes(config, context) {
|
|
4
|
+
const lazyFragmentsSet = new Set();
|
|
20
5
|
return [
|
|
21
|
-
|
|
22
|
-
...
|
|
23
|
-
...generateOperationsNodes(config.scalarsMapping, context.schema),
|
|
6
|
+
...generateFragmentTypes(config.scalarsMapping, context.schema, lazyFragmentsSet),
|
|
7
|
+
...generateOperationsNodes(config.clientTypeNameBuilders, config.scalarsMapping, context.schema, lazyFragmentsSet),
|
|
24
8
|
];
|
|
25
9
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ClientTypeNameBuilders } from '../../../../../../actors/ts/shared.js';
|
|
2
|
+
import { operationSchema } from '../../../../../../schema/client/operation.js';
|
|
3
|
+
import { RootSchema } from '../../../../../../schema/root.js';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
import { ScalarsMapping } from '../../server/scalars/mapping.js';
|
|
7
|
+
export declare function opTypeToName(type: z.infer<typeof operationSchema>['type']): string;
|
|
8
|
+
export declare function generateOperationsNodes(clientTypeNameBuilders: ClientTypeNameBuilders, scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>): ts.Node[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { generateSchemaName, generateZodInferInterfaceType, } from '../../server/shared.js';
|
|
3
|
+
import { generateOperationZodInputSchema } from './input-schema.js';
|
|
4
|
+
import { generateOperationNode } from './node.js';
|
|
5
|
+
import { generateOperationZodOutputSchema } from './output-schema.js';
|
|
6
|
+
export function opTypeToName(type) {
|
|
7
|
+
switch (type) {
|
|
8
|
+
case 'QUERY':
|
|
9
|
+
return 'Query';
|
|
10
|
+
case 'MUTATION':
|
|
11
|
+
return 'Mutation';
|
|
12
|
+
case 'SUBSCRIPTION':
|
|
13
|
+
return 'Subscription';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function generateOperationNodes(clientTypeNameBuilders, scalarsMapping, lazyFragmentsSet, schema, operation) {
|
|
17
|
+
const variablesName = clientTypeNameBuilders.variablesTypeName(operation.name);
|
|
18
|
+
const resultName = clientTypeNameBuilders.resultTypeName(operation.name);
|
|
19
|
+
return [
|
|
20
|
+
generateOperationZodInputSchema(scalarsMapping, operation, variablesName),
|
|
21
|
+
generateZodInferInterfaceType('input', variablesName, generateSchemaName(variablesName)),
|
|
22
|
+
ts.factory.createIdentifier('\n'),
|
|
23
|
+
generateOperationZodOutputSchema(scalarsMapping, schema, lazyFragmentsSet, operation, resultName),
|
|
24
|
+
generateZodInferInterfaceType('output', resultName, generateSchemaName(resultName)),
|
|
25
|
+
generateOperationNode(clientTypeNameBuilders, schema, operation),
|
|
26
|
+
ts.factory.createIdentifier('\n'),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
export function generateOperationsNodes(clientTypeNameBuilders, scalarsMapping, schema, lazyFragmentsSet) {
|
|
30
|
+
return Object.values(schema.client.operations)
|
|
31
|
+
.map((operation) => generateOperationNodes(clientTypeNameBuilders, scalarsMapping, lazyFragmentsSet, schema, operation))
|
|
32
|
+
.flat();
|
|
33
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { operationSchema } from '../../../../../../schema/client/operation.js';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
4
|
+
import { ScalarsMapping } from '../../server/scalars/mapping.js';
|
|
5
|
+
export declare function generateOperationZodInputSchema(scalarsMapping: ScalarsMapping, operation: z.infer<typeof operationSchema>, variablesName: string): ts.VariableStatement;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { generateInputTypeDefinitionFields } from '../../server/inputs.js';
|
|
3
|
+
import { generateSchemaName } from '../../server/shared.js';
|
|
4
|
+
function parametersToFields(parameters) {
|
|
5
|
+
return Object.fromEntries(Object.keys(parameters).map((name) => [
|
|
6
|
+
name.slice(1),
|
|
7
|
+
parameters[name],
|
|
8
|
+
]));
|
|
9
|
+
}
|
|
10
|
+
export function generateOperationZodInputSchema(scalarsMapping, operation, variablesName) {
|
|
11
|
+
return ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
12
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(generateSchemaName(variablesName)), undefined, undefined, ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('z'), 'object'), undefined, [
|
|
13
|
+
ts.factory.createObjectLiteralExpression(generateInputTypeDefinitionFields(scalarsMapping, parametersToFields(operation.parameters), true), true),
|
|
14
|
+
])),
|
|
15
|
+
], ts.NodeFlags.Const));
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClientTypeNameBuilders } from '../../../../../../actors/ts/shared.js';
|
|
2
|
+
import { operationSchema } from '../../../../../../schema/client/operation.js';
|
|
3
|
+
import { RootSchema } from '../../../../../../schema/root.js';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
export declare function generateOperationNode(clientTypeNameBuilders: ClientTypeNameBuilders, schema: RootSchema, operation: z.infer<typeof operationSchema>): ts.VariableStatement;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { generateSchemaName } from '../../server/shared.js';
|
|
3
|
+
import { extractFragmentSourceTextsInSpec } from '../fragments/spec/shared.js';
|
|
4
|
+
function generateProperties(clientTypeNameBuilders, schema, operation) {
|
|
5
|
+
return [
|
|
6
|
+
ts.factory.createPropertyAssignment('name', ts.factory.createStringLiteral(operation.name)),
|
|
7
|
+
ts.factory.createPropertyAssignment('type', ts.factory.createStringLiteral(operation.type)),
|
|
8
|
+
ts.factory.createPropertyAssignment('document', ts.factory.createStringLiteral([
|
|
9
|
+
operation.sourceText,
|
|
10
|
+
...extractFragmentSourceTextsInSpec(schema, operation.fragmentSpec),
|
|
11
|
+
].join(' '))),
|
|
12
|
+
ts.factory.createPropertyAssignment('variablesSchema', ts.factory.createIdentifier(generateSchemaName(clientTypeNameBuilders.variablesTypeName(operation.name)))),
|
|
13
|
+
ts.factory.createPropertyAssignment('resultSchema', ts.factory.createIdentifier(generateSchemaName(clientTypeNameBuilders.resultTypeName(operation.name)))),
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
export function generateOperationNode(clientTypeNameBuilders, schema, operation) {
|
|
17
|
+
return ts.factory.createVariableStatement(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), ts.factory.createVariableDeclarationList([
|
|
18
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(clientTypeNameBuilders.operationTypeName(operation.name)), undefined, undefined, ts.factory.createAsExpression(ts.factory.createObjectLiteralExpression(generateProperties(clientTypeNameBuilders, schema, operation), true), ts.factory.createTypeReferenceNode('const'))),
|
|
19
|
+
], ts.NodeFlags.Const));
|
|
20
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { operationSchema } from '../../../../../../schema/client/operation.js';
|
|
2
|
+
import { RootSchema } from '../../../../../../schema/root.js';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
|
+
import { ScalarsMapping } from '../../server/scalars/mapping.js';
|
|
6
|
+
export declare function generateOperationZodOutputSchema(scalarsMapping: ScalarsMapping, schema: RootSchema, lazyFragmentsSet: Set<string>, operation: z.infer<typeof operationSchema>, resultName: string): ts.VariableStatement;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { generateSchemaName } from '../../server/shared.js';
|
|
3
|
+
import { generateZodFragmentSpecCallExpression } from '../fragments/spec/index.js';
|
|
4
|
+
export function generateOperationZodOutputSchema(scalarsMapping, schema, lazyFragmentsSet, operation, resultName) {
|
|
5
|
+
return ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
6
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(generateSchemaName(resultName)), undefined, undefined, generateZodFragmentSpecCallExpression(scalarsMapping, schema, lazyFragmentsSet, operation.fragmentSpec, undefined, true)[0]),
|
|
7
|
+
], ts.NodeFlags.Const));
|
|
8
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { ActorContext } from '../../../../config.js';
|
|
3
|
-
import {
|
|
4
|
-
export declare function generateNodes(config:
|
|
3
|
+
import { Config } from '../actor.js';
|
|
4
|
+
export declare function generateNodes(config: Config, context: ActorContext): ts.Node[];
|
|
@@ -3,7 +3,7 @@ import { generateServerNodes } from './server/main.js';
|
|
|
3
3
|
import { generateClientNodes } from './client/main.js';
|
|
4
4
|
export function generateNodes(config, context) {
|
|
5
5
|
return [
|
|
6
|
-
ts.factory.createImportDeclaration([], ts.factory.createImportClause(
|
|
6
|
+
ts.factory.createImportDeclaration([], ts.factory.createImportClause(undefined, undefined, ts.factory.createNamedImports([
|
|
7
7
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('z')),
|
|
8
8
|
])), ts.factory.createStringLiteral('zod/v4')),
|
|
9
9
|
...config.importDeclarations,
|
|
@@ -3,5 +3,5 @@ import ts from 'typescript';
|
|
|
3
3
|
import { inputSchema } from '../../../../../schema/server.js';
|
|
4
4
|
import { inputFieldSchema } from '../../../../../schema/shared.js';
|
|
5
5
|
import { ScalarsMapping } from './scalars/index.js';
|
|
6
|
-
export declare function generateInputTypeDefinitionFields(scalarsMapping: ScalarsMapping, fields: Record<string, z.infer<typeof inputFieldSchema
|
|
6
|
+
export declare function generateInputTypeDefinitionFields(scalarsMapping: ScalarsMapping, fields: Record<string, z.infer<typeof inputFieldSchema>>, insideLazy: boolean): (ts.PropertyAssignment | ts.GetAccessorDeclaration)[];
|
|
7
7
|
export declare function generateInputTypeDefinitions(scalarsMapping: ScalarsMapping, input: z.infer<typeof inputSchema>): ts.Node[];
|