@soda-gql/codegen 0.11.25 → 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
  */
@@ -2196,10 +2178,8 @@ const renderInputRef = (schema, definition, excluded) => {
2196
2178
  const { name, modifier } = parseTypeReference(definition.type);
2197
2179
  const defaultValue = definition.defaultValue;
2198
2180
  if (excluded.has(name)) {
2199
- if (defaultValue) {
2200
- return `{ kind: "excluded", name: "${name}", modifier: "${modifier}", defaultValue: { default: ${renderConstValue(defaultValue)} } }`;
2201
- }
2202
- return `{ kind: "excluded", name: "${name}", modifier: "${modifier}" }`;
2181
+ const defaultSuffix$1 = defaultValue ? "|D" : "";
2182
+ return `"x|${name}|${modifier}${defaultSuffix$1}"`;
2203
2183
  }
2204
2184
  let kind;
2205
2185
  if (isScalarName(schema, name)) {
@@ -2259,7 +2239,7 @@ const renderOutputRef = (schema, type, args, excluded) => {
2259
2239
  const { name, modifier } = parseTypeReference(type);
2260
2240
  if (excluded.has(name)) {
2261
2241
  const argumentMap = renderArgumentMap(schema, args, excluded);
2262
- return `{ kind: "excluded", name: "${name}", modifier: "${modifier}", arguments: ${argumentMap} }`;
2242
+ return `{ spec: "x|${name}|${modifier}", arguments: ${argumentMap} }`;
2263
2243
  }
2264
2244
  let kind;
2265
2245
  if (isScalarName(schema, name)) {
@@ -2336,14 +2316,6 @@ const renderUnionVar = (schemaName, record, excluded) => {
2336
2316
  return `const union_${schemaName}_${record.name} = { name: "${record.name}", types: ${typesObj} } as const;`;
2337
2317
  };
2338
2318
  const collectObjectTypeNames = (schema) => Array.from(schema.objects.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
2339
- const renderFragmentBuildersType = (objectTypeNames, schemaName, adapterTypeName) => {
2340
- if (objectTypeNames.length === 0) {
2341
- return `type FragmentBuilders_${schemaName} = Record<string, never>;`;
2342
- }
2343
- const adapterPart = adapterTypeName ? `, ExtractMetadataAdapter<${adapterTypeName}>` : "";
2344
- const entries = objectTypeNames.map((name) => ` readonly ${name}: FragmentBuilderFor<Schema_${schemaName}, "${name}"${adapterPart}>`);
2345
- return `type FragmentBuilders_${schemaName} = {\n${entries.join(";\n")};\n};`;
2346
- };
2347
2319
  const collectInputTypeNames = (schema) => Array.from(schema.inputs.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
2348
2320
  const collectEnumTypeNames = (schema) => Array.from(schema.enums.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
2349
2321
  const collectUnionTypeNames = (schema) => Array.from(schema.unions.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
@@ -2521,7 +2493,7 @@ const multiRuntimeTemplate = ($$) => {
2521
2493
  }
2522
2494
  const extraImports = imports.length > 0 ? `${imports.join("\n")}\n` : "";
2523
2495
  const schemaBlocks = [];
2524
- const gqlEntries = [];
2496
+ const gqlExports = [];
2525
2497
  for (const [name, config] of Object.entries($$.schemas)) {
2526
2498
  const schemaVar = `${name}Schema`;
2527
2499
  const adapterVar = adapterAliases.get(name);
@@ -2529,7 +2501,6 @@ const multiRuntimeTemplate = ($$) => {
2529
2501
  if (adapterVar) {
2530
2502
  typeExports.push(`export type Adapter_${name} = typeof ${adapterVar} & { _?: never };`);
2531
2503
  }
2532
- typeExports.push(config.fragmentBuildersTypeBlock);
2533
2504
  const inputTypeMethodsVar = `inputTypeMethods_${name}`;
2534
2505
  const factoryVar = `createMethod_${name}`;
2535
2506
  const customDirectivesVar = `customDirectives_${name}`;
@@ -2590,10 +2561,10 @@ const ${customDirectivesVar} = { ...createStandardDirectives(), ...${config.dire
2590
2561
  ${typeExports.join("\n")}`);
2591
2562
  const gqlVarName = `gql_${name}`;
2592
2563
  if (adapterVar) {
2593
- const typeParams = `<Schema_${name}, FragmentBuilders_${name}, typeof ${customDirectivesVar}, Adapter_${name}>`;
2564
+ const typeParams = `<Schema_${name}, typeof ${customDirectivesVar}, Adapter_${name}>`;
2594
2565
  schemaBlocks.push(`const ${gqlVarName} = createGqlElementComposer${typeParams}(${schemaVar}, { adapter: ${adapterVar}, inputTypeMethods: ${inputTypeMethodsVar}, directiveMethods: ${customDirectivesVar} });`);
2595
2566
  } else {
2596
- const typeParams = `<Schema_${name}, FragmentBuilders_${name}, typeof ${customDirectivesVar}>`;
2567
+ const typeParams = `<Schema_${name}, typeof ${customDirectivesVar}>`;
2597
2568
  schemaBlocks.push(`const ${gqlVarName} = createGqlElementComposer${typeParams}(${schemaVar}, { inputTypeMethods: ${inputTypeMethodsVar}, directiveMethods: ${customDirectivesVar} });`);
2598
2569
  }
2599
2570
  schemaBlocks.push(`export type Context_${name} = Parameters<typeof ${gqlVarName}>[0] extends (ctx: infer C) => unknown ? C : never;`);
@@ -2606,13 +2577,11 @@ ${typeExports.join("\n")}`);
2606
2577
  prebuiltExports.push(`export { ${adapterVar} as __adapter_${name} }`);
2607
2578
  }
2608
2579
  schemaBlocks.push(`${prebuiltExports.join(";\n")};`);
2609
- gqlEntries.push(` ${name}: ${gqlVarName}`);
2580
+ gqlExports.push(`export { ${gqlVarName} as __gql_${name} }`);
2610
2581
  }
2611
2582
  const needsDefineEnum = false;
2612
2583
  return `\
2613
2584
  import {${needsDefineEnum ? "\n defineEnum," : ""}
2614
- type ExtractMetadataAdapter,
2615
- type FragmentBuilderFor,
2616
2585
  type AnyGraphqlSchema,
2617
2586
  createDirectiveMethod,
2618
2587
  createTypedDirectiveMethod,
@@ -2623,9 +2592,7 @@ import {${needsDefineEnum ? "\n defineEnum," : ""}
2623
2592
  ${extraImports}
2624
2593
  ${schemaBlocks.join("\n")}
2625
2594
 
2626
- export const gql = {
2627
- ${gqlEntries.join(",\n")}
2628
- };
2595
+ ${gqlExports.join(";\n")};
2629
2596
  `;
2630
2597
  };
2631
2598
  const generateMultiSchemaModule = (schemas, options) => {
@@ -2699,8 +2666,6 @@ const generateMultiSchemaModule = (schemas, options) => {
2699
2666
  const factoryVar = `createMethod_${name}`;
2700
2667
  const inputTypeMethodsBlock = renderInputTypeMethods(schema, factoryVar, excluded);
2701
2668
  const directiveMethodsBlock = renderDirectiveMethods(schema, excluded);
2702
- const adapterTypeName = options?.injection?.get(name)?.adapterImportPath ? `Adapter_${name}` : undefined;
2703
- const fragmentBuildersTypeBlock = renderFragmentBuildersType(objectTypeNames, name, adapterTypeName);
2704
2669
  const queryType = schema.operationTypes.query ?? "Query";
2705
2670
  const mutationType = schema.operationTypes.mutation ?? "Mutation";
2706
2671
  const subscriptionType = schema.operationTypes.subscription ?? "Subscription";
@@ -2720,7 +2685,6 @@ const generateMultiSchemaModule = (schemas, options) => {
2720
2685
  unionNames: unionTypeNames,
2721
2686
  inputTypeMethodsBlock,
2722
2687
  directiveMethodsBlock,
2723
- fragmentBuildersTypeBlock,
2724
2688
  defaultInputDepth: options?.defaultInputDepth?.get(name),
2725
2689
  inputDepthOverrides: options?.inputDepthOverrides?.get(name)
2726
2690
  };
@@ -2768,6 +2732,137 @@ const generateMultiSchemaModule = (schemas, options) => {
2768
2732
  stats: allStats
2769
2733
  };
2770
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
+ };
2771
2866
 
2772
2867
  //#endregion
2773
2868
  Object.defineProperty(exports, '__toESM', {
@@ -2776,16 +2871,34 @@ Object.defineProperty(exports, '__toESM', {
2776
2871
  return __toESM;
2777
2872
  }
2778
2873
  });
2874
+ Object.defineProperty(exports, 'compileTypeFilter', {
2875
+ enumerable: true,
2876
+ get: function () {
2877
+ return compileTypeFilter;
2878
+ }
2879
+ });
2779
2880
  Object.defineProperty(exports, 'createSchemaIndex', {
2780
2881
  enumerable: true,
2781
2882
  get: function () {
2782
2883
  return createSchemaIndex;
2783
2884
  }
2784
2885
  });
2886
+ Object.defineProperty(exports, 'generateIndexModule', {
2887
+ enumerable: true,
2888
+ get: function () {
2889
+ return generateIndexModule;
2890
+ }
2891
+ });
2785
2892
  Object.defineProperty(exports, 'generateMultiSchemaModule', {
2786
2893
  enumerable: true,
2787
2894
  get: function () {
2788
2895
  return generateMultiSchemaModule;
2789
2896
  }
2790
2897
  });
2791
- //# sourceMappingURL=generator-DaUj21om.cjs.map
2898
+ Object.defineProperty(exports, 'generatePrebuiltStub', {
2899
+ enumerable: true,
2900
+ get: function () {
2901
+ return generatePrebuiltStub;
2902
+ }
2903
+ });
2904
+ //# sourceMappingURL=generator-BEFJKQs_.cjs.map