@soda-gql/codegen 0.11.26 → 0.12.0
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/dist/{generator-CsQAp9Xj.mjs → generator-76iJu4D4.mjs} +138 -41
- package/dist/generator-76iJu4D4.mjs.map +1 -0
- package/dist/{generator-BJX_PNQq.cjs → generator-BEFJKQs_.cjs} +155 -40
- package/dist/generator-BEFJKQs_.cjs.map +1 -0
- package/dist/generator-C_BtU_dR.cjs +6 -0
- package/dist/generator-DOfX1Run.mjs +3 -0
- package/dist/index.cjs +280 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +51 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +279 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/generator-BJX_PNQq.cjs.map +0 -1
- package/dist/generator-C2g1EDwR.cjs +0 -4
- package/dist/generator-CsQAp9Xj.mjs.map +0 -1
- package/dist/generator-DSYhdRB2.mjs +0 -3
|
@@ -2164,24 +2164,6 @@ const isEnumName = (schema, name) => schema.enums.has(name);
|
|
|
2164
2164
|
const _isInputName = (schema, name) => schema.inputs.has(name);
|
|
2165
2165
|
const isUnionName = (schema, name) => schema.unions.has(name);
|
|
2166
2166
|
const isObjectName = (schema, name) => schema.objects.has(name);
|
|
2167
|
-
const renderConstValue = (value) => {
|
|
2168
|
-
switch (value.kind) {
|
|
2169
|
-
case Kind.NULL: return "null";
|
|
2170
|
-
case Kind.INT:
|
|
2171
|
-
case Kind.FLOAT: return value.value;
|
|
2172
|
-
case Kind.STRING:
|
|
2173
|
-
case Kind.ENUM: return JSON.stringify(value.value);
|
|
2174
|
-
case Kind.BOOLEAN: return value.value ? "true" : "false";
|
|
2175
|
-
case Kind.LIST: return `[${value.values.map((item) => renderConstValue(item)).join(", ")}]`;
|
|
2176
|
-
case Kind.OBJECT: {
|
|
2177
|
-
if (value.fields.length === 0) {
|
|
2178
|
-
return "{}";
|
|
2179
|
-
}
|
|
2180
|
-
const entries = value.fields.map((field) => `${field.name.value}: ${renderConstValue(field.value)}`);
|
|
2181
|
-
return `{ ${entries.join(", ")} }`;
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
};
|
|
2185
2167
|
/**
|
|
2186
2168
|
* Maps type kind to deferred specifier prefix character.
|
|
2187
2169
|
*/
|
|
@@ -2335,14 +2317,6 @@ const renderUnionVar = (schemaName, record, excluded) => {
|
|
|
2335
2317
|
return `const union_${schemaName}_${record.name} = { name: "${record.name}", types: ${typesObj} } as const;`;
|
|
2336
2318
|
};
|
|
2337
2319
|
const collectObjectTypeNames = (schema) => Array.from(schema.objects.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2338
|
-
const renderFragmentBuildersType = (objectTypeNames, schemaName, adapterTypeName) => {
|
|
2339
|
-
if (objectTypeNames.length === 0) {
|
|
2340
|
-
return `type FragmentBuilders_${schemaName} = Record<string, never>;`;
|
|
2341
|
-
}
|
|
2342
|
-
const adapterPart = adapterTypeName ? `, ExtractMetadataAdapter<${adapterTypeName}>` : "";
|
|
2343
|
-
const entries = objectTypeNames.map((name) => ` readonly ${name}: FragmentBuilderFor<Schema_${schemaName}, "${name}"${adapterPart}>`);
|
|
2344
|
-
return `type FragmentBuilders_${schemaName} = {\n${entries.join(";\n")};\n};`;
|
|
2345
|
-
};
|
|
2346
2320
|
const collectInputTypeNames = (schema) => Array.from(schema.inputs.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2347
2321
|
const collectEnumTypeNames = (schema) => Array.from(schema.enums.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2348
2322
|
const collectUnionTypeNames = (schema) => Array.from(schema.unions.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
@@ -2520,7 +2494,7 @@ const multiRuntimeTemplate = ($$) => {
|
|
|
2520
2494
|
}
|
|
2521
2495
|
const extraImports = imports.length > 0 ? `${imports.join("\n")}\n` : "";
|
|
2522
2496
|
const schemaBlocks = [];
|
|
2523
|
-
const
|
|
2497
|
+
const gqlExports = [];
|
|
2524
2498
|
for (const [name, config] of Object.entries($$.schemas)) {
|
|
2525
2499
|
const schemaVar = `${name}Schema`;
|
|
2526
2500
|
const adapterVar = adapterAliases.get(name);
|
|
@@ -2528,7 +2502,6 @@ const multiRuntimeTemplate = ($$) => {
|
|
|
2528
2502
|
if (adapterVar) {
|
|
2529
2503
|
typeExports.push(`export type Adapter_${name} = typeof ${adapterVar} & { _?: never };`);
|
|
2530
2504
|
}
|
|
2531
|
-
typeExports.push(config.fragmentBuildersTypeBlock);
|
|
2532
2505
|
const inputTypeMethodsVar = `inputTypeMethods_${name}`;
|
|
2533
2506
|
const factoryVar = `createMethod_${name}`;
|
|
2534
2507
|
const customDirectivesVar = `customDirectives_${name}`;
|
|
@@ -2589,10 +2562,10 @@ const ${customDirectivesVar} = { ...createStandardDirectives(), ...${config.dire
|
|
|
2589
2562
|
${typeExports.join("\n")}`);
|
|
2590
2563
|
const gqlVarName = `gql_${name}`;
|
|
2591
2564
|
if (adapterVar) {
|
|
2592
|
-
const typeParams = `<Schema_${name},
|
|
2565
|
+
const typeParams = `<Schema_${name}, typeof ${customDirectivesVar}, Adapter_${name}>`;
|
|
2593
2566
|
schemaBlocks.push(`const ${gqlVarName} = createGqlElementComposer${typeParams}(${schemaVar}, { adapter: ${adapterVar}, inputTypeMethods: ${inputTypeMethodsVar}, directiveMethods: ${customDirectivesVar} });`);
|
|
2594
2567
|
} else {
|
|
2595
|
-
const typeParams = `<Schema_${name},
|
|
2568
|
+
const typeParams = `<Schema_${name}, typeof ${customDirectivesVar}>`;
|
|
2596
2569
|
schemaBlocks.push(`const ${gqlVarName} = createGqlElementComposer${typeParams}(${schemaVar}, { inputTypeMethods: ${inputTypeMethodsVar}, directiveMethods: ${customDirectivesVar} });`);
|
|
2597
2570
|
}
|
|
2598
2571
|
schemaBlocks.push(`export type Context_${name} = Parameters<typeof ${gqlVarName}>[0] extends (ctx: infer C) => unknown ? C : never;`);
|
|
@@ -2605,13 +2578,11 @@ ${typeExports.join("\n")}`);
|
|
|
2605
2578
|
prebuiltExports.push(`export { ${adapterVar} as __adapter_${name} }`);
|
|
2606
2579
|
}
|
|
2607
2580
|
schemaBlocks.push(`${prebuiltExports.join(";\n")};`);
|
|
2608
|
-
|
|
2581
|
+
gqlExports.push(`export { ${gqlVarName} as __gql_${name} }`);
|
|
2609
2582
|
}
|
|
2610
2583
|
const needsDefineEnum = false;
|
|
2611
2584
|
return `\
|
|
2612
2585
|
import {${needsDefineEnum ? "\n defineEnum," : ""}
|
|
2613
|
-
type ExtractMetadataAdapter,
|
|
2614
|
-
type FragmentBuilderFor,
|
|
2615
2586
|
type AnyGraphqlSchema,
|
|
2616
2587
|
createDirectiveMethod,
|
|
2617
2588
|
createTypedDirectiveMethod,
|
|
@@ -2622,9 +2593,7 @@ import {${needsDefineEnum ? "\n defineEnum," : ""}
|
|
|
2622
2593
|
${extraImports}
|
|
2623
2594
|
${schemaBlocks.join("\n")}
|
|
2624
2595
|
|
|
2625
|
-
|
|
2626
|
-
${gqlEntries.join(",\n")}
|
|
2627
|
-
};
|
|
2596
|
+
${gqlExports.join(";\n")};
|
|
2628
2597
|
`;
|
|
2629
2598
|
};
|
|
2630
2599
|
const generateMultiSchemaModule = (schemas, options) => {
|
|
@@ -2698,8 +2667,6 @@ const generateMultiSchemaModule = (schemas, options) => {
|
|
|
2698
2667
|
const factoryVar = `createMethod_${name}`;
|
|
2699
2668
|
const inputTypeMethodsBlock = renderInputTypeMethods(schema, factoryVar, excluded);
|
|
2700
2669
|
const directiveMethodsBlock = renderDirectiveMethods(schema, excluded);
|
|
2701
|
-
const adapterTypeName = options?.injection?.get(name)?.adapterImportPath ? `Adapter_${name}` : undefined;
|
|
2702
|
-
const fragmentBuildersTypeBlock = renderFragmentBuildersType(objectTypeNames, name, adapterTypeName);
|
|
2703
2670
|
const queryType = schema.operationTypes.query ?? "Query";
|
|
2704
2671
|
const mutationType = schema.operationTypes.mutation ?? "Mutation";
|
|
2705
2672
|
const subscriptionType = schema.operationTypes.subscription ?? "Subscription";
|
|
@@ -2719,7 +2686,6 @@ const generateMultiSchemaModule = (schemas, options) => {
|
|
|
2719
2686
|
unionNames: unionTypeNames,
|
|
2720
2687
|
inputTypeMethodsBlock,
|
|
2721
2688
|
directiveMethodsBlock,
|
|
2722
|
-
fragmentBuildersTypeBlock,
|
|
2723
2689
|
defaultInputDepth: options?.defaultInputDepth?.get(name),
|
|
2724
2690
|
inputDepthOverrides: options?.inputDepthOverrides?.get(name)
|
|
2725
2691
|
};
|
|
@@ -2767,7 +2733,138 @@ const generateMultiSchemaModule = (schemas, options) => {
|
|
|
2767
2733
|
stats: allStats
|
|
2768
2734
|
};
|
|
2769
2735
|
};
|
|
2736
|
+
/**
|
|
2737
|
+
* Generate a stub `types.prebuilt.ts` file with empty PrebuiltTypes registries.
|
|
2738
|
+
* This stub is only written when `types.prebuilt.ts` does not already exist.
|
|
2739
|
+
* Typegen will later overwrite it with the real type registry.
|
|
2740
|
+
*/
|
|
2741
|
+
const generatePrebuiltStub = (schemaNames) => {
|
|
2742
|
+
const typeDeclarations = schemaNames.map((name) => `export type PrebuiltTypes_${name} = {
|
|
2743
|
+
readonly fragments: {};
|
|
2744
|
+
readonly operations: {};
|
|
2745
|
+
};`).join("\n\n");
|
|
2746
|
+
return `\
|
|
2747
|
+
/**
|
|
2748
|
+
* Prebuilt type registry stub.
|
|
2749
|
+
*
|
|
2750
|
+
* This file was generated by @soda-gql/codegen as an empty stub.
|
|
2751
|
+
* Run 'soda-gql typegen' to populate with real prebuilt types.
|
|
2752
|
+
*
|
|
2753
|
+
* @module
|
|
2754
|
+
* @generated
|
|
2755
|
+
*/
|
|
2756
|
+
|
|
2757
|
+
${typeDeclarations}
|
|
2758
|
+
`;
|
|
2759
|
+
};
|
|
2760
|
+
/**
|
|
2761
|
+
* Generate the `index.ts` module that re-exports from `_internal`
|
|
2762
|
+
* and constructs the `gql` object from individual `__gql_*` exports.
|
|
2763
|
+
*
|
|
2764
|
+
* The `gql` object preserves the original inferred types from schema inference.
|
|
2765
|
+
* PrebuiltContext types will be integrated once the type resolution strategy
|
|
2766
|
+
* is redesigned to match the tagged template runtime API.
|
|
2767
|
+
*/
|
|
2768
|
+
const generateIndexModule = (schemaNames) => {
|
|
2769
|
+
const gqlImports = schemaNames.map((name) => `__gql_${name}`).join(", ");
|
|
2770
|
+
const prebuiltImports = schemaNames.map((name) => `PrebuiltTypes_${name}`).join(", ");
|
|
2771
|
+
const schemaTypeImports = schemaNames.map((name) => `Schema_${name}`).join(", ");
|
|
2772
|
+
const directiveImports = schemaNames.map((name) => `__directiveMethods_${name}`).join(", ");
|
|
2773
|
+
const perSchemaTypes = schemaNames.map((name) => `
|
|
2774
|
+
type ResolveFragmentAtBuilder_${name}<TKey extends string> =
|
|
2775
|
+
TKey extends keyof PrebuiltTypes_${name}["fragments"]
|
|
2776
|
+
? Fragment<
|
|
2777
|
+
PrebuiltTypes_${name}["fragments"][TKey]["typename"],
|
|
2778
|
+
PrebuiltTypes_${name}["fragments"][TKey]["input"] extends void
|
|
2779
|
+
? void
|
|
2780
|
+
: Partial<PrebuiltTypes_${name}["fragments"][TKey]["input"] & AnyConstAssignableInput>,
|
|
2781
|
+
Partial<AnyFields>,
|
|
2782
|
+
PrebuiltTypes_${name}["fragments"][TKey]["output"] & object
|
|
2783
|
+
>
|
|
2784
|
+
: Fragment<"(unknown)", PrebuiltEntryNotFound<TKey, "fragment">, Partial<AnyFields>, PrebuiltEntryNotFound<TKey, "fragment">>;
|
|
2785
|
+
|
|
2786
|
+
type ResolveOperationAtBuilder_${name}<TOperationType extends OperationType, TName extends string> =
|
|
2787
|
+
TName extends keyof PrebuiltTypes_${name}["operations"]
|
|
2788
|
+
? Operation<
|
|
2789
|
+
TOperationType,
|
|
2790
|
+
TName,
|
|
2791
|
+
string[],
|
|
2792
|
+
PrebuiltTypes_${name}["operations"][TName]["input"] & AnyConstAssignableInput,
|
|
2793
|
+
Partial<AnyFields>,
|
|
2794
|
+
PrebuiltTypes_${name}["operations"][TName]["output"] & object
|
|
2795
|
+
>
|
|
2796
|
+
: Operation<
|
|
2797
|
+
TOperationType,
|
|
2798
|
+
TName,
|
|
2799
|
+
string[],
|
|
2800
|
+
PrebuiltEntryNotFound<TName, "operation">,
|
|
2801
|
+
Partial<AnyFields>,
|
|
2802
|
+
PrebuiltEntryNotFound<TName, "operation">
|
|
2803
|
+
>;
|
|
2804
|
+
|
|
2805
|
+
type PrebuiltCurriedFragment_${name} = <TKey extends string>(
|
|
2806
|
+
name: TKey,
|
|
2807
|
+
typeName: string,
|
|
2808
|
+
) => (...args: unknown[]) => (...args: unknown[]) => ResolveFragmentAtBuilder_${name}<TKey>;
|
|
2809
|
+
|
|
2810
|
+
type PrebuiltCurriedOperation_${name}<TOperationType extends OperationType> = <TName extends string>(
|
|
2811
|
+
operationName: TName,
|
|
2812
|
+
) => (...args: unknown[]) => (...args: unknown[]) => ResolveOperationAtBuilder_${name}<TOperationType, TName>;
|
|
2813
|
+
|
|
2814
|
+
type GenericFieldFactory_${name} = Record<string, (...args: unknown[]) => Record<string, unknown> & ((callback: (tools: GenericFieldsBuilderTools_${name}) => Record<string, unknown>) => Record<string, unknown>)>;
|
|
2815
|
+
type GenericFieldsBuilderTools_${name} = { readonly f: GenericFieldFactory_${name}; readonly $: Readonly<Record<string, never>> };
|
|
2816
|
+
|
|
2817
|
+
type PrebuiltCallbackOperation_${name}<TOperationType extends OperationType> = <TName extends string>(
|
|
2818
|
+
options: { name: TName; fields: (tools: GenericFieldsBuilderTools_${name}) => Record<string, unknown>; variables?: Record<string, unknown>; metadata?: (tools: { readonly $: Readonly<Record<string, never>>; readonly fragmentMetadata: unknown[] | undefined }) => Record<string, unknown> },
|
|
2819
|
+
) => ResolveOperationAtBuilder_${name}<TOperationType, TName>;
|
|
2820
|
+
|
|
2821
|
+
export type PrebuiltContext_${name} = {
|
|
2822
|
+
readonly fragment: PrebuiltCurriedFragment_${name};
|
|
2823
|
+
readonly query: PrebuiltCurriedOperation_${name}<"query"> & {
|
|
2824
|
+
readonly operation: PrebuiltCallbackOperation_${name}<"query">;
|
|
2825
|
+
readonly compat: (operationName: string) => (strings: TemplateStringsArray, ...values: never[]) => GqlDefine<unknown>;
|
|
2826
|
+
};
|
|
2827
|
+
readonly mutation: PrebuiltCurriedOperation_${name}<"mutation"> & {
|
|
2828
|
+
readonly operation: PrebuiltCallbackOperation_${name}<"mutation">;
|
|
2829
|
+
readonly compat: (operationName: string) => (strings: TemplateStringsArray, ...values: never[]) => GqlDefine<unknown>;
|
|
2830
|
+
};
|
|
2831
|
+
readonly subscription: PrebuiltCurriedOperation_${name}<"subscription"> & {
|
|
2832
|
+
readonly operation: PrebuiltCallbackOperation_${name}<"subscription">;
|
|
2833
|
+
readonly compat: (operationName: string) => (strings: TemplateStringsArray, ...values: never[]) => GqlDefine<unknown>;
|
|
2834
|
+
};
|
|
2835
|
+
readonly define: <TValue>(factory: () => TValue | Promise<TValue>) => GqlDefine<TValue>;
|
|
2836
|
+
readonly extend: (...args: unknown[]) => AnyOperation;
|
|
2837
|
+
readonly $var: VarBuilder<Schema_${name}>;
|
|
2838
|
+
readonly $dir: typeof __directiveMethods_${name};
|
|
2839
|
+
readonly $colocate: <T extends Record<string, unknown>>(projections: T) => T;
|
|
2840
|
+
};
|
|
2841
|
+
|
|
2842
|
+
type GqlComposer_${name} = {
|
|
2843
|
+
<TResult>(composeElement: (context: PrebuiltContext_${name}) => TResult): TResult;
|
|
2844
|
+
readonly $schema: AnyGraphqlSchema;
|
|
2845
|
+
};`).join("\n");
|
|
2846
|
+
const gqlEntries = schemaNames.map((name) => ` ${name}: __gql_${name} as unknown as GqlComposer_${name}`).join(",\n");
|
|
2847
|
+
return `\
|
|
2848
|
+
/**
|
|
2849
|
+
* Generated by @soda-gql/codegen
|
|
2850
|
+
* @module
|
|
2851
|
+
* @generated
|
|
2852
|
+
*/
|
|
2853
|
+
|
|
2854
|
+
export * from "./_internal";
|
|
2855
|
+
import { ${gqlImports} } from "./_internal";
|
|
2856
|
+
import type { ${schemaTypeImports} } from "./_internal";
|
|
2857
|
+
import type { ${directiveImports} } from "./_internal";
|
|
2858
|
+
import type { ${prebuiltImports} } from "./types.prebuilt";
|
|
2859
|
+
import type { Fragment, Operation, OperationType, PrebuiltEntryNotFound, AnyConstAssignableInput, AnyFields, AnyGraphqlSchema, AnyOperation, VarBuilder, GqlDefine } from "@soda-gql/core";
|
|
2860
|
+
${perSchemaTypes}
|
|
2861
|
+
|
|
2862
|
+
export const gql = {
|
|
2863
|
+
${gqlEntries}
|
|
2864
|
+
};
|
|
2865
|
+
`;
|
|
2866
|
+
};
|
|
2770
2867
|
|
|
2771
2868
|
//#endregion
|
|
2772
|
-
export {
|
|
2773
|
-
//# sourceMappingURL=generator-
|
|
2869
|
+
export { compileTypeFilter as a, generatePrebuiltStub as i, generateIndexModule as n, generateMultiSchemaModule as r, createSchemaIndex as t };
|
|
2870
|
+
//# sourceMappingURL=generator-76iJu4D4.mjs.map
|