@soda-gql/codegen 0.11.24 → 0.11.25

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/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as neverthrow0 from "neverthrow";
1
+ import * as neverthrow3 from "neverthrow";
2
2
  import { Result } from "neverthrow";
3
3
  import { ConstDirectiveNode, DocumentNode, EnumValueDefinitionNode, FieldDefinitionNode, InputValueDefinitionNode, NamedTypeNode, TypeNode } from "graphql";
4
4
  import { TypeFilterConfig } from "@soda-gql/config";
@@ -640,7 +640,7 @@ type CodegenSuccess = {
640
640
  type CodegenResult = Result<CodegenSuccess, CodegenError>;
641
641
  //#endregion
642
642
  //#region packages/codegen/src/inject-template.d.ts
643
- declare const writeInjectTemplate: (outPath: string) => neverthrow0.Err<void, CodegenError> | neverthrow0.Ok<void, CodegenError>;
643
+ declare const writeInjectTemplate: (outPath: string) => neverthrow3.Err<void, CodegenError> | neverthrow3.Ok<void, CodegenError>;
644
644
  declare const getInjectTemplate: () => string;
645
645
  //#endregion
646
646
  //#region packages/codegen/src/runner.d.ts
@@ -651,12 +651,12 @@ declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
651
651
  * Load a single schema file.
652
652
  * @internal Use loadSchema for public API.
653
653
  */
654
- declare const loadSingleSchema: (schemaPath: string) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
654
+ declare const loadSingleSchema: (schemaPath: string) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
655
655
  /**
656
656
  * Load and merge multiple schema files into a single DocumentNode.
657
657
  * Uses GraphQL's concatAST to combine definitions from all files.
658
658
  */
659
- declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
659
+ declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
660
660
  declare const hashSchema: (document: DocumentNode) => string;
661
661
  //#endregion
662
662
  export { type CodegenCliCommand, type CodegenError, type CodegenFormat, type CodegenInjectConfig, type CodegenOptions, type CodegenResult, type CodegenSchemaConfig, type CodegenSuccess, EmitOptions, EnrichedFragment, EnrichedOperation, EnrichedVariable, GeneratedFile, GraphqlCompatError, GraphqlCompatOptions, InferredVariable, ParseResult, ParsedArgument, ParsedFieldSelection, ParsedFragment, ParsedFragmentSpread, ParsedInlineFragment, ParsedObjectField, ParsedOperation, ParsedSelection, ParsedValue, ParsedVariable, TransformOptions, TransformResult, TypeInfo, collectVariableUsages, emitFragment, emitOperation, getArgumentType, getFieldReturnType, getInputFieldType, hashSchema, inferVariablesFromUsages, isModifierAssignable, loadSchema, mergeModifiers, mergeVariableUsages, parseGraphqlFile, parseGraphqlSource, parseTypeNode, runCodegen, sortFragmentsByDependency, transformParsedGraphql, writeInjectTemplate };
package/dist/index.mjs CHANGED
@@ -936,9 +936,12 @@ const emitSelectionsInternal = (selections, indent, variableNames, schema, paren
936
936
  const lines = [];
937
937
  const inlineFragments = [];
938
938
  const otherSelections = [];
939
+ let hasTypenameField = false;
939
940
  for (const sel of selections) {
940
941
  if (sel.kind === "inlineFragment") {
941
942
  inlineFragments.push(sel);
943
+ } else if (sel.kind === "field" && sel.name === "__typename" && !sel.alias) {
944
+ hasTypenameField = true;
942
945
  } else {
943
946
  otherSelections.push(sel);
944
947
  }
@@ -951,11 +954,14 @@ const emitSelectionsInternal = (selections, indent, variableNames, schema, paren
951
954
  lines.push(result.value);
952
955
  }
953
956
  if (inlineFragments.length > 0) {
954
- const unionResult = emitInlineFragmentsAsUnion(inlineFragments, indent, variableNames, schema);
957
+ const unionResult = emitInlineFragmentsAsUnion(inlineFragments, indent, variableNames, schema, hasTypenameField);
955
958
  if (unionResult.isErr()) {
956
959
  return err(unionResult.error);
957
960
  }
958
961
  lines.push(unionResult.value);
962
+ } else if (hasTypenameField) {
963
+ const padding = " ".repeat(indent);
964
+ lines.push(`${padding}__typename: true,`);
959
965
  }
960
966
  return ok(lines.join("\n"));
961
967
  };
@@ -972,9 +978,9 @@ const emitSingleSelection = (sel, indent, variableNames, schema, parentTypeName)
972
978
  };
973
979
  /**
974
980
  * Emit inline fragments grouped as a union selection.
975
- * Format: { TypeA: ({ f }) => ({ ...fields }), TypeB: ({ f }) => ({ ...fields }) }
981
+ * Format: { TypeA: ({ f }) => ({ ...fields }), TypeB: ({ f }) => ({ ...fields }), __typename: true }
976
982
  */
977
- const emitInlineFragmentsAsUnion = (inlineFragments, indent, variableNames, schema) => {
983
+ const emitInlineFragmentsAsUnion = (inlineFragments, indent, variableNames, schema, includeTypename) => {
978
984
  const padding = " ".repeat(indent);
979
985
  for (const frag of inlineFragments) {
980
986
  if (frag.onType === "") {
@@ -1013,6 +1019,10 @@ const emitInlineFragmentsAsUnion = (inlineFragments, indent, variableNames, sche
1013
1019
  ${fieldsResult.value}
1014
1020
  ${innerPadding}}),`);
1015
1021
  }
1022
+ if (includeTypename) {
1023
+ const innerPadding = " ".repeat(indent + 1);
1024
+ entries.push(`${innerPadding}__typename: true,`);
1025
+ }
1016
1026
  return ok(`${padding}...({
1017
1027
  ${entries.join("\n")}
1018
1028
  ${padding}}),`);