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