houdini 1.0.0-next.2 → 1.0.0-next.4

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.
Files changed (72) hide show
  1. package/build/cmd-cjs/index.js +1417 -1231
  2. package/build/cmd-esm/index.js +1417 -1231
  3. package/build/codegen/generators/artifacts/selection.d.ts +3 -3
  4. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  5. package/build/codegen/generators/typescript/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
  6. package/build/codegen/transforms/fragmentVariables.d.ts +1 -0
  7. package/build/codegen-cjs/index.js +1262 -1078
  8. package/build/codegen-esm/index.js +1262 -1078
  9. package/build/lib/config.d.ts +1 -1
  10. package/build/lib/walk.d.ts +4 -1
  11. package/build/lib-cjs/index.js +10 -10
  12. package/build/lib-esm/index.js +10 -10
  13. package/build/runtime/cache/cache.d.ts +3 -3
  14. package/build/runtime/cache/lists.d.ts +1 -0
  15. package/build/runtime/client/documentStore.d.ts +1 -1
  16. package/build/runtime/client/plugins/fetchParams.d.ts +1 -1
  17. package/build/runtime/generated.d.ts +1 -0
  18. package/build/runtime/index.d.ts +1 -1
  19. package/build/runtime/lib/config.d.ts +21 -22
  20. package/build/runtime/lib/scalars.d.ts +2 -2
  21. package/build/runtime/lib/types.d.ts +2 -3
  22. package/build/runtime/public/cache.d.ts +19 -6
  23. package/build/runtime/public/record.d.ts +17 -17
  24. package/build/runtime/public/tests/test.d.ts +43 -0
  25. package/build/runtime/public/types.d.ts +8 -0
  26. package/build/runtime-cjs/cache/cache.d.ts +3 -3
  27. package/build/runtime-cjs/cache/cache.js +30 -15
  28. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  29. package/build/runtime-cjs/cache/lists.js +6 -3
  30. package/build/runtime-cjs/client/documentStore.d.ts +1 -1
  31. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
  32. package/build/runtime-cjs/client/plugins/fetchParams.js +6 -1
  33. package/build/runtime-cjs/client/plugins/query.js +0 -1
  34. package/build/runtime-cjs/generated.d.ts +1 -0
  35. package/build/runtime-cjs/index.d.ts +1 -1
  36. package/build/runtime-cjs/lib/config.d.ts +21 -22
  37. package/build/runtime-cjs/lib/scalars.d.ts +2 -2
  38. package/build/runtime-cjs/lib/types.d.ts +2 -3
  39. package/build/runtime-cjs/public/cache.d.ts +19 -6
  40. package/build/runtime-cjs/public/cache.js +29 -32
  41. package/build/runtime-cjs/public/list.js +6 -28
  42. package/build/runtime-cjs/public/record.d.ts +17 -17
  43. package/build/runtime-cjs/public/record.js +22 -188
  44. package/build/runtime-cjs/public/tests/test.d.ts +43 -0
  45. package/build/runtime-cjs/public/tests/test.js +27 -2
  46. package/build/runtime-cjs/public/types.d.ts +8 -0
  47. package/build/runtime-esm/cache/cache.d.ts +3 -3
  48. package/build/runtime-esm/cache/cache.js +30 -15
  49. package/build/runtime-esm/cache/lists.d.ts +1 -0
  50. package/build/runtime-esm/cache/lists.js +6 -3
  51. package/build/runtime-esm/client/documentStore.d.ts +1 -1
  52. package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
  53. package/build/runtime-esm/client/plugins/fetchParams.js +6 -1
  54. package/build/runtime-esm/client/plugins/query.js +0 -1
  55. package/build/runtime-esm/generated.d.ts +1 -0
  56. package/build/runtime-esm/index.d.ts +1 -1
  57. package/build/runtime-esm/lib/config.d.ts +21 -22
  58. package/build/runtime-esm/lib/scalars.d.ts +2 -2
  59. package/build/runtime-esm/lib/types.d.ts +2 -3
  60. package/build/runtime-esm/public/cache.d.ts +19 -6
  61. package/build/runtime-esm/public/cache.js +28 -30
  62. package/build/runtime-esm/public/list.js +6 -28
  63. package/build/runtime-esm/public/record.d.ts +17 -17
  64. package/build/runtime-esm/public/record.js +21 -184
  65. package/build/runtime-esm/public/tests/test.d.ts +43 -0
  66. package/build/runtime-esm/public/tests/test.js +26 -1
  67. package/build/runtime-esm/public/types.d.ts +8 -0
  68. package/build/test-cjs/index.js +1270 -1087
  69. package/build/test-esm/index.js +1270 -1087
  70. package/build/vite-cjs/index.js +1271 -1087
  71. package/build/vite-esm/index.js +1271 -1087
  72. package/package.json +1 -1
@@ -54349,8 +54349,7 @@ var Config = class {
54349
54349
  types: types14 = {},
54350
54350
  logLevel,
54351
54351
  defaultFragmentMasking = "enable",
54352
- schemaPollInterval = 2e3,
54353
- schemaPollHeaders = {},
54352
+ watchSchema,
54354
54353
  projectDir
54355
54354
  } = this.configFile;
54356
54355
  if (typeof schema === "string") {
@@ -54383,8 +54382,8 @@ var Config = class {
54383
54382
  this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
54384
54383
  this.defaultFragmentMasking = defaultFragmentMasking;
54385
54384
  this.routesDir = join(this.projectRoot, "src", "routes");
54386
- this.schemaPollInterval = schemaPollInterval;
54387
- this.schemaPollHeaders = schemaPollHeaders;
54385
+ this.schemaPollInterval = watchSchema?.interval ?? 2e3;
54386
+ this.schemaPollHeaders = watchSchema?.headers ?? {};
54388
54387
  this.rootDir = join(this.projectRoot, "$houdini");
54389
54388
  if (defaultKeys) {
54390
54389
  this.defaultKeys = defaultKeys;
@@ -54397,11 +54396,12 @@ var Config = class {
54397
54396
  }
54398
54397
  }
54399
54398
  async apiURL() {
54400
- if (!this.configFile.apiUrl) {
54399
+ const apiURL = this.configFile.watchSchema?.url;
54400
+ if (!apiURL) {
54401
54401
  return "";
54402
54402
  }
54403
54403
  const env = await this.getEnv();
54404
- return this.processEnvValues(env, this.configFile.apiUrl);
54404
+ return this.processEnvValues(env, apiURL);
54405
54405
  }
54406
54406
  get include() {
54407
54407
  if (this.configFile.include) {
@@ -54605,8 +54605,8 @@ var Config = class {
54605
54605
  pluginDirectory(name2) {
54606
54606
  return join(this.pluginRootDirectory, name2);
54607
54607
  }
54608
- get manualLoadDirective() {
54609
- return "manual_load";
54608
+ get loadDirective() {
54609
+ return "load";
54610
54610
  }
54611
54611
  get maskEnableDirective() {
54612
54612
  return "mask_enable";
@@ -54723,7 +54723,7 @@ var Config = class {
54723
54723
  this.withDirective,
54724
54724
  this.paginateDirective,
54725
54725
  this.cacheDirective,
54726
- this.manualLoadDirective,
54726
+ this.loadDirective,
54727
54727
  this.maskEnableDirective,
54728
54728
  this.maskDisableDirective
54729
54729
  ].includes(name2.value) || this.isDeleteDirective(name2.value);
@@ -54994,7 +54994,7 @@ async function cleanupFiles(pathFolder, listOfObj) {
54994
54994
  }
54995
54995
 
54996
54996
  // src/codegen/generators/artifacts/index.ts
54997
- var graphql11 = __toESM(require_graphql2(), 1);
54997
+ var graphql12 = __toESM(require_graphql2(), 1);
54998
54998
  var recast5 = __toESM(require_main2(), 1);
54999
54999
 
55000
55000
  // src/codegen/utils/commonjs.ts
@@ -55252,159 +55252,534 @@ function murmurHash(str) {
55252
55252
  return s;
55253
55253
  }
55254
55254
 
55255
- // src/codegen/generators/artifacts/indexFile.ts
55256
- async function writeIndexFile(config2, docs) {
55257
- const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
55258
- let body = config2.module === "esm" ? docsToGenerate.reduce(
55259
- (content, doc) => content + `
55260
- export { default as ${doc.name}} from './${doc.name}'`,
55261
- ""
55262
- ) : docsToGenerate.reduce(
55263
- (content, doc) => content + `
55264
- ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
55265
- cjsIndexFilePreamble
55266
- );
55267
- await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
55268
- }
55269
-
55270
- // src/codegen/generators/artifacts/inputs.ts
55255
+ // src/codegen/transforms/fragmentVariables.ts
55271
55256
  var graphql3 = __toESM(require_graphql2(), 1);
55272
- var recast3 = __toESM(require_main2(), 1);
55273
- var AST3 = recast3.types.builders;
55274
- function inputObject(config2, inputs) {
55275
- const visitedTypes = /* @__PURE__ */ new Set();
55276
- const inputObj = {
55277
- fields: inputs.reduce((fields, input) => {
55278
- const { type } = unwrapType(config2, input.type);
55279
- return {
55280
- ...fields,
55281
- [input.variable.name.value]: type.name
55282
- };
55283
- }, {}),
55284
- types: {}
55285
- };
55286
- for (const input of inputs) {
55287
- walkInputs(config2, visitedTypes, inputObj, input.type);
55288
- }
55289
- return inputObj;
55290
- }
55291
- function walkInputs(config2, visitedTypes, inputObj, rootType) {
55292
- const { type } = unwrapType(config2, rootType);
55293
- if (visitedTypes.has(type.name)) {
55294
- return;
55295
- }
55296
- if (graphql3.isEnumType(type) || graphql3.isScalarType(type)) {
55297
- return;
55298
- }
55299
- if (graphql3.isUnionType(type)) {
55300
- return;
55301
- }
55302
- visitedTypes.add(type.name);
55303
- inputObj.types[type.name] = Object.values(type.getFields()).reduce(
55304
- (typeFields, field) => {
55305
- const { type: fieldType } = unwrapType(config2, field.type);
55306
- walkInputs(config2, visitedTypes, inputObj, fieldType);
55307
- return {
55308
- ...typeFields,
55309
- [field.name]: fieldType.toString()
55310
- };
55311
- },
55312
- {}
55313
- );
55314
- }
55315
55257
 
55316
- // src/codegen/generators/artifacts/operations.ts
55317
- var graphql5 = __toESM(require_graphql2(), 1);
55318
-
55319
- // src/codegen/generators/artifacts/utils.ts
55320
- var graphql4 = __toESM(require_graphql2(), 1);
55321
- var recast4 = __toESM(require_main2(), 1);
55322
- var AST4 = recast4.types.builders;
55323
- function serializeValue(value) {
55324
- if (Array.isArray(value)) {
55325
- return AST4.arrayExpression(value.map(serializeValue));
55258
+ // src/codegen/transforms/composeQueries.ts
55259
+ var import_graphql = __toESM(require_graphql2(), 1);
55260
+ async function includeFragmentDefinitions(config2, documents) {
55261
+ const fragments = collectFragments(config2, documents);
55262
+ for (const [index, { name: name2, document, filename }] of documents.entries()) {
55263
+ const operation = document.definitions.find(
55264
+ ({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
55265
+ );
55266
+ if (!operation) {
55267
+ continue;
55268
+ }
55269
+ const allFragments = flattenFragments(
55270
+ filename,
55271
+ { requiredFragments: findRequiredFragments(operation.selectionSet) },
55272
+ fragments
55273
+ );
55274
+ documents[index].document = {
55275
+ ...document,
55276
+ definitions: [
55277
+ operation,
55278
+ ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
55279
+ ]
55280
+ };
55326
55281
  }
55327
- if (typeof value === "object" && value !== null) {
55328
- return AST4.objectExpression(
55329
- Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
55330
- ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
55331
- )
55282
+ }
55283
+ function collectFragments(config2, docs) {
55284
+ return docs.reduce((acc, doc) => {
55285
+ const definitions = doc.document.definitions.reduce(
55286
+ (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
55287
+ ...prev,
55288
+ [definition.name.value]: {
55289
+ definition,
55290
+ requiredFragments: findRequiredFragments(definition.selectionSet),
55291
+ document: doc
55292
+ }
55293
+ },
55294
+ {}
55332
55295
  );
55296
+ return {
55297
+ ...acc,
55298
+ ...definitions
55299
+ };
55300
+ }, {});
55301
+ }
55302
+ function findRequiredFragments(selectionSet) {
55303
+ if (selectionSet.selections.length === 0) {
55304
+ return [];
55333
55305
  }
55334
- if (typeof value === "string") {
55335
- if (value.indexOf("\n") !== -1) {
55336
- return AST4.templateLiteral(
55337
- [AST4.templateElement({ raw: value, cooked: value }, true)],
55338
- []
55339
- );
55306
+ const referencedFragments = [];
55307
+ for (const selection2 of selectionSet.selections) {
55308
+ if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
55309
+ referencedFragments.push(selection2.name.value);
55310
+ } else if (selection2.selectionSet) {
55311
+ referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
55340
55312
  }
55341
- return AST4.stringLiteral(value);
55342
55313
  }
55343
- return AST4.literal(value);
55314
+ return referencedFragments;
55344
55315
  }
55345
- function deepMerge(filepath, ...targets) {
55346
- if (typeof targets[0] !== "object") {
55347
- const matches = targets.filter((val) => val !== targets[0]).length === 0;
55348
- if (!matches) {
55349
- throw new HoudiniError({ filepath, message: "could not merge: " + targets });
55316
+ function flattenFragments(filepath, operation, fragments) {
55317
+ const frags = /* @__PURE__ */ new Set();
55318
+ const remaining = [...operation.requiredFragments];
55319
+ while (remaining.length > 0) {
55320
+ const nextFragment = remaining.shift();
55321
+ if (!nextFragment) {
55322
+ continue;
55350
55323
  }
55351
- return targets[0];
55352
- }
55353
- if (Array.isArray(targets[0])) {
55354
- return targets[0].concat(...targets.slice(1));
55355
- }
55356
- const fields = {};
55357
- for (const target of targets) {
55358
- for (const [key, value] of Object.entries(target)) {
55359
- if (!fields[key]) {
55360
- fields[key] = [];
55361
- }
55362
- fields[key].push(value);
55324
+ if (!frags.has(nextFragment)) {
55325
+ frags.add(nextFragment);
55326
+ } else {
55327
+ continue;
55328
+ }
55329
+ const targetFragment = fragments[nextFragment];
55330
+ if (!targetFragment) {
55331
+ throw new HoudiniError({
55332
+ filepath,
55333
+ message: "compose: could not find definition for fragment " + nextFragment
55334
+ });
55363
55335
  }
55336
+ remaining.push(...targetFragment.requiredFragments);
55364
55337
  }
55365
- return Object.fromEntries(
55366
- Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
55367
- );
55338
+ return [...frags];
55368
55339
  }
55369
- function convertValue(config2, val) {
55370
- let value;
55371
- let kind;
55372
- if (val.kind === graphql4.Kind.INT) {
55373
- value = parseInt(val.value, 10);
55374
- kind = "Int";
55375
- } else if (val.kind === graphql4.Kind.FLOAT) {
55376
- value = parseFloat(val.value);
55377
- kind = "Float";
55378
- } else if (val.kind === graphql4.Kind.BOOLEAN) {
55379
- value = val.value;
55380
- kind = "Boolean";
55381
- } else if (val.kind === graphql4.Kind.VARIABLE) {
55382
- value = val.name.value;
55383
- kind = "Variable";
55384
- } else if (val.kind === graphql4.Kind.STRING) {
55385
- value = val.value;
55386
- kind = "String";
55340
+
55341
+ // src/codegen/transforms/fragmentVariables.ts
55342
+ var GraphqlKinds2 = graphql3.Kind;
55343
+ async function fragmentVariables(config2, documents) {
55344
+ const fragments = collectFragments(config2, documents);
55345
+ const generatedFragments = {};
55346
+ const visitedFragments = /* @__PURE__ */ new Set();
55347
+ for (const doc2 of documents) {
55348
+ const operation = doc2.document.definitions.find(
55349
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
55350
+ );
55351
+ if (!operation) {
55352
+ continue;
55353
+ }
55354
+ doc2.document = inlineFragmentArgs({
55355
+ config: config2,
55356
+ filepath: doc2.filename,
55357
+ fragmentDefinitions: fragments,
55358
+ document: doc2.document,
55359
+ generatedFragments,
55360
+ visitedFragments,
55361
+ scope: null
55362
+ });
55387
55363
  }
55388
- return { kind, value };
55364
+ const doc = {
55365
+ kind: graphql3.Kind.DOCUMENT,
55366
+ definitions: Object.values(generatedFragments)
55367
+ };
55368
+ documents.push({
55369
+ name: "generated::fragmentVariables",
55370
+ kind: "HoudiniFragment" /* Fragment */,
55371
+ document: doc,
55372
+ originalDocument: doc,
55373
+ generateStore: false,
55374
+ generateArtifact: false,
55375
+ filename: "generated::fragmentVariables",
55376
+ originalString: ""
55377
+ });
55389
55378
  }
55390
-
55391
- // src/codegen/generators/artifacts/operations.ts
55392
- function operationsByPath(config2, filepath, definition, filterTypes) {
55393
- if (!definition) {
55394
- return {};
55379
+ function inlineFragmentArgs({
55380
+ config: config2,
55381
+ filepath,
55382
+ fragmentDefinitions,
55383
+ document,
55384
+ generatedFragments,
55385
+ visitedFragments,
55386
+ scope,
55387
+ newName
55388
+ }) {
55389
+ if (!scope) {
55390
+ scope = operationScope(
55391
+ document.definitions.find(
55392
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
55393
+ )
55394
+ );
55395
55395
  }
55396
- const pathOperations = {};
55397
- graphql5.visit(definition, {
55398
- FragmentSpread(node, _, __, ___, ancestors) {
55399
- if (!config2.isListFragment(node.name.value)) {
55400
- return;
55401
- }
55402
- const path2 = ancestorKey(ancestors);
55403
- if (!pathOperations[path2]) {
55404
- pathOperations[path2] = [];
55405
- }
55406
- pathOperations[path2].push(
55407
- operationObject({
55396
+ const definitionArgs = fragmentArguments(
55397
+ config2,
55398
+ filepath,
55399
+ document
55400
+ ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
55401
+ const result = graphql3.visit(document, {
55402
+ FragmentSpread(node) {
55403
+ const { definition } = fragmentDefinitions[node.name.value];
55404
+ let { args, hash } = collectWithArguments(config2, filepath, node, scope);
55405
+ const newFragmentName = `${node.name.value}${hash}`;
55406
+ if (!visitedFragments.has(newFragmentName)) {
55407
+ visitedFragments.add(newFragmentName);
55408
+ const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
55409
+ if (args) {
55410
+ for (const [field, value] of Object.entries(defaultArguments || {})) {
55411
+ if (!args[field]) {
55412
+ args[field] = value;
55413
+ }
55414
+ }
55415
+ generatedFragments[newFragmentName] = inlineFragmentArgs({
55416
+ config: config2,
55417
+ filepath,
55418
+ fragmentDefinitions,
55419
+ document: fragmentDefinitions[node.name.value].definition,
55420
+ generatedFragments,
55421
+ visitedFragments,
55422
+ scope: args,
55423
+ newName: newFragmentName
55424
+ });
55425
+ } else {
55426
+ const doc = fragmentDefinitions[node.name.value].document;
55427
+ const definitionIndex = doc.document.definitions.findIndex(
55428
+ (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
55429
+ );
55430
+ const localDefinitions = [...doc.document.definitions];
55431
+ localDefinitions.splice(definitionIndex, 1);
55432
+ localDefinitions.push(
55433
+ inlineFragmentArgs({
55434
+ config: config2,
55435
+ filepath,
55436
+ fragmentDefinitions,
55437
+ document: fragmentDefinitions[node.name.value].definition,
55438
+ generatedFragments,
55439
+ visitedFragments,
55440
+ scope: defaultArguments,
55441
+ newName: ""
55442
+ })
55443
+ );
55444
+ doc.document = {
55445
+ ...doc.document,
55446
+ definitions: localDefinitions
55447
+ };
55448
+ }
55449
+ if (node.name.value !== newFragmentName) {
55450
+ return {
55451
+ ...node,
55452
+ name: {
55453
+ kind: "Name",
55454
+ value: newFragmentName
55455
+ }
55456
+ };
55457
+ }
55458
+ }
55459
+ },
55460
+ Argument(node) {
55461
+ const value = node.value;
55462
+ if (value.kind !== "Variable") {
55463
+ return;
55464
+ }
55465
+ if (!scope) {
55466
+ throw new HoudiniError({
55467
+ filepath,
55468
+ message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
55469
+ });
55470
+ }
55471
+ const newValue = scope[value.name.value];
55472
+ if (newValue) {
55473
+ return {
55474
+ ...node,
55475
+ value: newValue
55476
+ };
55477
+ }
55478
+ if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
55479
+ throw new HoudiniError({
55480
+ filepath,
55481
+ message: "Missing value for required arg: " + value.name.value
55482
+ });
55483
+ }
55484
+ return null;
55485
+ }
55486
+ });
55487
+ if (newName) {
55488
+ result.name = {
55489
+ kind: graphql3.Kind.NAME,
55490
+ value: newName
55491
+ };
55492
+ }
55493
+ return result;
55494
+ }
55495
+ function withArguments(config2, node) {
55496
+ const withDirectives = node.directives?.filter(
55497
+ (directive) => directive.name.value === config2.withDirective
55498
+ );
55499
+ if (!withDirectives || withDirectives.length === 0) {
55500
+ return [];
55501
+ }
55502
+ return withDirectives.flatMap((directive) => directive.arguments || []);
55503
+ }
55504
+ function fragmentArguments(config2, filepath, definition) {
55505
+ const directives = definition.directives?.filter(
55506
+ (directive) => directive.name.value === config2.argumentsDirective
55507
+ );
55508
+ if (!directives || directives.length === 0) {
55509
+ return [];
55510
+ }
55511
+ return directives.flatMap(
55512
+ (directive) => directive.arguments?.flatMap((arg) => {
55513
+ if (arg.value.kind !== "ObjectValue") {
55514
+ throw new HoudiniError({
55515
+ filepath,
55516
+ message: "values of @argument must be objects"
55517
+ });
55518
+ }
55519
+ const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
55520
+ if (!typeArg || typeArg.kind !== "StringValue") {
55521
+ return [];
55522
+ }
55523
+ let type = typeArg.value;
55524
+ let name2 = arg.name.value;
55525
+ let required = false;
55526
+ let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
55527
+ if (type[type.length - 1] === "!") {
55528
+ type = type.slice(0, -1);
55529
+ required = true;
55530
+ defaultValue = null;
55531
+ }
55532
+ return [
55533
+ {
55534
+ name: name2,
55535
+ type,
55536
+ required,
55537
+ defaultValue
55538
+ }
55539
+ ];
55540
+ }) || []
55541
+ );
55542
+ }
55543
+ function collectDefaultArgumentValues(config2, filepath, definition) {
55544
+ let result = {};
55545
+ for (const { name: name2, required, defaultValue } of fragmentArguments(
55546
+ config2,
55547
+ filepath,
55548
+ definition
55549
+ )) {
55550
+ if (required || !defaultValue) {
55551
+ continue;
55552
+ }
55553
+ result[name2] = defaultValue;
55554
+ }
55555
+ return result;
55556
+ }
55557
+ function collectWithArguments(config2, filepath, node, scope = {}) {
55558
+ const withArgs = withArguments(config2, node);
55559
+ if (withArgs.length === 0) {
55560
+ return { args: null, hash: "" };
55561
+ }
55562
+ let args = {};
55563
+ for (const arg of withArgs) {
55564
+ let value = arg.value;
55565
+ if (value.kind === GraphqlKinds2.VARIABLE) {
55566
+ if (!scope || !scope[value.name.value]) {
55567
+ throw new HoudiniError({
55568
+ filepath,
55569
+ message: "Encountered undefined variable: " + value.name.value
55570
+ });
55571
+ }
55572
+ value = scope[value.name.value];
55573
+ }
55574
+ args[arg.name.value] = {
55575
+ ...value,
55576
+ loc: void 0
55577
+ };
55578
+ }
55579
+ return {
55580
+ args,
55581
+ hash: "_" + murmurHash(JSON.stringify(args))
55582
+ };
55583
+ }
55584
+ function operationScope(operation) {
55585
+ return operation.variableDefinitions?.reduce(
55586
+ (scope, definition) => ({
55587
+ ...scope,
55588
+ [definition.variable.name.value]: {
55589
+ kind: "Variable",
55590
+ name: {
55591
+ kind: "Name",
55592
+ value: definition.variable.name.value
55593
+ }
55594
+ }
55595
+ }),
55596
+ {}
55597
+ ) || {};
55598
+ }
55599
+ function fragmentArgumentsDefinitions(config2, filepath, definition) {
55600
+ const args = fragmentArguments(config2, filepath, definition);
55601
+ if (args.length === 0) {
55602
+ return [];
55603
+ }
55604
+ return args.map((arg) => {
55605
+ const innerType = {
55606
+ kind: "NamedType",
55607
+ name: {
55608
+ kind: "Name",
55609
+ value: arg.type
55610
+ }
55611
+ };
55612
+ return {
55613
+ kind: "VariableDefinition",
55614
+ type: arg.required ? innerType : {
55615
+ kind: "NonNullType",
55616
+ type: innerType
55617
+ },
55618
+ variable: {
55619
+ kind: "Variable",
55620
+ name: {
55621
+ kind: "Name",
55622
+ value: arg.name
55623
+ }
55624
+ },
55625
+ defaultValue: arg.defaultValue ?? void 0
55626
+ };
55627
+ });
55628
+ }
55629
+
55630
+ // src/codegen/generators/artifacts/indexFile.ts
55631
+ async function writeIndexFile(config2, docs) {
55632
+ const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
55633
+ let body = config2.module === "esm" ? docsToGenerate.reduce(
55634
+ (content, doc) => content + `
55635
+ export { default as ${doc.name}} from './${doc.name}'`,
55636
+ ""
55637
+ ) : docsToGenerate.reduce(
55638
+ (content, doc) => content + `
55639
+ ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
55640
+ cjsIndexFilePreamble
55641
+ );
55642
+ await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
55643
+ }
55644
+
55645
+ // src/codegen/generators/artifacts/inputs.ts
55646
+ var graphql4 = __toESM(require_graphql2(), 1);
55647
+ var recast3 = __toESM(require_main2(), 1);
55648
+ var AST3 = recast3.types.builders;
55649
+ function inputObject(config2, inputs) {
55650
+ const visitedTypes = /* @__PURE__ */ new Set();
55651
+ const inputObj = {
55652
+ fields: inputs.reduce((fields, input) => {
55653
+ const { type } = unwrapType(config2, input.type);
55654
+ return {
55655
+ ...fields,
55656
+ [input.variable.name.value]: type.name
55657
+ };
55658
+ }, {}),
55659
+ types: {}
55660
+ };
55661
+ for (const input of inputs) {
55662
+ walkInputs(config2, visitedTypes, inputObj, input.type);
55663
+ }
55664
+ return inputObj;
55665
+ }
55666
+ function walkInputs(config2, visitedTypes, inputObj, rootType) {
55667
+ const { type } = unwrapType(config2, rootType);
55668
+ if (visitedTypes.has(type.name)) {
55669
+ return;
55670
+ }
55671
+ if (graphql4.isEnumType(type) || graphql4.isScalarType(type)) {
55672
+ return;
55673
+ }
55674
+ if (graphql4.isUnionType(type)) {
55675
+ return;
55676
+ }
55677
+ visitedTypes.add(type.name);
55678
+ inputObj.types[type.name] = Object.values(type.getFields()).reduce(
55679
+ (typeFields, field) => {
55680
+ const { type: fieldType } = unwrapType(config2, field.type);
55681
+ walkInputs(config2, visitedTypes, inputObj, fieldType);
55682
+ return {
55683
+ ...typeFields,
55684
+ [field.name]: fieldType.toString()
55685
+ };
55686
+ },
55687
+ {}
55688
+ );
55689
+ }
55690
+
55691
+ // src/codegen/generators/artifacts/operations.ts
55692
+ var graphql6 = __toESM(require_graphql2(), 1);
55693
+
55694
+ // src/codegen/generators/artifacts/utils.ts
55695
+ var graphql5 = __toESM(require_graphql2(), 1);
55696
+ var recast4 = __toESM(require_main2(), 1);
55697
+ var AST4 = recast4.types.builders;
55698
+ function serializeValue(value) {
55699
+ if (Array.isArray(value)) {
55700
+ return AST4.arrayExpression(value.map(serializeValue));
55701
+ }
55702
+ if (typeof value === "object" && value !== null) {
55703
+ return AST4.objectExpression(
55704
+ Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
55705
+ ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
55706
+ )
55707
+ );
55708
+ }
55709
+ if (typeof value === "string") {
55710
+ if (value.indexOf("\n") !== -1) {
55711
+ return AST4.templateLiteral(
55712
+ [AST4.templateElement({ raw: value, cooked: value }, true)],
55713
+ []
55714
+ );
55715
+ }
55716
+ return AST4.stringLiteral(value);
55717
+ }
55718
+ return AST4.literal(value);
55719
+ }
55720
+ function deepMerge(filepath, ...targets) {
55721
+ if (typeof targets[0] !== "object") {
55722
+ const matches = targets.filter((val) => val !== targets[0]).length === 0;
55723
+ if (!matches) {
55724
+ throw new HoudiniError({ filepath, message: "could not merge: " + targets });
55725
+ }
55726
+ return targets[0];
55727
+ }
55728
+ if (Array.isArray(targets[0])) {
55729
+ return targets[0].concat(...targets.slice(1));
55730
+ }
55731
+ const fields = {};
55732
+ for (const target of targets) {
55733
+ for (const [key, value] of Object.entries(target)) {
55734
+ if (!fields[key]) {
55735
+ fields[key] = [];
55736
+ }
55737
+ fields[key].push(value);
55738
+ }
55739
+ }
55740
+ return Object.fromEntries(
55741
+ Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
55742
+ );
55743
+ }
55744
+ function convertValue(config2, val) {
55745
+ let value;
55746
+ let kind;
55747
+ if (val.kind === graphql5.Kind.INT) {
55748
+ value = parseInt(val.value, 10);
55749
+ kind = "Int";
55750
+ } else if (val.kind === graphql5.Kind.FLOAT) {
55751
+ value = parseFloat(val.value);
55752
+ kind = "Float";
55753
+ } else if (val.kind === graphql5.Kind.BOOLEAN) {
55754
+ value = val.value;
55755
+ kind = "Boolean";
55756
+ } else if (val.kind === graphql5.Kind.VARIABLE) {
55757
+ value = val.name.value;
55758
+ kind = "Variable";
55759
+ } else if (val.kind === graphql5.Kind.STRING) {
55760
+ value = val.value;
55761
+ kind = "String";
55762
+ }
55763
+ return { kind, value };
55764
+ }
55765
+
55766
+ // src/codegen/generators/artifacts/operations.ts
55767
+ function operationsByPath(config2, filepath, definition, filterTypes) {
55768
+ if (!definition) {
55769
+ return {};
55770
+ }
55771
+ const pathOperations = {};
55772
+ graphql6.visit(definition, {
55773
+ FragmentSpread(node, _, __, ___, ancestors) {
55774
+ if (!config2.isListFragment(node.name.value)) {
55775
+ return;
55776
+ }
55777
+ const path2 = ancestorKey(ancestors);
55778
+ if (!pathOperations[path2]) {
55779
+ pathOperations[path2] = [];
55780
+ }
55781
+ pathOperations[path2].push(
55782
+ operationObject({
55408
55783
  config: config2,
55409
55784
  filepath,
55410
55785
  listName: config2.listNameFromFragment(node.name.value),
@@ -55553,7 +55928,7 @@ function ancestorKey(ancestors) {
55553
55928
  }
55554
55929
 
55555
55930
  // src/codegen/generators/artifacts/selection.ts
55556
- var graphql10 = __toESM(require_graphql2(), 1);
55931
+ var graphql11 = __toESM(require_graphql2(), 1);
55557
55932
 
55558
55933
  // ../../node_modules/.pnpm/@kitql+helper@0.5.0/node_modules/@kitql/helper/index.mjs
55559
55934
  var config = {
@@ -55593,16 +55968,16 @@ function logYellow(str) {
55593
55968
  }
55594
55969
 
55595
55970
  // src/codegen/transforms/list.ts
55596
- var graphql8 = __toESM(require_graphql2(), 1);
55971
+ var graphql9 = __toESM(require_graphql2(), 1);
55597
55972
 
55598
55973
  // src/codegen/utils/objectIdentificationSelection.ts
55599
- var graphql6 = __toESM(require_graphql2(), 1);
55974
+ var graphql7 = __toESM(require_graphql2(), 1);
55600
55975
  var objectIdentificationSelection = (config2, type) => {
55601
55976
  return config2.keyFieldsForType(type.name).map((key) => {
55602
55977
  return {
55603
- kind: graphql6.Kind.FIELD,
55978
+ kind: graphql7.Kind.FIELD,
55604
55979
  name: {
55605
- kind: graphql6.Kind.NAME,
55980
+ kind: graphql7.Kind.NAME,
55606
55981
  value: key
55607
55982
  }
55608
55983
  };
@@ -55610,7 +55985,7 @@ var objectIdentificationSelection = (config2, type) => {
55610
55985
  };
55611
55986
 
55612
55987
  // src/codegen/transforms/paginate.ts
55613
- var graphql7 = __toESM(require_graphql2(), 1);
55988
+ var graphql8 = __toESM(require_graphql2(), 1);
55614
55989
  async function paginate(config2, documents) {
55615
55990
  const newDocs = [];
55616
55991
  for (const doc of documents) {
@@ -55643,7 +56018,7 @@ async function paginate(config2, documents) {
55643
56018
  };
55644
56019
  let cursorType = "String";
55645
56020
  let paginationPath = [];
55646
- doc.document = graphql7.visit(doc.document, {
56021
+ doc.document = graphql8.visit(doc.document, {
55647
56022
  Field(node, _, __, ___, ancestors) {
55648
56023
  const paginateDirective = node.directives?.find(
55649
56024
  (directive) => directive.name.value === config2.paginateDirective
@@ -55654,23 +56029,22 @@ async function paginate(config2, documents) {
55654
56029
  paginated = true;
55655
56030
  const fieldTypeFields = parentTypeFromAncestors(config2.schema, doc.filename, ancestors).getFields()[node.name.value];
55656
56031
  const args = new Set(fieldTypeFields.args.map((arg) => arg.name));
55657
- const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
55658
- const specifiedForwards = passedArgs.has("first");
55659
- const specifiedBackwards = passedArgs.has("last");
55660
56032
  cursorType = fieldTypeFields.args?.find((arg) => ["before", "after"].includes(arg.name))?.type?.name || "String";
55661
56033
  flags.after.type = cursorType;
55662
56034
  flags.before.type = cursorType;
55663
- const forwardPagination = !specifiedBackwards && args.has("first") && args.has("after");
55664
- const backwardsPagination = !specifiedForwards && args.has("last") && args.has("before");
55665
- const offsetPagination = !forwardPagination && !backwardsPagination && args.has("offset") && args.has("limit");
55666
- flags.first.enabled = forwardPagination;
55667
- flags.after.enabled = forwardPagination;
55668
- flags.last.enabled = backwardsPagination;
55669
- flags.before.enabled = backwardsPagination;
56035
+ const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
56036
+ const forwards = args.has("first") && args.has("after");
56037
+ const backwards = args.has("last") && args.has("after");
56038
+ const cursorPagination = passedArgs.has("last") || passedArgs.has("first");
56039
+ const offsetPagination = !cursorPagination && args.has("offset") && args.has("limit");
56040
+ flags.first.enabled = forwards;
56041
+ flags.after.enabled = forwards;
56042
+ flags.last.enabled = backwards;
56043
+ flags.before.enabled = backwards;
55670
56044
  flags.offset.enabled = offsetPagination;
55671
56045
  flags.limit.enabled = offsetPagination;
55672
56046
  paginationPath = ancestors.filter(
55673
- (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql7.Kind.FIELD
56047
+ (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql8.Kind.FIELD
55674
56048
  ).concat(node).map((field) => field.alias?.value || field.name.value);
55675
56049
  return {
55676
56050
  ...node,
@@ -55686,12 +56060,8 @@ async function paginate(config2, documents) {
55686
56060
  let fragmentName = "";
55687
56061
  let refetchQueryName = "";
55688
56062
  let nodeQuery = false;
55689
- let refetchUpdate = "append" /* append */;
55690
- if (flags.last.enabled) {
55691
- refetchUpdate = "prepend" /* prepend */;
55692
- }
55693
56063
  let fragment = "";
55694
- doc.document = graphql7.visit(doc.document, {
56064
+ doc.document = graphql8.visit(doc.document, {
55695
56065
  OperationDefinition(node) {
55696
56066
  if (node.operation !== "query") {
55697
56067
  throw new HoudiniError({
@@ -55745,9 +56115,9 @@ async function paginate(config2, documents) {
55745
56115
  directives: [
55746
56116
  ...node.directives || [],
55747
56117
  {
55748
- kind: graphql7.Kind.DIRECTIVE,
56118
+ kind: graphql8.Kind.DIRECTIVE,
55749
56119
  name: {
55750
- kind: graphql7.Kind.NAME,
56120
+ kind: graphql8.Kind.NAME,
55751
56121
  value: config2.argumentsDirective
55752
56122
  }
55753
56123
  }
@@ -55784,42 +56154,40 @@ async function paginate(config2, documents) {
55784
56154
  targetType = fragment;
55785
56155
  }
55786
56156
  }
56157
+ const pageSize = flags.first.defaultValue ?? flags.last.defaultValue ?? flags.limit.defaultValue;
56158
+ const start = flags.after.defaultValue ?? flags.before.defaultValue ?? flags.offset.defaultValue;
56159
+ let direction = "forward";
56160
+ if (flags.before.enabled && flags.after.enabled) {
56161
+ direction = "both";
56162
+ } else if (flags.before.enabled) {
56163
+ direction = "backward";
56164
+ }
55787
56165
  doc.refetch = {
55788
- update: refetchUpdate,
55789
56166
  path: paginationPath,
55790
56167
  method: flags.first.enabled || flags.last.enabled ? "cursor" : "offset",
55791
- pageSize: 0,
56168
+ pageSize,
55792
56169
  embedded: nodeQuery,
55793
56170
  targetType,
55794
56171
  paginated: true,
55795
- direction: flags.last.enabled ? "backwards" : "forward"
55796
- };
55797
- if (flags.first.enabled) {
55798
- doc.refetch.pageSize = flags.first.defaultValue;
55799
- doc.refetch.start = flags.after.defaultValue;
55800
- } else if (flags.last.enabled) {
55801
- doc.refetch.pageSize = flags.last.defaultValue;
55802
- doc.refetch.start = flags.before.defaultValue;
55803
- } else if (flags.limit.enabled) {
55804
- doc.refetch.pageSize = flags.limit.defaultValue;
55805
- doc.refetch.start = flags.offset.defaultValue;
55806
- }
56172
+ direction,
56173
+ start
56174
+ };
55807
56175
  if (!fragment) {
55808
56176
  continue;
55809
56177
  }
55810
56178
  const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
55811
56179
  const fragmentSpreadSelection = [
55812
56180
  {
55813
- kind: graphql7.Kind.FRAGMENT_SPREAD,
56181
+ kind: graphql8.Kind.FRAGMENT_SPREAD,
55814
56182
  name: {
55815
- kind: graphql7.Kind.NAME,
56183
+ kind: graphql8.Kind.NAME,
55816
56184
  value: fragmentName
55817
56185
  },
55818
56186
  directives: [
55819
56187
  {
55820
- kind: graphql7.Kind.DIRECTIVE,
56188
+ kind: graphql8.Kind.DIRECTIVE,
55821
56189
  name: {
55822
- kind: graphql7.Kind.NAME,
56190
+ kind: graphql8.Kind.NAME,
55823
56191
  value: config2.withDirective
55824
56192
  },
55825
56193
  ["arguments"]: paginationArgs.map(
@@ -55847,29 +56215,29 @@ async function paginate(config2, documents) {
55847
56215
  });
55848
56216
  const typeConfig = config2.typeConfig?.[fragment];
55849
56217
  const queryDoc = {
55850
- kind: graphql7.Kind.DOCUMENT,
56218
+ kind: graphql8.Kind.DOCUMENT,
55851
56219
  definitions: [
55852
56220
  {
55853
- kind: graphql7.Kind.OPERATION_DEFINITION,
56221
+ kind: graphql8.Kind.OPERATION_DEFINITION,
55854
56222
  name: {
55855
- kind: graphql7.Kind.NAME,
56223
+ kind: graphql8.Kind.NAME,
55856
56224
  value: refetchQueryName
55857
56225
  },
55858
56226
  operation: "query",
55859
56227
  variableDefinitions: paginationArgs.map(
55860
56228
  (arg) => ({
55861
- kind: graphql7.Kind.VARIABLE_DEFINITION,
56229
+ kind: graphql8.Kind.VARIABLE_DEFINITION,
55862
56230
  type: {
55863
- kind: graphql7.Kind.NAMED_TYPE,
56231
+ kind: graphql8.Kind.NAMED_TYPE,
55864
56232
  name: {
55865
- kind: graphql7.Kind.NAME,
56233
+ kind: graphql8.Kind.NAME,
55866
56234
  value: arg.type
55867
56235
  }
55868
56236
  },
55869
56237
  variable: {
55870
- kind: graphql7.Kind.VARIABLE,
56238
+ kind: graphql8.Kind.VARIABLE,
55871
56239
  name: {
55872
- kind: graphql7.Kind.NAME,
56240
+ kind: graphql8.Kind.NAME,
55873
56241
  value: arg.name
55874
56242
  }
55875
56243
  },
@@ -55881,12 +56249,12 @@ async function paginate(config2, documents) {
55881
56249
  ).concat(
55882
56250
  !nodeQuery ? [] : keys.map(
55883
56251
  (key) => ({
55884
- kind: graphql7.Kind.VARIABLE_DEFINITION,
56252
+ kind: graphql8.Kind.VARIABLE_DEFINITION,
55885
56253
  type: key.type,
55886
56254
  variable: {
55887
- kind: graphql7.Kind.VARIABLE,
56255
+ kind: graphql8.Kind.VARIABLE,
55888
56256
  name: {
55889
- kind: graphql7.Kind.NAME,
56257
+ kind: graphql8.Kind.NAME,
55890
56258
  value: key.name
55891
56259
  }
55892
56260
  }
@@ -55894,42 +56262,42 @@ async function paginate(config2, documents) {
55894
56262
  )
55895
56263
  ),
55896
56264
  selectionSet: {
55897
- kind: graphql7.Kind.SELECTION_SET,
56265
+ kind: graphql8.Kind.SELECTION_SET,
55898
56266
  selections: !nodeQuery ? fragmentSpreadSelection : [
55899
56267
  {
55900
- kind: graphql7.Kind.FIELD,
56268
+ kind: graphql8.Kind.FIELD,
55901
56269
  name: {
55902
- kind: graphql7.Kind.NAME,
56270
+ kind: graphql8.Kind.NAME,
55903
56271
  value: typeConfig?.resolve?.queryField || "node"
55904
56272
  },
55905
56273
  ["arguments"]: keys.map((key) => ({
55906
- kind: graphql7.Kind.ARGUMENT,
56274
+ kind: graphql8.Kind.ARGUMENT,
55907
56275
  name: {
55908
- kind: graphql7.Kind.NAME,
56276
+ kind: graphql8.Kind.NAME,
55909
56277
  value: key.name
55910
56278
  },
55911
56279
  value: {
55912
- kind: graphql7.Kind.VARIABLE,
56280
+ kind: graphql8.Kind.VARIABLE,
55913
56281
  name: {
55914
- kind: graphql7.Kind.NAME,
56282
+ kind: graphql8.Kind.NAME,
55915
56283
  value: key.name
55916
56284
  }
55917
56285
  }
55918
56286
  })),
55919
56287
  selectionSet: {
55920
- kind: graphql7.Kind.SELECTION_SET,
56288
+ kind: graphql8.Kind.SELECTION_SET,
55921
56289
  selections: [
55922
56290
  {
55923
- kind: graphql7.Kind.FIELD,
56291
+ kind: graphql8.Kind.FIELD,
55924
56292
  name: {
55925
- kind: graphql7.Kind.NAME,
56293
+ kind: graphql8.Kind.NAME,
55926
56294
  value: "__typename"
55927
56295
  }
55928
56296
  },
55929
56297
  ...(typeConfig?.keys || ["id"]).map((key) => ({
55930
- kind: graphql7.Kind.FIELD,
56298
+ kind: graphql8.Kind.FIELD,
55931
56299
  name: {
55932
- kind: graphql7.Kind.NAME,
56300
+ kind: graphql8.Kind.NAME,
55933
56301
  value: key
55934
56302
  }
55935
56303
  })),
@@ -55979,27 +56347,21 @@ function replaceArgumentsWithVariables(args, flags) {
55979
56347
  if (flags[name2].defaultValue || !spec.enabled || seenArgs[name2]) {
55980
56348
  continue;
55981
56349
  }
55982
- if (["first", "after"].includes(name2) && flags["before"].enabled) {
55983
- continue;
55984
- }
55985
- if (["last", "before"].includes(name2) && flags["first"].enabled) {
55986
- continue;
55987
- }
55988
56350
  newArgs.push(variableAsArgument(name2));
55989
56351
  }
55990
56352
  return newArgs;
55991
56353
  }
55992
56354
  function variableAsArgument(name2, variable) {
55993
56355
  return {
55994
- kind: graphql7.Kind.ARGUMENT,
56356
+ kind: graphql8.Kind.ARGUMENT,
55995
56357
  name: {
55996
- kind: graphql7.Kind.NAME,
56358
+ kind: graphql8.Kind.NAME,
55997
56359
  value: name2
55998
56360
  },
55999
56361
  value: {
56000
- kind: graphql7.Kind.VARIABLE,
56362
+ kind: graphql8.Kind.VARIABLE,
56001
56363
  name: {
56002
- kind: graphql7.Kind.NAME,
56364
+ kind: graphql8.Kind.NAME,
56003
56365
  value: variable ?? name2
56004
56366
  }
56005
56367
  }
@@ -56007,18 +56369,18 @@ function variableAsArgument(name2, variable) {
56007
56369
  }
56008
56370
  function staticVariableDefinition(name2, type, defaultValue, variableName) {
56009
56371
  return {
56010
- kind: graphql7.Kind.VARIABLE_DEFINITION,
56372
+ kind: graphql8.Kind.VARIABLE_DEFINITION,
56011
56373
  type: {
56012
- kind: graphql7.Kind.NAMED_TYPE,
56374
+ kind: graphql8.Kind.NAMED_TYPE,
56013
56375
  name: {
56014
- kind: graphql7.Kind.NAME,
56376
+ kind: graphql8.Kind.NAME,
56015
56377
  value: type
56016
56378
  }
56017
56379
  },
56018
56380
  variable: {
56019
- kind: graphql7.Kind.VARIABLE,
56381
+ kind: graphql8.Kind.VARIABLE,
56020
56382
  name: {
56021
- kind: graphql7.Kind.NAME,
56383
+ kind: graphql8.Kind.NAME,
56022
56384
  value: variableName ?? name2
56023
56385
  }
56024
56386
  },
@@ -56030,9 +56392,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
56030
56392
  }
56031
56393
  function argumentNode(name2, value) {
56032
56394
  return {
56033
- kind: graphql7.Kind.ARGUMENT,
56395
+ kind: graphql8.Kind.ARGUMENT,
56034
56396
  name: {
56035
- kind: graphql7.Kind.NAME,
56397
+ kind: graphql8.Kind.NAME,
56036
56398
  value: name2
56037
56399
  },
56038
56400
  value: objectNode(value)
@@ -56040,16 +56402,16 @@ function argumentNode(name2, value) {
56040
56402
  }
56041
56403
  function objectNode([type, defaultValue]) {
56042
56404
  const node = {
56043
- kind: graphql7.Kind.OBJECT,
56405
+ kind: graphql8.Kind.OBJECT,
56044
56406
  fields: [
56045
56407
  {
56046
- kind: graphql7.Kind.OBJECT_FIELD,
56408
+ kind: graphql8.Kind.OBJECT_FIELD,
56047
56409
  name: {
56048
- kind: graphql7.Kind.NAME,
56410
+ kind: graphql8.Kind.NAME,
56049
56411
  value: "type"
56050
56412
  },
56051
56413
  value: {
56052
- kind: graphql7.Kind.STRING,
56414
+ kind: graphql8.Kind.STRING,
56053
56415
  value: type
56054
56416
  }
56055
56417
  }
@@ -56057,8 +56419,8 @@ function objectNode([type, defaultValue]) {
56057
56419
  };
56058
56420
  if (defaultValue) {
56059
56421
  node.fields.push({
56060
- kind: graphql7.Kind.OBJECT_FIELD,
56061
- name: { kind: graphql7.Kind.NAME, value: "default" },
56422
+ kind: graphql8.Kind.OBJECT_FIELD,
56423
+ name: { kind: graphql8.Kind.NAME, value: "default" },
56062
56424
  value: {
56063
56425
  kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
56064
56426
  value: defaultValue.toString()
@@ -56069,34 +56431,34 @@ function objectNode([type, defaultValue]) {
56069
56431
  }
56070
56432
  var pageInfoSelection = [
56071
56433
  {
56072
- kind: graphql7.Kind.FIELD,
56434
+ kind: graphql8.Kind.FIELD,
56073
56435
  name: {
56074
- kind: graphql7.Kind.NAME,
56436
+ kind: graphql8.Kind.NAME,
56075
56437
  value: "edges"
56076
56438
  },
56077
56439
  selectionSet: {
56078
- kind: graphql7.Kind.SELECTION_SET,
56440
+ kind: graphql8.Kind.SELECTION_SET,
56079
56441
  selections: [
56080
56442
  {
56081
- kind: graphql7.Kind.FIELD,
56443
+ kind: graphql8.Kind.FIELD,
56082
56444
  name: {
56083
- kind: graphql7.Kind.NAME,
56445
+ kind: graphql8.Kind.NAME,
56084
56446
  value: "cursor"
56085
56447
  }
56086
56448
  },
56087
56449
  {
56088
- kind: graphql7.Kind.FIELD,
56450
+ kind: graphql8.Kind.FIELD,
56089
56451
  name: {
56090
- kind: graphql7.Kind.NAME,
56452
+ kind: graphql8.Kind.NAME,
56091
56453
  value: "node"
56092
56454
  },
56093
56455
  selectionSet: {
56094
- kind: graphql7.Kind.SELECTION_SET,
56456
+ kind: graphql8.Kind.SELECTION_SET,
56095
56457
  selections: [
56096
56458
  {
56097
- kind: graphql7.Kind.FIELD,
56459
+ kind: graphql8.Kind.FIELD,
56098
56460
  name: {
56099
- kind: graphql7.Kind.NAME,
56461
+ kind: graphql8.Kind.NAME,
56100
56462
  value: "__typename"
56101
56463
  }
56102
56464
  }
@@ -56107,39 +56469,39 @@ var pageInfoSelection = [
56107
56469
  }
56108
56470
  },
56109
56471
  {
56110
- kind: graphql7.Kind.FIELD,
56472
+ kind: graphql8.Kind.FIELD,
56111
56473
  name: {
56112
- kind: graphql7.Kind.NAME,
56474
+ kind: graphql8.Kind.NAME,
56113
56475
  value: "pageInfo"
56114
56476
  },
56115
56477
  selectionSet: {
56116
- kind: graphql7.Kind.SELECTION_SET,
56478
+ kind: graphql8.Kind.SELECTION_SET,
56117
56479
  selections: [
56118
56480
  {
56119
- kind: graphql7.Kind.FIELD,
56481
+ kind: graphql8.Kind.FIELD,
56120
56482
  name: {
56121
- kind: graphql7.Kind.NAME,
56483
+ kind: graphql8.Kind.NAME,
56122
56484
  value: "hasPreviousPage"
56123
56485
  }
56124
56486
  },
56125
56487
  {
56126
- kind: graphql7.Kind.FIELD,
56488
+ kind: graphql8.Kind.FIELD,
56127
56489
  name: {
56128
- kind: graphql7.Kind.NAME,
56490
+ kind: graphql8.Kind.NAME,
56129
56491
  value: "hasNextPage"
56130
56492
  }
56131
56493
  },
56132
56494
  {
56133
- kind: graphql7.Kind.FIELD,
56495
+ kind: graphql8.Kind.FIELD,
56134
56496
  name: {
56135
- kind: graphql7.Kind.NAME,
56497
+ kind: graphql8.Kind.NAME,
56136
56498
  value: "startCursor"
56137
56499
  }
56138
56500
  },
56139
56501
  {
56140
- kind: graphql7.Kind.FIELD,
56502
+ kind: graphql8.Kind.FIELD,
56141
56503
  name: {
56142
- kind: graphql7.Kind.NAME,
56504
+ kind: graphql8.Kind.NAME,
56143
56505
  value: "endCursor"
56144
56506
  }
56145
56507
  }
@@ -56153,15 +56515,15 @@ async function addListFragments(config2, documents) {
56153
56515
  const lists = {};
56154
56516
  const errors = [];
56155
56517
  for (const doc of documents) {
56156
- doc.document = graphql8.visit(doc.document, {
56518
+ doc.document = graphql9.visit(doc.document, {
56157
56519
  Directive(node, key, parent, path2, ancestors) {
56158
56520
  if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
56159
56521
  const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
56160
56522
  let error = {
56161
- ...new graphql8.GraphQLError(
56523
+ ...new graphql9.GraphQLError(
56162
56524
  "",
56163
56525
  node,
56164
- new graphql8.Source(""),
56526
+ new graphql9.Source(""),
56165
56527
  node.loc ? [node.loc.start, node.loc.end] : null,
56166
56528
  path2
56167
56529
  ),
@@ -56213,7 +56575,7 @@ async function addListFragments(config2, documents) {
56213
56575
  {
56214
56576
  kind: "Argument",
56215
56577
  name: {
56216
- kind: graphql8.Kind.NAME,
56578
+ kind: graphql9.Kind.NAME,
56217
56579
  value: "connection"
56218
56580
  },
56219
56581
  value: {
@@ -56263,7 +56625,7 @@ async function addListFragments(config2, documents) {
56263
56625
  const validDeletes = [
56264
56626
  ...new Set(
56265
56627
  Object.values(lists).map(({ type }) => {
56266
- if (!(type instanceof graphql8.GraphQLObjectType)) {
56628
+ if (!(type instanceof graphql9.GraphQLObjectType)) {
56267
56629
  return "";
56268
56630
  }
56269
56631
  if (config2.keyFieldsForType(type.name).length !== 1) {
@@ -56277,7 +56639,7 @@ async function addListFragments(config2, documents) {
56277
56639
  return;
56278
56640
  }
56279
56641
  const generatedDoc = {
56280
- kind: graphql8.Kind.DOCUMENT,
56642
+ kind: graphql9.Kind.DOCUMENT,
56281
56643
  definitions: Object.entries(lists).flatMap(
56282
56644
  ([name2, { selection: selection2, type }]) => {
56283
56645
  const schemaType = config2.schema.getType(type.name);
@@ -56285,7 +56647,7 @@ async function addListFragments(config2, documents) {
56285
56647
  throw new HoudiniError({ message: "Lists must have a selection" });
56286
56648
  }
56287
56649
  const fragmentSelection = {
56288
- kind: graphql8.Kind.SELECTION_SET,
56650
+ kind: graphql9.Kind.SELECTION_SET,
56289
56651
  selections: [...selection2.selections]
56290
56652
  };
56291
56653
  if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
@@ -56300,14 +56662,14 @@ async function addListFragments(config2, documents) {
56300
56662
  {
56301
56663
  name: {
56302
56664
  value: config2.listInsertFragment(name2),
56303
- kind: graphql8.Kind.NAME
56665
+ kind: graphql9.Kind.NAME
56304
56666
  },
56305
- kind: graphql8.Kind.FRAGMENT_DEFINITION,
56667
+ kind: graphql9.Kind.FRAGMENT_DEFINITION,
56306
56668
  selectionSet: fragmentSelection,
56307
56669
  typeCondition: {
56308
- kind: graphql8.Kind.NAMED_TYPE,
56670
+ kind: graphql9.Kind.NAMED_TYPE,
56309
56671
  name: {
56310
- kind: graphql8.Kind.NAME,
56672
+ kind: graphql9.Kind.NAME,
56311
56673
  value: type.name
56312
56674
  }
56313
56675
  }
@@ -56315,32 +56677,32 @@ async function addListFragments(config2, documents) {
56315
56677
  {
56316
56678
  name: {
56317
56679
  value: config2.listToggleFragment(name2),
56318
- kind: graphql8.Kind.NAME
56680
+ kind: graphql9.Kind.NAME
56319
56681
  },
56320
- kind: graphql8.Kind.FRAGMENT_DEFINITION,
56682
+ kind: graphql9.Kind.FRAGMENT_DEFINITION,
56321
56683
  selectionSet: fragmentSelection,
56322
56684
  typeCondition: {
56323
- kind: graphql8.Kind.NAMED_TYPE,
56685
+ kind: graphql9.Kind.NAMED_TYPE,
56324
56686
  name: {
56325
- kind: graphql8.Kind.NAME,
56687
+ kind: graphql9.Kind.NAME,
56326
56688
  value: type.name
56327
56689
  }
56328
56690
  }
56329
56691
  },
56330
56692
  {
56331
- kind: graphql8.Kind.FRAGMENT_DEFINITION,
56693
+ kind: graphql9.Kind.FRAGMENT_DEFINITION,
56332
56694
  name: {
56333
56695
  value: config2.listRemoveFragment(name2),
56334
- kind: graphql8.Kind.NAME
56696
+ kind: graphql9.Kind.NAME
56335
56697
  },
56336
56698
  selectionSet: {
56337
- kind: graphql8.Kind.SELECTION_SET,
56699
+ kind: graphql9.Kind.SELECTION_SET,
56338
56700
  selections: [...objectIdentificationSelection(config2, type)]
56339
56701
  },
56340
56702
  typeCondition: {
56341
- kind: graphql8.Kind.NAMED_TYPE,
56703
+ kind: graphql9.Kind.NAMED_TYPE,
56342
56704
  name: {
56343
- kind: graphql8.Kind.NAME,
56705
+ kind: graphql9.Kind.NAME,
56344
56706
  value: type.name
56345
56707
  }
56346
56708
  }
@@ -56349,14 +56711,14 @@ async function addListFragments(config2, documents) {
56349
56711
  }
56350
56712
  ).concat(
56351
56713
  ...validDeletes.map((typeName) => ({
56352
- kind: graphql8.Kind.DIRECTIVE_DEFINITION,
56714
+ kind: graphql9.Kind.DIRECTIVE_DEFINITION,
56353
56715
  name: {
56354
- kind: graphql8.Kind.NAME,
56716
+ kind: graphql9.Kind.NAME,
56355
56717
  value: config2.listDeleteDirective(typeName)
56356
56718
  },
56357
56719
  locations: [
56358
56720
  {
56359
- kind: graphql8.Kind.NAME,
56721
+ kind: graphql9.Kind.NAME,
56360
56722
  value: "FIELD"
56361
56723
  }
56362
56724
  ],
@@ -56364,8 +56726,8 @@ async function addListFragments(config2, documents) {
56364
56726
  }))
56365
56727
  )
56366
56728
  };
56367
- config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql8.print).join("\n\n");
56368
- config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql8.print).join("\n\n");
56729
+ config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql9.print).join("\n\n");
56730
+ config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql9.print).join("\n\n");
56369
56731
  documents.push({
56370
56732
  name: "generated::lists",
56371
56733
  kind: "HoudiniFragment" /* Fragment */,
@@ -56450,11 +56812,11 @@ var nodeNotDefinedMessage = (config2) => `Looks like you are trying to use the $
56450
56812
  For more information, visit this link: ${siteURL}/guides/pagination`;
56451
56813
 
56452
56814
  // src/codegen/generators/artifacts/fieldKey.ts
56453
- var graphql9 = __toESM(require_graphql2(), 1);
56815
+ var graphql10 = __toESM(require_graphql2(), 1);
56454
56816
  function fieldKey(config2, field) {
56455
56817
  const attributeName = field.alias?.value || field.name.value;
56456
- const printed = graphql9.print(field);
56457
- const secondParse = graphql9.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
56818
+ const printed = graphql10.print(field);
56819
+ const secondParse = graphql10.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
56458
56820
  const paginated = !!field.directives?.find(
56459
56821
  (directive) => directive.name.value === config2.paginateDirective
56460
56822
  );
@@ -56492,7 +56854,7 @@ function selection({
56492
56854
  path: path2 = [],
56493
56855
  includeFragments,
56494
56856
  document,
56495
- markEdges
56857
+ inConnection
56496
56858
  }) {
56497
56859
  let object = {};
56498
56860
  const typeMap = {};
@@ -56549,8 +56911,8 @@ function selection({
56549
56911
  const typeConditionName = field.typeCondition.name.value;
56550
56912
  const typeCondition = config2.schema.getType(typeConditionName);
56551
56913
  const possibleTypes = [];
56552
- if (!graphql10.isAbstractType(typeCondition)) {
56553
- } else if (graphql10.isAbstractType(parentType)) {
56914
+ if (!graphql11.isAbstractType(typeCondition)) {
56915
+ } else if (graphql11.isAbstractType(parentType)) {
56554
56916
  const possibleParentTypes = config2.schema.getPossibleTypes(parentType).map((type) => type.name);
56555
56917
  for (const possible of config2.schema.getPossibleTypes(typeCondition)) {
56556
56918
  if (possibleParentTypes.includes(possible.name)) {
@@ -56598,7 +56960,7 @@ function selection({
56598
56960
  } else {
56599
56961
  let typeRef = type.getFields()[field.name.value].type;
56600
56962
  fieldType = getRootType(typeRef);
56601
- nullable = !graphql10.isNonNullType(typeRef);
56963
+ nullable = !graphql11.isNonNullType(typeRef);
56602
56964
  }
56603
56965
  const typeName = fieldType.toString();
56604
56966
  const pathSoFar = path2.concat(attributeName);
@@ -56634,14 +56996,23 @@ function selection({
56634
56996
  (directive) => directive.name.value === config2.paginateDirective
56635
56997
  );
56636
56998
  if (paginated && document.refetch && document.refetch.method === "offset") {
56637
- fieldObj.update = document.refetch.update;
56999
+ fieldObj.updates = ["append" /* append */];
56638
57000
  }
56639
- if (attributeName === "edges" && markEdges && document.refetch) {
56640
- fieldObj.update = document.refetch.update;
56641
- markEdges = "";
57001
+ let continueConnection = inConnection;
57002
+ if ([
57003
+ "edges",
57004
+ "endCursor",
57005
+ "startCursor",
57006
+ "hasNextPage",
57007
+ "hasPreviousPage"
57008
+ ].includes(attributeName) && inConnection && document.refetch) {
57009
+ fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
57010
+ }
57011
+ if (attributeName === "node" && inConnection) {
57012
+ continueConnection = false;
56642
57013
  }
56643
57014
  if (field.selectionSet) {
56644
- const edgesMark = paginated && document.refetch?.method === "cursor" ? document.refetch.update : markEdges;
57015
+ const connectionState = paginated && document.refetch?.method === "cursor" || continueConnection;
56645
57016
  fieldObj.selection = selection({
56646
57017
  config: config2,
56647
57018
  filepath,
@@ -56651,7 +57022,7 @@ function selection({
56651
57022
  path: pathSoFar,
56652
57023
  includeFragments,
56653
57024
  document,
56654
- markEdges: edgesMark
57025
+ inConnection: connectionState
56655
57026
  });
56656
57027
  }
56657
57028
  if (field.arguments?.length && fieldObj.list) {
@@ -56663,7 +57034,7 @@ function selection({
56663
57034
  {}
56664
57035
  );
56665
57036
  }
56666
- if (graphql10.isInterfaceType(fieldType) || graphql10.isUnionType(fieldType)) {
57037
+ if (graphql11.isInterfaceType(fieldType) || graphql11.isUnionType(fieldType)) {
56667
57038
  fieldObj.abstract = true;
56668
57039
  }
56669
57040
  object.fields = {
@@ -56720,7 +57091,7 @@ function artifactGenerator(stats) {
56720
57091
  return async function(config2, docs) {
56721
57092
  const filterTypes = {};
56722
57093
  for (const doc of docs) {
56723
- graphql11.visit(doc.document, {
57094
+ graphql12.visit(doc.document, {
56724
57095
  Directive(node, _, __, ___, ancestors) {
56725
57096
  if (node.name.value !== config2.listDirective) {
56726
57097
  return;
@@ -56779,7 +57150,7 @@ function artifactGenerator(stats) {
56779
57150
  return;
56780
57151
  }
56781
57152
  const usedVariableNames = /* @__PURE__ */ new Set();
56782
- let documentWithoutInternalDirectives = graphql11.visit(document, {
57153
+ let documentWithoutInternalDirectives = graphql12.visit(document, {
56783
57154
  Directive(node) {
56784
57155
  if (config2.isInternalDirective(node)) {
56785
57156
  return null;
@@ -56792,7 +57163,7 @@ function artifactGenerator(stats) {
56792
57163
  }
56793
57164
  }
56794
57165
  });
56795
- let documentWithoutExtraVariables = graphql11.visit(
57166
+ let documentWithoutExtraVariables = graphql12.visit(
56796
57167
  documentWithoutInternalDirectives,
56797
57168
  {
56798
57169
  VariableDefinition(variableDefinitionNode) {
@@ -56803,13 +57174,13 @@ function artifactGenerator(stats) {
56803
57174
  }
56804
57175
  }
56805
57176
  );
56806
- let rawString = graphql11.print(documentWithoutExtraVariables);
57177
+ let rawString = graphql12.print(documentWithoutExtraVariables);
56807
57178
  let docKind = doc.kind;
56808
57179
  const operations = document.definitions.filter(
56809
- ({ kind }) => kind === graphql11.Kind.OPERATION_DEFINITION
57180
+ ({ kind }) => kind === graphql12.Kind.OPERATION_DEFINITION
56810
57181
  );
56811
57182
  const fragments = document.definitions.filter(
56812
- ({ kind }) => kind === graphql11.Kind.FRAGMENT_DEFINITION
57183
+ ({ kind }) => kind === graphql12.Kind.FRAGMENT_DEFINITION
56813
57184
  );
56814
57185
  let rootType = "";
56815
57186
  let selectionSet;
@@ -56842,7 +57213,13 @@ function artifactGenerator(stats) {
56842
57213
  rootType = matchingFragment.typeCondition.name.value;
56843
57214
  selectionSet = matchingFragment.selectionSet;
56844
57215
  }
56845
- const inputs = operations[0]?.variableDefinitions;
57216
+ let inputs = operations[0]?.variableDefinitions;
57217
+ let directive = fragments[0]?.directives?.find(
57218
+ (directive2) => directive2.name.value === config2.argumentsDirective
57219
+ );
57220
+ if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
57221
+ inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
57222
+ }
56846
57223
  const mergedSelection = flattenSelections({
56847
57224
  config: config2,
56848
57225
  filepath: doc.filename,
@@ -56903,7 +57280,7 @@ function artifactGenerator(stats) {
56903
57280
  }
56904
57281
  if (docKind === "HoudiniQuery") {
56905
57282
  const cacheDirective = operations[0].directives?.find(
56906
- (directive) => directive.name.value === config2.cacheDirective
57283
+ (directive2) => directive2.name.value === config2.cacheDirective
56907
57284
  );
56908
57285
  if (cacheDirective) {
56909
57286
  const args = cacheDirective.arguments?.reduce(
@@ -57119,19 +57496,19 @@ async function generatePluginRuntime(config2, plugin) {
57119
57496
  );
57120
57497
  }
57121
57498
 
57122
- // src/codegen/generators/typescript/index.ts
57123
- var recast12 = __toESM(require_main2(), 1);
57499
+ // src/codegen/generators/typescript/documentTypes.ts
57500
+ var recast11 = __toESM(require_main2(), 1);
57124
57501
 
57125
57502
  // src/codegen/generators/typescript/addReferencedInputTypes.ts
57126
- var graphql14 = __toESM(require_graphql2(), 1);
57503
+ var graphql15 = __toESM(require_graphql2(), 1);
57127
57504
  var recast9 = __toESM(require_main2(), 1);
57128
57505
 
57129
57506
  // src/codegen/generators/typescript/typeReference.ts
57130
- var graphql13 = __toESM(require_graphql2(), 1);
57507
+ var graphql14 = __toESM(require_graphql2(), 1);
57131
57508
  var recast8 = __toESM(require_main2(), 1);
57132
57509
 
57133
57510
  // src/codegen/generators/typescript/types.ts
57134
- var graphql12 = __toESM(require_graphql2(), 1);
57511
+ var graphql13 = __toESM(require_graphql2(), 1);
57135
57512
  var recast7 = __toESM(require_main2(), 1);
57136
57513
  var AST7 = recast7.types.builders;
57137
57514
  function readonlyProperty(prop, enable = true) {
@@ -57162,336 +57539,89 @@ function scalarPropertyValue(config2, missingScalars, target) {
57162
57539
  return AST7.tsBooleanKeyword();
57163
57540
  }
57164
57541
  case "ID": {
57165
- return AST7.tsStringKeyword();
57166
- }
57167
- default: {
57168
- if (graphql12.isNonNullType(target) && "ofType" in target) {
57169
- return scalarPropertyValue(
57170
- config2,
57171
- missingScalars,
57172
- target.ofType
57173
- );
57174
- }
57175
- if (config2.scalars?.[target.name]) {
57176
- return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
57177
- }
57178
- missingScalars.add(target.name);
57179
- return AST7.tsAnyKeyword();
57180
- }
57181
- }
57182
- }
57183
-
57184
- // src/codegen/generators/typescript/typeReference.ts
57185
- var AST8 = recast8.types.builders;
57186
- function tsTypeReference(config2, missingScalars, definition) {
57187
- const { type, wrappers } = unwrapType(config2, definition.type);
57188
- let result;
57189
- if (graphql13.isScalarType(type)) {
57190
- result = scalarPropertyValue(config2, missingScalars, type);
57191
- } else {
57192
- result = AST8.tsTypeReference(AST8.identifier(type.name));
57193
- }
57194
- for (const toWrap of wrappers) {
57195
- if (toWrap === "NonNull" /* NonNull */) {
57196
- continue;
57197
- } else if (toWrap === "Nullable" /* Nullable */) {
57198
- result = nullableField(result, true);
57199
- } else if (toWrap === "List" /* List */) {
57200
- result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
57201
- }
57202
- }
57203
- return result;
57204
- }
57205
-
57206
- // src/codegen/generators/typescript/addReferencedInputTypes.ts
57207
- var AST9 = recast9.types.builders;
57208
- function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
57209
- const { type } = unwrapType(config2, rootType);
57210
- if (graphql14.isScalarType(type)) {
57211
- return;
57212
- }
57213
- if (visitedTypes.has(type.name)) {
57214
- return;
57215
- }
57216
- if (graphql14.isUnionType(type)) {
57217
- throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
57218
- }
57219
- visitedTypes.add(type.name);
57220
- if (graphql14.isEnumType(type)) {
57221
- ensureImports({
57222
- config: config2,
57223
- body,
57224
- import: [type.name],
57225
- sourceModule: "$houdini/graphql/enums",
57226
- importKind: "type"
57227
- });
57228
- return;
57229
- }
57230
- const members = [];
57231
- for (const field of Object.values(type.getFields())) {
57232
- addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
57233
- members.push(
57234
- AST9.tsPropertySignature(
57235
- AST9.identifier(field.name),
57236
- AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
57237
- graphql14.isNullableType(field.type)
57238
- )
57239
- );
57240
- }
57241
- body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
57242
- }
57243
-
57244
- // src/codegen/generators/typescript/imperativeCache.ts
57245
- var graphql15 = __toESM(require_graphql2(), 1);
57246
- var recast10 = __toESM(require_main2(), 1);
57247
- var AST10 = recast10.types.builders;
57248
- async function imperativeCacheTypef(config2, docs) {
57249
- const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
57250
- const body = [];
57251
- const declaration = AST10.tsTypeAliasDeclaration(
57252
- AST10.identifier(CacheTypeDefName),
57253
- AST10.tsTypeLiteral([
57254
- AST10.tsPropertySignature(
57255
- AST10.identifier("types"),
57256
- AST10.tsTypeAnnotation(typeDefinitions(config2, body))
57257
- ),
57258
- AST10.tsPropertySignature(
57259
- AST10.identifier("lists"),
57260
- AST10.tsTypeAnnotation(listDefinitions(config2, docs))
57261
- )
57262
- ])
57263
- );
57264
- declaration.declare = true;
57265
- const importRecord = AST10.importDeclaration(
57266
- [AST10.importSpecifier(AST10.identifier("Record"))],
57267
- AST10.stringLiteral("./public/record")
57268
- );
57269
- importRecord.importKind = "type";
57270
- await fs_exports.writeFile(
57271
- target,
57272
- recast10.prettyPrint(
57273
- AST10.program([importRecord, ...body, AST10.exportNamedDeclaration(declaration)])
57274
- ).code
57275
- );
57276
- }
57277
- function typeDefinitions(config2, body) {
57278
- const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
57279
- const visitedTypes = /* @__PURE__ */ new Set();
57280
- const types14 = Object.values(config2.schema.getTypeMap()).filter(
57281
- (type) => !graphql15.isAbstractType(type) && !graphql15.isScalarType(type) && !graphql15.isEnumType(type) && !graphql15.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
57282
- );
57283
- return AST10.tsTypeLiteral(
57284
- types14.map((type) => {
57285
- let typeName = type.name;
57286
- if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
57287
- typeName = "__ROOT__";
57288
- }
57289
- let idFields = AST10.tsNeverKeyword();
57290
- const keys = keyFieldsForType(config2.configFile, type.name);
57291
- if (graphql15.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
57292
- idFields = AST10.tsTypeLiteral(
57293
- keys.map((key) => {
57294
- const fieldType = type.getFields()[key];
57295
- const unwrapped = unwrapType(config2, fieldType.type);
57296
- return AST10.tsPropertySignature(
57297
- AST10.identifier(key),
57298
- AST10.tsTypeAnnotation(
57299
- scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
57300
- )
57301
- );
57302
- })
57303
- );
57304
- } else if (typeName === "__ROOT__") {
57305
- idFields = AST10.tsTypeLiteral([]);
57306
- }
57307
- let fields = AST10.tsTypeLiteral([]);
57308
- if (graphql15.isObjectType(type)) {
57309
- fields = AST10.tsTypeLiteral(
57310
- Object.entries(type.getFields()).map(
57311
- ([key, fieldType]) => {
57312
- const unwrapped = unwrapType(config2, fieldType.type);
57313
- let typeOptions = AST10.tsUnionType([]);
57314
- if (graphql15.isScalarType(unwrapped.type)) {
57315
- typeOptions.types.push(
57316
- scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
57317
- );
57318
- } else if (graphql15.isEnumType(unwrapped.type)) {
57319
- typeOptions.types.push(
57320
- AST10.tsTypeReference(AST10.identifier(unwrapped.type.name))
57321
- );
57322
- } else if (!graphql15.isAbstractType(unwrapped.type)) {
57323
- typeOptions.types.push(record(unwrapped.type.name));
57324
- } else {
57325
- typeOptions.types.push(
57326
- ...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
57327
- );
57328
- }
57329
- for (const wrapper of unwrapped.wrappers) {
57330
- if (wrapper === "Nullable" /* Nullable */) {
57331
- typeOptions = AST10.tsParenthesizedType(
57332
- AST10.tsUnionType([typeOptions, AST10.tsNullKeyword()])
57333
- );
57334
- } else if (wrapper === "List" /* List */) {
57335
- typeOptions = AST10.tsArrayType(
57336
- AST10.tsParenthesizedType(typeOptions)
57337
- );
57338
- }
57339
- }
57340
- if (typeOptions.type === "TSParenthesizedType") {
57341
- typeOptions = typeOptions.typeAnnotation;
57342
- }
57343
- let args = AST10.tsNeverKeyword();
57344
- if (fieldType.args?.length > 0) {
57345
- args = AST10.tsTypeLiteral(
57346
- fieldType.args.map((arg) => {
57347
- addReferencedInputTypes(
57348
- config2,
57349
- "",
57350
- body,
57351
- visitedTypes,
57352
- /* @__PURE__ */ new Set(),
57353
- arg.type
57354
- );
57355
- const prop = AST10.tsPropertySignature(
57356
- AST10.identifier(arg.name),
57357
- AST10.tsTypeAnnotation(
57358
- tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
57359
- )
57360
- );
57361
- const unwrapped2 = unwrapType(config2, arg.type);
57362
- prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
57363
- return prop;
57364
- })
57365
- );
57366
- }
57367
- return AST10.tsPropertySignature(
57368
- AST10.identifier(key),
57369
- AST10.tsTypeAnnotation(
57370
- AST10.tsTypeLiteral([
57371
- AST10.tsPropertySignature(
57372
- AST10.identifier("type"),
57373
- AST10.tsTypeAnnotation(typeOptions)
57374
- ),
57375
- AST10.tsPropertySignature(
57376
- AST10.identifier("args"),
57377
- AST10.tsTypeAnnotation(args)
57378
- )
57379
- ])
57380
- )
57381
- );
57382
- }
57383
- )
57542
+ return AST7.tsStringKeyword();
57543
+ }
57544
+ default: {
57545
+ if (graphql13.isNonNullType(target) && "ofType" in target) {
57546
+ return scalarPropertyValue(
57547
+ config2,
57548
+ missingScalars,
57549
+ target.ofType
57384
57550
  );
57385
57551
  }
57386
- return AST10.tsPropertySignature(
57387
- AST10.identifier(typeName),
57388
- AST10.tsTypeAnnotation(
57389
- AST10.tsTypeLiteral([
57390
- AST10.tsPropertySignature(
57391
- AST10.identifier("idFields"),
57392
- AST10.tsTypeAnnotation(idFields)
57393
- ),
57394
- AST10.tsPropertySignature(
57395
- AST10.identifier("fields"),
57396
- AST10.tsTypeAnnotation(fields)
57397
- )
57398
- ])
57399
- )
57400
- );
57401
- })
57402
- );
57403
- }
57404
- function listDefinitions(config2, docs) {
57405
- const lists = [];
57406
- const visitedLists = /* @__PURE__ */ new Set();
57407
- for (const doc of docs) {
57408
- graphql15.visit(doc.document, {
57409
- Directive(node, key, parent, path2, ancestors) {
57410
- if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
57411
- return;
57412
- }
57413
- const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
57414
- const nameValue = nameArg?.value?.value || "";
57415
- if (!nameValue || visitedLists.has(nameValue)) {
57416
- return;
57417
- }
57418
- visitedLists.add(nameValue);
57419
- const parentType = parentTypeFromAncestors(
57420
- config2.schema,
57421
- doc.filename,
57422
- ancestors.slice(0, -1)
57423
- );
57424
- const targetField = ancestors[ancestors.length - 1];
57425
- const targetFieldDefinition = parentType.getFields()[targetField.name.value];
57426
- const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
57427
- const possibleTypes = [];
57428
- if (graphql15.isAbstractType(listType)) {
57429
- possibleTypes.push(
57430
- ...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
57431
- );
57432
- } else {
57433
- possibleTypes.push(listType.name);
57434
- }
57435
- lists.push(
57436
- AST10.tsPropertySignature(
57437
- AST10.identifier(nameValue),
57438
- AST10.tsTypeAnnotation(
57439
- AST10.tsTypeLiteral([
57440
- AST10.tsPropertySignature(
57441
- AST10.identifier("types"),
57442
- AST10.tsTypeAnnotation(
57443
- AST10.tsUnionType(
57444
- possibleTypes.map(
57445
- (possible) => AST10.tsLiteralType(AST10.stringLiteral(possible))
57446
- )
57447
- )
57448
- )
57449
- ),
57450
- AST10.tsPropertySignature(
57451
- AST10.identifier("filters"),
57452
- AST10.tsTypeAnnotation(
57453
- targetFieldDefinition.args.length === 0 ? AST10.tsNeverKeyword() : AST10.tsTypeLiteral(
57454
- targetFieldDefinition.args.map((arg) => {
57455
- const argDef = AST10.tsPropertySignature(
57456
- AST10.identifier(arg.name),
57457
- AST10.tsTypeAnnotation(
57458
- tsTypeReference(
57459
- config2,
57460
- /* @__PURE__ */ new Set(),
57461
- arg
57462
- )
57463
- )
57464
- );
57465
- argDef.optional = true;
57466
- return argDef;
57467
- })
57468
- )
57469
- )
57470
- )
57471
- ])
57472
- )
57473
- )
57474
- );
57552
+ if (config2.scalars?.[target.name]) {
57553
+ return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
57475
57554
  }
57476
- });
57555
+ missingScalars.add(target.name);
57556
+ return AST7.tsAnyKeyword();
57557
+ }
57477
57558
  }
57478
- return AST10.tsTypeLiteral(lists);
57479
57559
  }
57480
- var CacheTypeDefName = "CacheTypeDef";
57481
- function record(name2) {
57482
- return AST10.tsTypeReference(
57483
- AST10.identifier("Record"),
57484
- AST10.tsTypeParameterInstantiation([
57485
- AST10.tsTypeReference(AST10.identifier(CacheTypeDefName)),
57486
- AST10.tsLiteralType(AST10.stringLiteral(name2))
57487
- ])
57488
- );
57560
+
57561
+ // src/codegen/generators/typescript/typeReference.ts
57562
+ var AST8 = recast8.types.builders;
57563
+ function tsTypeReference(config2, missingScalars, definition) {
57564
+ const { type, wrappers } = unwrapType(config2, definition.type);
57565
+ let result;
57566
+ if (graphql14.isScalarType(type)) {
57567
+ result = scalarPropertyValue(config2, missingScalars, type);
57568
+ } else {
57569
+ result = AST8.tsTypeReference(AST8.identifier(type.name));
57570
+ }
57571
+ for (const toWrap of wrappers) {
57572
+ if (toWrap === "NonNull" /* NonNull */) {
57573
+ continue;
57574
+ } else if (toWrap === "Nullable" /* Nullable */) {
57575
+ result = nullableField(result, true);
57576
+ } else if (toWrap === "List" /* List */) {
57577
+ result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
57578
+ }
57579
+ }
57580
+ return result;
57581
+ }
57582
+
57583
+ // src/codegen/generators/typescript/addReferencedInputTypes.ts
57584
+ var AST9 = recast9.types.builders;
57585
+ function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
57586
+ const { type } = unwrapType(config2, rootType);
57587
+ if (graphql15.isScalarType(type)) {
57588
+ return;
57589
+ }
57590
+ if (visitedTypes.has(type.name)) {
57591
+ return;
57592
+ }
57593
+ if (graphql15.isUnionType(type)) {
57594
+ throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
57595
+ }
57596
+ visitedTypes.add(type.name);
57597
+ if (graphql15.isEnumType(type)) {
57598
+ ensureImports({
57599
+ config: config2,
57600
+ body,
57601
+ import: [type.name],
57602
+ sourceModule: "$houdini/graphql/enums",
57603
+ importKind: "type"
57604
+ });
57605
+ return;
57606
+ }
57607
+ const members = [];
57608
+ for (const field of Object.values(type.getFields())) {
57609
+ addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
57610
+ members.push(
57611
+ AST9.tsPropertySignature(
57612
+ AST9.identifier(field.name),
57613
+ AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
57614
+ graphql15.isNullableType(field.type)
57615
+ )
57616
+ );
57617
+ }
57618
+ body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
57489
57619
  }
57490
57620
 
57491
57621
  // src/codegen/generators/typescript/inlineType.ts
57492
57622
  var graphql16 = __toESM(require_graphql2(), 1);
57493
- var recast11 = __toESM(require_main2(), 1);
57494
- var AST11 = recast11.types.builders;
57623
+ var recast10 = __toESM(require_main2(), 1);
57624
+ var AST10 = recast10.types.builders;
57495
57625
  var fragmentKey = "$fragments";
57496
57626
  function inlineType({
57497
57627
  config: config2,
@@ -57520,7 +57650,7 @@ function inlineType({
57520
57650
  });
57521
57651
  visitedTypes.add(type.name);
57522
57652
  }
57523
- result = AST11.tsTypeReference(AST11.identifier(type.name));
57653
+ result = AST10.tsTypeReference(AST10.identifier(type.name));
57524
57654
  } else if (selections) {
57525
57655
  const rootObj = type;
57526
57656
  const inlineFragments = {};
@@ -57571,7 +57701,7 @@ function inlineType({
57571
57701
  selectedFields.push(selection2);
57572
57702
  }
57573
57703
  }
57574
- result = AST11.tsTypeLiteral([
57704
+ result = AST10.tsTypeLiteral([
57575
57705
  ...(selectedFields || []).filter(
57576
57706
  (field) => field.kind === "Field"
57577
57707
  ).map((selection2) => {
@@ -57591,9 +57721,9 @@ function inlineType({
57591
57721
  allOptional
57592
57722
  });
57593
57723
  const prop = readonlyProperty(
57594
- AST11.tsPropertySignature(
57595
- AST11.identifier(attributeName),
57596
- AST11.tsTypeAnnotation(attributeType)
57724
+ AST10.tsPropertySignature(
57725
+ AST10.identifier(attributeName),
57726
+ AST10.tsTypeAnnotation(attributeType)
57597
57727
  ),
57598
57728
  allowReadonly
57599
57729
  );
@@ -57607,15 +57737,15 @@ function inlineType({
57607
57737
  if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
57608
57738
  result.members.push(
57609
57739
  readonlyProperty(
57610
- AST11.tsPropertySignature(
57611
- AST11.identifier(fragmentKey),
57612
- AST11.tsTypeAnnotation(
57613
- AST11.tsTypeLiteral(
57740
+ AST10.tsPropertySignature(
57741
+ AST10.identifier(fragmentKey),
57742
+ AST10.tsTypeAnnotation(
57743
+ AST10.tsTypeLiteral(
57614
57744
  (fragmentSpreads || []).map(
57615
- (fragmentSpread) => AST11.tsPropertySignature(
57616
- AST11.identifier(fragmentSpread.name.value),
57617
- AST11.tsTypeAnnotation(
57618
- AST11.tsLiteralType(AST11.booleanLiteral(true))
57745
+ (fragmentSpread) => AST10.tsPropertySignature(
57746
+ AST10.identifier(fragmentSpread.name.value),
57747
+ AST10.tsTypeAnnotation(
57748
+ AST10.tsLiteralType(AST10.booleanLiteral(true))
57619
57749
  )
57620
57750
  )
57621
57751
  )
@@ -57661,9 +57791,9 @@ function inlineType({
57661
57791
  }
57662
57792
  objectType.members.push(
57663
57793
  readonlyProperty(
57664
- AST11.tsPropertySignature(
57665
- AST11.identifier("__typename"),
57666
- AST11.tsTypeAnnotation(AST11.tsLiteralType(AST11.stringLiteral(typeName)))
57794
+ AST10.tsPropertySignature(
57795
+ AST10.identifier("__typename"),
57796
+ AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
57667
57797
  ),
57668
57798
  allowReadonly
57669
57799
  )
@@ -57674,8 +57804,8 @@ function inlineType({
57674
57804
  if (Object.keys(inlineFragmentSelections).length > 0) {
57675
57805
  let selectionTypes = Object.entries(inlineFragmentSelections).map(
57676
57806
  ([typeName, { type: type2, tsType }]) => {
57677
- return AST11.tsParenthesizedType(
57678
- AST11.tsIntersectionType(
57807
+ return AST10.tsParenthesizedType(
57808
+ AST10.tsIntersectionType(
57679
57809
  [tsType].flatMap((type3) => {
57680
57810
  if (type3.type === "TSUnionType") {
57681
57811
  return type3.types.filter(
@@ -57688,9 +57818,9 @@ function inlineType({
57688
57818
  );
57689
57819
  }
57690
57820
  );
57691
- result = AST11.tsIntersectionType([
57821
+ result = AST10.tsIntersectionType([
57692
57822
  result,
57693
- AST11.tsParenthesizedType(AST11.tsUnionType(selectionTypes))
57823
+ AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
57694
57824
  ]);
57695
57825
  }
57696
57826
  } else {
@@ -57702,7 +57832,7 @@ function inlineType({
57702
57832
  } else if (toWrap === "NonNull" /* NonNull */) {
57703
57833
  continue;
57704
57834
  } else if (toWrap === "List" /* List */) {
57705
- result = AST11.tsArrayType(AST11.tsParenthesizedType(result));
57835
+ result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
57706
57836
  }
57707
57837
  }
57708
57838
  return result;
@@ -57746,9 +57876,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
57746
57876
  return { field, type: selectionType };
57747
57877
  }
57748
57878
 
57749
- // src/codegen/generators/typescript/index.ts
57750
- var AST12 = recast12.types.builders;
57751
- async function typescriptGenerator(config2, docs) {
57879
+ // src/codegen/generators/typescript/documentTypes.ts
57880
+ var AST11 = recast11.types.builders;
57881
+ async function generateDocumentTypes(config2, docs) {
57752
57882
  const typePaths = [];
57753
57883
  const fragmentDefinitions = {};
57754
57884
  for (const document of docs) {
@@ -57765,7 +57895,7 @@ async function typescriptGenerator(config2, docs) {
57765
57895
  return;
57766
57896
  }
57767
57897
  const typeDefPath = config2.artifactTypePath(originalDocument);
57768
- const program = AST12.program([]);
57898
+ const program = AST11.program([]);
57769
57899
  const visitedTypes = /* @__PURE__ */ new Set();
57770
57900
  let definition = originalDocument.definitions.find(
57771
57901
  (def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
@@ -57798,21 +57928,21 @@ async function typescriptGenerator(config2, docs) {
57798
57928
  missingScalars
57799
57929
  );
57800
57930
  }
57801
- await fs_exports.writeFile(typeDefPath, recast12.print(program).code);
57931
+ await fs_exports.writeFile(typeDefPath, recast11.print(program).code);
57802
57932
  typePaths.push(typeDefPath);
57803
57933
  })
57804
57934
  );
57805
- const typeIndex = AST12.program(
57935
+ const typeIndex = AST11.program(
57806
57936
  typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
57807
- return AST12.exportAllDeclaration(
57808
- AST12.literal(
57937
+ return AST11.exportAllDeclaration(
57938
+ AST11.literal(
57809
57939
  "./" + path_exports.relative(path_exports.resolve(config2.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
57810
57940
  ),
57811
57941
  null
57812
57942
  );
57813
57943
  }).concat([
57814
- AST12.exportAllDeclaration(AST12.literal("./runtime"), null),
57815
- AST12.exportAllDeclaration(AST12.literal("./graphql"), null)
57944
+ AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
57945
+ AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
57816
57946
  ])
57817
57947
  );
57818
57948
  const export_default_as = ({ module: module2, as }) => `
@@ -57821,7 +57951,7 @@ export { default as ${as} } from "${module2}"
57821
57951
  const export_star_from = ({ module: module2 }) => `
57822
57952
  export * from "${module2}"
57823
57953
  `;
57824
- let indexContent = recast12.print(typeIndex).code;
57954
+ let indexContent = recast11.print(typeIndex).code;
57825
57955
  for (const plugin of config2.plugins) {
57826
57956
  if (!plugin.index_file) {
57827
57957
  continue;
@@ -57842,7 +57972,6 @@ export * from "${module2}"
57842
57972
  }
57843
57973
  }
57844
57974
  await fs_exports.writeFile(config2.typeIndexPath, indexContent);
57845
- await imperativeCacheTypef(config2, docs);
57846
57975
  if (missingScalars.size > 0) {
57847
57976
  console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
57848
57977
  ", "
@@ -57884,23 +58013,23 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57884
58013
  const optimisticTypeName = `${definition.name.value}$optimistic`;
57885
58014
  const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
57886
58015
  body.push(
57887
- AST12.exportNamedDeclaration(
57888
- AST12.tsTypeAliasDeclaration(
57889
- AST12.identifier(definition.name.value),
57890
- AST12.tsTypeLiteral([
58016
+ AST11.exportNamedDeclaration(
58017
+ AST11.tsTypeAliasDeclaration(
58018
+ AST11.identifier(definition.name.value),
58019
+ AST11.tsTypeLiteral([
57891
58020
  readonlyProperty(
57892
- AST12.tsPropertySignature(
57893
- AST12.stringLiteral("input"),
57894
- AST12.tsTypeAnnotation(AST12.tsTypeReference(AST12.identifier(inputTypeName)))
58021
+ AST11.tsPropertySignature(
58022
+ AST11.stringLiteral("input"),
58023
+ AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
57895
58024
  )
57896
58025
  ),
57897
58026
  readonlyProperty(
57898
- AST12.tsPropertySignature(
57899
- AST12.stringLiteral("result"),
57900
- AST12.tsTypeAnnotation(
57901
- definition.operation === "mutation" ? AST12.tsTypeReference(AST12.identifier(shapeTypeName)) : AST12.tsUnionType([
57902
- AST12.tsTypeReference(AST12.identifier(shapeTypeName)),
57903
- AST12.tsUndefinedKeyword()
58027
+ AST11.tsPropertySignature(
58028
+ AST11.stringLiteral("result"),
58029
+ AST11.tsTypeAnnotation(
58030
+ definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
58031
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
58032
+ AST11.tsUndefinedKeyword()
57904
58033
  ])
57905
58034
  )
57906
58035
  )
@@ -57908,9 +58037,9 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57908
58037
  ])
57909
58038
  )
57910
58039
  ),
57911
- AST12.exportNamedDeclaration(
57912
- AST12.tsTypeAliasDeclaration(
57913
- AST12.identifier(shapeTypeName),
58040
+ AST11.exportNamedDeclaration(
58041
+ AST11.tsTypeAliasDeclaration(
58042
+ AST11.identifier(shapeTypeName),
57914
58043
  inlineType({
57915
58044
  config: config2,
57916
58045
  filepath,
@@ -57938,15 +58067,15 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57938
58067
  );
57939
58068
  }
57940
58069
  body.push(
57941
- AST12.exportNamedDeclaration(
57942
- AST12.tsTypeAliasDeclaration(
57943
- AST12.identifier(inputTypeName),
57944
- AST12.tsTypeLiteral(
58070
+ AST11.exportNamedDeclaration(
58071
+ AST11.tsTypeAliasDeclaration(
58072
+ AST11.identifier(inputTypeName),
58073
+ AST11.tsTypeLiteral(
57945
58074
  (definition.variableDefinitions || []).map(
57946
58075
  (definition2) => {
57947
- return AST12.tsPropertySignature(
57948
- AST12.identifier(definition2.variable.name.value),
57949
- AST12.tsTypeAnnotation(
58076
+ return AST11.tsPropertySignature(
58077
+ AST11.identifier(definition2.variable.name.value),
58078
+ AST11.tsTypeAnnotation(
57950
58079
  tsTypeReference(config2, missingScalars, definition2)
57951
58080
  ),
57952
58081
  definition2.type.kind !== "NonNullType"
@@ -57959,16 +58088,16 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57959
58088
  );
57960
58089
  } else {
57961
58090
  body.push(
57962
- AST12.exportNamedDeclaration(
57963
- AST12.tsTypeAliasDeclaration(AST12.identifier(inputTypeName), AST12.tsNullKeyword())
58091
+ AST11.exportNamedDeclaration(
58092
+ AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
57964
58093
  )
57965
58094
  );
57966
58095
  }
57967
58096
  if (definition.operation === "mutation") {
57968
58097
  body.push(
57969
- AST12.exportNamedDeclaration(
57970
- AST12.tsTypeAliasDeclaration(
57971
- AST12.identifier(optimisticTypeName),
58098
+ AST11.exportNamedDeclaration(
58099
+ AST11.tsTypeAliasDeclaration(
58100
+ AST11.identifier(optimisticTypeName),
57972
58101
  inlineType({
57973
58102
  config: config2,
57974
58103
  filepath,
@@ -57994,65 +58123,463 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
57994
58123
  }
57995
58124
  const propTypeName = definition.name.value;
57996
58125
  const shapeTypeName = `${definition.name.value}$data`;
58126
+ const inputTypeName = `${definition.name.value}$input`;
57997
58127
  const type = config2.schema.getType(definition.typeCondition.name.value);
57998
58128
  if (!type) {
57999
58129
  throw new Error("Should not get here");
58000
58130
  }
58131
+ let extraExports = [];
58132
+ let directive = definition.directives?.find(
58133
+ (directive2) => directive2.name.value === config2.argumentsDirective
58134
+ );
58135
+ if (directive) {
58136
+ extraExports.push(
58137
+ AST11.exportNamedDeclaration(
58138
+ AST11.tsTypeAliasDeclaration(
58139
+ AST11.identifier(inputTypeName),
58140
+ AST11.tsTypeLiteral(
58141
+ (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
58142
+ (definition2) => {
58143
+ return AST11.tsPropertySignature(
58144
+ AST11.identifier(definition2.variable.name.value),
58145
+ AST11.tsTypeAnnotation(
58146
+ tsTypeReference(config2, missingScalars, definition2)
58147
+ ),
58148
+ definition2.type.kind !== "NonNullType"
58149
+ );
58150
+ }
58151
+ )
58152
+ )
58153
+ )
58154
+ )
58155
+ );
58156
+ }
58001
58157
  body.push(
58002
- AST12.exportNamedDeclaration(
58003
- AST12.tsTypeAliasDeclaration(
58004
- AST12.identifier(propTypeName),
58005
- AST12.tsTypeLiteral([
58158
+ ...extraExports,
58159
+ AST11.exportNamedDeclaration(
58160
+ AST11.tsTypeAliasDeclaration(
58161
+ AST11.identifier(propTypeName),
58162
+ AST11.tsTypeLiteral([
58006
58163
  readonlyProperty(
58007
- AST12.tsPropertySignature(
58008
- AST12.stringLiteral("shape"),
58009
- AST12.tsTypeAnnotation(
58010
- AST12.tsTypeReference(AST12.identifier(shapeTypeName))
58164
+ AST11.tsPropertySignature(
58165
+ AST11.stringLiteral("shape"),
58166
+ AST11.tsTypeAnnotation(
58167
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName))
58011
58168
  ),
58012
58169
  true
58013
58170
  )
58014
58171
  ),
58015
58172
  readonlyProperty(
58016
- AST12.tsPropertySignature(
58017
- AST12.stringLiteral(fragmentKey),
58173
+ AST11.tsPropertySignature(
58174
+ AST11.stringLiteral(fragmentKey),
58175
+ AST11.tsTypeAnnotation(
58176
+ AST11.tsTypeLiteral([
58177
+ AST11.tsPropertySignature(
58178
+ AST11.stringLiteral(propTypeName),
58179
+ AST11.tsTypeAnnotation(
58180
+ AST11.tsLiteralType(AST11.booleanLiteral(true))
58181
+ )
58182
+ )
58183
+ ])
58184
+ )
58185
+ )
58186
+ )
58187
+ ])
58188
+ )
58189
+ ),
58190
+ AST11.exportNamedDeclaration(
58191
+ AST11.tsTypeAliasDeclaration(
58192
+ AST11.identifier(shapeTypeName),
58193
+ inlineType({
58194
+ config: config2,
58195
+ filepath,
58196
+ rootType: type,
58197
+ selections,
58198
+ root: true,
58199
+ allowReadonly: true,
58200
+ body,
58201
+ visitedTypes,
58202
+ missingScalars,
58203
+ includeFragments: true
58204
+ })
58205
+ )
58206
+ )
58207
+ );
58208
+ }
58209
+ }
58210
+
58211
+ // src/codegen/generators/typescript/imperativeTypeDef.ts
58212
+ var graphql17 = __toESM(require_graphql2(), 1);
58213
+ var recast12 = __toESM(require_main2(), 1);
58214
+ var AST12 = recast12.types.builders;
58215
+ async function imperativeCacheTypef(config2, docs) {
58216
+ const returnType = (doc) => config2.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
58217
+ config: config2,
58218
+ doc,
58219
+ ensure_import({ identifier, module: module2 }) {
58220
+ ensureImports({
58221
+ config: config2,
58222
+ body,
58223
+ sourceModule: module2,
58224
+ import: [identifier]
58225
+ });
58226
+ }
58227
+ }) ?? "any";
58228
+ const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
58229
+ const body = [];
58230
+ const declaration = AST12.tsTypeAliasDeclaration(
58231
+ AST12.identifier(CacheTypeDefName),
58232
+ AST12.tsTypeLiteral([
58233
+ AST12.tsPropertySignature(
58234
+ AST12.identifier("types"),
58235
+ AST12.tsTypeAnnotation(typeDefinitions(config2, body, docs, returnType))
58236
+ ),
58237
+ AST12.tsPropertySignature(
58238
+ AST12.identifier("lists"),
58239
+ AST12.tsTypeAnnotation(listDefinitions(config2, docs))
58240
+ ),
58241
+ AST12.tsPropertySignature(
58242
+ AST12.identifier("queries"),
58243
+ AST12.tsTypeAnnotation(queryDefinitions(config2, body, docs, returnType))
58244
+ )
58245
+ ])
58246
+ );
58247
+ declaration.declare = true;
58248
+ const importRecord = AST12.importDeclaration(
58249
+ [AST12.importSpecifier(AST12.identifier("Record"))],
58250
+ AST12.stringLiteral("./public/record")
58251
+ );
58252
+ importRecord.importKind = "type";
58253
+ await fs_exports.writeFile(
58254
+ target,
58255
+ recast12.prettyPrint(
58256
+ AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
58257
+ ).code
58258
+ );
58259
+ }
58260
+ function typeDefinitions(config2, body, docs, returnType) {
58261
+ const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
58262
+ const visitedTypes = /* @__PURE__ */ new Set();
58263
+ const types14 = Object.values(config2.schema.getTypeMap()).filter(
58264
+ (type) => !graphql17.isAbstractType(type) && !graphql17.isScalarType(type) && !graphql17.isEnumType(type) && !graphql17.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
58265
+ );
58266
+ const fragmentMap = fragmentListMap(
58267
+ config2,
58268
+ types14.map((type) => type.name),
58269
+ body,
58270
+ docs,
58271
+ returnType
58272
+ );
58273
+ return AST12.tsTypeLiteral(
58274
+ types14.map((type) => {
58275
+ let typeName = type.name;
58276
+ if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
58277
+ typeName = "__ROOT__";
58278
+ }
58279
+ let idFields = AST12.tsNeverKeyword();
58280
+ const keys = keyFieldsForType(config2.configFile, type.name);
58281
+ if (graphql17.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
58282
+ idFields = AST12.tsTypeLiteral(
58283
+ keys.map((key) => {
58284
+ const fieldType = type.getFields()[key];
58285
+ const unwrapped = unwrapType(config2, fieldType.type);
58286
+ return AST12.tsPropertySignature(
58287
+ AST12.identifier(key),
58288
+ AST12.tsTypeAnnotation(
58289
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
58290
+ )
58291
+ );
58292
+ })
58293
+ );
58294
+ } else if (typeName === "__ROOT__") {
58295
+ idFields = AST12.tsTypeLiteral([]);
58296
+ }
58297
+ let fields = AST12.tsTypeLiteral([]);
58298
+ if (graphql17.isObjectType(type)) {
58299
+ fields = AST12.tsTypeLiteral(
58300
+ Object.entries(type.getFields()).map(
58301
+ ([key, fieldType]) => {
58302
+ const unwrapped = unwrapType(config2, fieldType.type);
58303
+ let typeOptions = AST12.tsUnionType([]);
58304
+ if (graphql17.isScalarType(unwrapped.type)) {
58305
+ typeOptions.types.push(
58306
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
58307
+ );
58308
+ } else if (graphql17.isEnumType(unwrapped.type)) {
58309
+ typeOptions.types.push(
58310
+ AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
58311
+ );
58312
+ } else if (!graphql17.isAbstractType(unwrapped.type)) {
58313
+ typeOptions.types.push(record(unwrapped.type.name));
58314
+ } else {
58315
+ typeOptions.types.push(
58316
+ ...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
58317
+ );
58318
+ }
58319
+ for (const wrapper of unwrapped.wrappers) {
58320
+ if (wrapper === "Nullable" /* Nullable */) {
58321
+ typeOptions = AST12.tsParenthesizedType(
58322
+ AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
58323
+ );
58324
+ } else if (wrapper === "List" /* List */) {
58325
+ typeOptions = AST12.tsArrayType(
58326
+ AST12.tsParenthesizedType(typeOptions)
58327
+ );
58328
+ }
58329
+ }
58330
+ if (typeOptions.type === "TSParenthesizedType") {
58331
+ typeOptions = typeOptions.typeAnnotation;
58332
+ }
58333
+ let args = AST12.tsNeverKeyword();
58334
+ if (fieldType.args?.length > 0) {
58335
+ args = AST12.tsTypeLiteral(
58336
+ fieldType.args.map((arg) => {
58337
+ addReferencedInputTypes(
58338
+ config2,
58339
+ "",
58340
+ body,
58341
+ visitedTypes,
58342
+ /* @__PURE__ */ new Set(),
58343
+ arg.type
58344
+ );
58345
+ const prop = AST12.tsPropertySignature(
58346
+ AST12.identifier(arg.name),
58347
+ AST12.tsTypeAnnotation(
58348
+ tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
58349
+ )
58350
+ );
58351
+ const unwrapped2 = unwrapType(config2, arg.type);
58352
+ prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
58353
+ return prop;
58354
+ })
58355
+ );
58356
+ }
58357
+ return AST12.tsPropertySignature(
58358
+ AST12.identifier(key),
58018
58359
  AST12.tsTypeAnnotation(
58019
58360
  AST12.tsTypeLiteral([
58020
58361
  AST12.tsPropertySignature(
58021
- AST12.stringLiteral(propTypeName),
58022
- AST12.tsTypeAnnotation(
58023
- AST12.tsLiteralType(AST12.booleanLiteral(true))
58024
- )
58362
+ AST12.identifier("type"),
58363
+ AST12.tsTypeAnnotation(typeOptions)
58364
+ ),
58365
+ AST12.tsPropertySignature(
58366
+ AST12.identifier("args"),
58367
+ AST12.tsTypeAnnotation(args)
58025
58368
  )
58026
58369
  ])
58027
58370
  )
58028
- )
58371
+ );
58372
+ }
58373
+ )
58374
+ );
58375
+ }
58376
+ return AST12.tsPropertySignature(
58377
+ AST12.identifier(typeName),
58378
+ AST12.tsTypeAnnotation(
58379
+ AST12.tsTypeLiteral([
58380
+ AST12.tsPropertySignature(
58381
+ AST12.identifier("idFields"),
58382
+ AST12.tsTypeAnnotation(idFields)
58383
+ ),
58384
+ AST12.tsPropertySignature(
58385
+ AST12.identifier("fields"),
58386
+ AST12.tsTypeAnnotation(fields)
58387
+ ),
58388
+ AST12.tsPropertySignature(
58389
+ AST12.identifier("fragments"),
58390
+ AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
58029
58391
  )
58030
58392
  ])
58031
58393
  )
58394
+ );
58395
+ })
58396
+ );
58397
+ }
58398
+ function listDefinitions(config2, docs) {
58399
+ const lists = [];
58400
+ const visitedLists = /* @__PURE__ */ new Set();
58401
+ for (const doc of docs) {
58402
+ graphql17.visit(doc.document, {
58403
+ Directive(node, key, parent, path2, ancestors) {
58404
+ if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
58405
+ return;
58406
+ }
58407
+ const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
58408
+ const nameValue = nameArg?.value?.value || "";
58409
+ if (!nameValue || visitedLists.has(nameValue)) {
58410
+ return;
58411
+ }
58412
+ visitedLists.add(nameValue);
58413
+ const parentType = parentTypeFromAncestors(
58414
+ config2.schema,
58415
+ doc.filename,
58416
+ ancestors.slice(0, -1)
58417
+ );
58418
+ const targetField = ancestors[ancestors.length - 1];
58419
+ const targetFieldDefinition = parentType.getFields()[targetField.name.value];
58420
+ const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
58421
+ const possibleTypes = [];
58422
+ if (graphql17.isAbstractType(listType)) {
58423
+ possibleTypes.push(
58424
+ ...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
58425
+ );
58426
+ } else {
58427
+ possibleTypes.push(listType.name);
58428
+ }
58429
+ lists.push(
58430
+ AST12.tsPropertySignature(
58431
+ AST12.identifier(nameValue),
58432
+ AST12.tsTypeAnnotation(
58433
+ AST12.tsTypeLiteral([
58434
+ AST12.tsPropertySignature(
58435
+ AST12.identifier("types"),
58436
+ AST12.tsTypeAnnotation(
58437
+ AST12.tsUnionType(
58438
+ possibleTypes.map(
58439
+ (possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
58440
+ )
58441
+ )
58442
+ )
58443
+ ),
58444
+ AST12.tsPropertySignature(
58445
+ AST12.identifier("filters"),
58446
+ AST12.tsTypeAnnotation(
58447
+ targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
58448
+ targetFieldDefinition.args.map((arg) => {
58449
+ const argDef = AST12.tsPropertySignature(
58450
+ AST12.identifier(arg.name),
58451
+ AST12.tsTypeAnnotation(
58452
+ tsTypeReference(
58453
+ config2,
58454
+ /* @__PURE__ */ new Set(),
58455
+ arg
58456
+ )
58457
+ )
58458
+ );
58459
+ argDef.optional = true;
58460
+ return argDef;
58461
+ })
58462
+ )
58463
+ )
58464
+ )
58465
+ ])
58466
+ )
58467
+ )
58468
+ );
58469
+ }
58470
+ });
58471
+ }
58472
+ return AST12.tsTypeLiteral(lists);
58473
+ }
58474
+ function queryDefinitions(config2, body, docs, returnType) {
58475
+ return AST12.tsTupleType(
58476
+ docs.reduce((prev, doc) => {
58477
+ if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
58478
+ return prev;
58479
+ }
58480
+ const definition = doc.document.definitions.find(
58481
+ (def) => def.kind === "OperationDefinition" && def.operation === "query"
58482
+ );
58483
+ if (!definition) {
58484
+ return prev;
58485
+ }
58486
+ const runtimeType = returnType(doc);
58487
+ const [shapeType, inputType] = ensureImports({
58488
+ config: config2,
58489
+ body,
58490
+ sourceModule: path_exports.relative(
58491
+ config2.runtimeDirectory,
58492
+ config2.artifactImportPath(doc.name)
58493
+ ),
58494
+ import: [`${doc.name}$result`, `${doc.name}$input`]
58495
+ });
58496
+ return prev.concat(
58497
+ AST12.tsTupleType([
58498
+ AST12.tsTypeReference(AST12.identifier(runtimeType)),
58499
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
58500
+ AST12.tsTypeReference(AST12.identifier(inputType))
58501
+ ])
58502
+ );
58503
+ }, [])
58504
+ );
58505
+ }
58506
+ function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
58507
+ return docs.reduce((prev, doc) => {
58508
+ if (doc.kind !== "HoudiniFragment" /* Fragment */) {
58509
+ return prev;
58510
+ }
58511
+ const definition = doc.document.definitions.find(
58512
+ (def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
58513
+ );
58514
+ if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
58515
+ return prev;
58516
+ }
58517
+ const typeName = definition.typeCondition.name.value;
58518
+ const previousValue = prev[typeName]?.elementTypes ?? [];
58519
+ const tagResult = return_type(doc);
58520
+ const [shapeType] = ensureImports({
58521
+ config: config2,
58522
+ body,
58523
+ sourceModule: path_exports.relative(
58524
+ config2.runtimeDirectory,
58525
+ config2.artifactImportPath(doc.name)
58032
58526
  ),
58033
- AST12.exportNamedDeclaration(
58034
- AST12.tsTypeAliasDeclaration(
58035
- AST12.identifier(shapeTypeName),
58036
- inlineType({
58527
+ import: [`${definition.name.value}$data`]
58528
+ });
58529
+ let inputType = AST12.tsNeverKeyword();
58530
+ let directive = definition.directives?.find(
58531
+ (directive2) => directive2.name.value === config2.argumentsDirective
58532
+ );
58533
+ if (directive) {
58534
+ inputType = AST12.tsTypeReference(
58535
+ AST12.identifier(
58536
+ ensureImports({
58037
58537
  config: config2,
58038
- filepath,
58039
- rootType: type,
58040
- selections,
58041
- root: true,
58042
- allowReadonly: true,
58043
58538
  body,
58044
- visitedTypes,
58045
- missingScalars,
58046
- includeFragments: true
58047
- })
58539
+ sourceModule: path_exports.relative(
58540
+ config2.runtimeDirectory,
58541
+ config2.artifactImportPath(doc.name)
58542
+ ),
58543
+ import: [`${definition.name.value}$input`]
58544
+ })[0]
58545
+ )
58546
+ );
58547
+ }
58548
+ return {
58549
+ ...prev,
58550
+ [typeName]: AST12.tsTupleType(
58551
+ previousValue.concat(
58552
+ AST12.tsTupleType([
58553
+ AST12.tsTypeReference(AST12.identifier(tagResult)),
58554
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
58555
+ inputType
58556
+ ])
58048
58557
  )
58049
58558
  )
58050
- );
58051
- }
58559
+ };
58560
+ }, {});
58561
+ }
58562
+ var CacheTypeDefName = "CacheTypeDef";
58563
+ function record(name2) {
58564
+ return AST12.tsTypeReference(
58565
+ AST12.identifier("Record"),
58566
+ AST12.tsTypeParameterInstantiation([
58567
+ AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
58568
+ AST12.tsLiteralType(AST12.stringLiteral(name2))
58569
+ ])
58570
+ );
58571
+ }
58572
+
58573
+ // src/codegen/generators/typescript/index.ts
58574
+ async function typescriptGenerator(config2, docs) {
58575
+ await Promise.all([
58576
+ generateDocumentTypes(config2, docs),
58577
+ imperativeCacheTypef(config2, docs)
58578
+ ]);
58052
58579
  }
58053
58580
 
58054
58581
  // src/codegen/generators/persistedQueries/index.ts
58055
- var graphql17 = __toESM(require_graphql2(), 1);
58582
+ var graphql18 = __toESM(require_graphql2(), 1);
58056
58583
  async function persistOutputGenerator(config2, docs) {
58057
58584
  if (typeof config2.persistedQueryPath !== "string" || config2.persistedQueryPath.length === 0)
58058
58585
  return;
@@ -58064,8 +58591,8 @@ async function persistOutputGenerator(config2, docs) {
58064
58591
  if (!generateArtifact) {
58065
58592
  return acc;
58066
58593
  }
58067
- let rawString = graphql17.print(
58068
- graphql17.visit(document, {
58594
+ let rawString = graphql18.print(
58595
+ graphql18.visit(document, {
58069
58596
  Directive(node) {
58070
58597
  if (config2.isInternalDirective(node)) {
58071
58598
  return null;
@@ -58074,7 +58601,7 @@ async function persistOutputGenerator(config2, docs) {
58074
58601
  })
58075
58602
  );
58076
58603
  const operations = document.definitions.filter(
58077
- ({ kind }) => kind === graphql17.Kind.OPERATION_DEFINITION
58604
+ ({ kind }) => kind === graphql18.Kind.OPERATION_DEFINITION
58078
58605
  );
58079
58606
  if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
58080
58607
  acc[hashDocument(rawString)] = rawString;
@@ -58087,11 +58614,11 @@ async function persistOutputGenerator(config2, docs) {
58087
58614
  }
58088
58615
 
58089
58616
  // src/codegen/generators/definitions/enums.ts
58090
- var graphql18 = __toESM(require_graphql2(), 1);
58617
+ var graphql19 = __toESM(require_graphql2(), 1);
58091
58618
  var recast13 = __toESM(require_main2(), 1);
58092
58619
  var AST13 = recast13.types.builders;
58093
58620
  async function definitionsGenerator(config2) {
58094
- const enums = graphql18.parse(graphql18.printSchema(config2.schema)).definitions.filter(
58621
+ const enums = graphql19.parse(graphql19.printSchema(config2.schema)).definitions.filter(
58095
58622
  (definition) => definition.kind === "EnumTypeDefinition"
58096
58623
  ).filter((def) => !config2.isInternalEnum(def));
58097
58624
  const runtimeDefinitions = recast13.print(
@@ -58181,91 +58708,8 @@ async function writeIndexFile2(config2, docs) {
58181
58708
  await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
58182
58709
  }
58183
58710
 
58184
- // src/codegen/transforms/composeQueries.ts
58185
- var import_graphql = __toESM(require_graphql2(), 1);
58186
- async function includeFragmentDefinitions(config2, documents) {
58187
- const fragments = collectFragments(config2, documents);
58188
- for (const [index, { name: name2, document, filename }] of documents.entries()) {
58189
- const operation = document.definitions.find(
58190
- ({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
58191
- );
58192
- if (!operation) {
58193
- continue;
58194
- }
58195
- const allFragments = flattenFragments(
58196
- filename,
58197
- { requiredFragments: findRequiredFragments(operation.selectionSet) },
58198
- fragments
58199
- );
58200
- documents[index].document = {
58201
- ...document,
58202
- definitions: [
58203
- operation,
58204
- ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
58205
- ]
58206
- };
58207
- }
58208
- }
58209
- function collectFragments(config2, docs) {
58210
- return docs.reduce((acc, doc) => {
58211
- const definitions = doc.document.definitions.reduce(
58212
- (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
58213
- ...prev,
58214
- [definition.name.value]: {
58215
- definition,
58216
- requiredFragments: findRequiredFragments(definition.selectionSet),
58217
- document: doc
58218
- }
58219
- },
58220
- {}
58221
- );
58222
- return {
58223
- ...acc,
58224
- ...definitions
58225
- };
58226
- }, {});
58227
- }
58228
- function findRequiredFragments(selectionSet) {
58229
- if (selectionSet.selections.length === 0) {
58230
- return [];
58231
- }
58232
- const referencedFragments = [];
58233
- for (const selection2 of selectionSet.selections) {
58234
- if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
58235
- referencedFragments.push(selection2.name.value);
58236
- } else if (selection2.selectionSet) {
58237
- referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
58238
- }
58239
- }
58240
- return referencedFragments;
58241
- }
58242
- function flattenFragments(filepath, operation, fragments) {
58243
- const frags = /* @__PURE__ */ new Set();
58244
- const remaining = [...operation.requiredFragments];
58245
- while (remaining.length > 0) {
58246
- const nextFragment = remaining.shift();
58247
- if (!nextFragment) {
58248
- continue;
58249
- }
58250
- if (!frags.has(nextFragment)) {
58251
- frags.add(nextFragment);
58252
- } else {
58253
- continue;
58254
- }
58255
- const targetFragment = fragments[nextFragment];
58256
- if (!targetFragment) {
58257
- throw new HoudiniError({
58258
- filepath,
58259
- message: "compose: could not find definition for fragment " + nextFragment
58260
- });
58261
- }
58262
- remaining.push(...targetFragment.requiredFragments);
58263
- }
58264
- return [...frags];
58265
- }
58266
-
58267
58711
  // src/codegen/transforms/schema.ts
58268
- var graphql19 = __toESM(require_graphql2(), 1);
58712
+ var graphql20 = __toESM(require_graphql2(), 1);
58269
58713
  async function graphqlExtensions(config2, documents) {
58270
58714
  const internalSchema = `
58271
58715
  enum CachePolicy {
@@ -58329,9 +58773,9 @@ directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
58329
58773
  directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
58330
58774
 
58331
58775
  """
58332
- @${config2.manualLoadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
58776
+ @${config2.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
58333
58777
  """
58334
- directive @${config2.manualLoadDirective} on QUERY
58778
+ directive @${config2.loadDirective} on QUERY
58335
58779
 
58336
58780
  """
58337
58781
  @${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
@@ -58343,19 +58787,19 @@ directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
58343
58787
  """
58344
58788
  directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
58345
58789
  `;
58346
- let currentSchema = graphql19.printSchema(config2.schema);
58790
+ let currentSchema = graphql20.printSchema(config2.schema);
58347
58791
  if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
58348
58792
  currentSchema += internalSchema;
58349
58793
  }
58350
58794
  config2.newSchema += internalSchema;
58351
- config2.schema = graphql19.buildSchema(currentSchema);
58795
+ config2.schema = graphql20.buildSchema(currentSchema);
58352
58796
  }
58353
58797
 
58354
58798
  // src/codegen/transforms/typename.ts
58355
- var graphql20 = __toESM(require_graphql2(), 1);
58799
+ var graphql21 = __toESM(require_graphql2(), 1);
58356
58800
  async function addTypename(config2, documents) {
58357
58801
  for (const doc of documents) {
58358
- doc.document = graphql20.visit(doc.document, {
58802
+ doc.document = graphql21.visit(doc.document, {
58359
58803
  Field(node, key, parent, path2, ancestors) {
58360
58804
  if (!node.selectionSet) {
58361
58805
  return;
@@ -58367,7 +58811,7 @@ async function addTypename(config2, documents) {
58367
58811
  );
58368
58812
  const field = type.getFields()[node.name.value];
58369
58813
  const fieldType = unwrapType(config2, field.type).type;
58370
- if (graphql20.isInterfaceType(fieldType) || graphql20.isUnionType(fieldType)) {
58814
+ if (graphql21.isInterfaceType(fieldType) || graphql21.isUnionType(fieldType)) {
58371
58815
  return {
58372
58816
  ...node,
58373
58817
  selectionSet: {
@@ -58375,9 +58819,9 @@ async function addTypename(config2, documents) {
58375
58819
  selections: [
58376
58820
  ...node.selectionSet.selections,
58377
58821
  {
58378
- kind: graphql20.Kind.FIELD,
58822
+ kind: graphql21.Kind.FIELD,
58379
58823
  name: {
58380
- kind: graphql20.Kind.NAME,
58824
+ kind: graphql21.Kind.NAME,
58381
58825
  value: "__typename"
58382
58826
  }
58383
58827
  }
@@ -58391,10 +58835,10 @@ async function addTypename(config2, documents) {
58391
58835
  }
58392
58836
 
58393
58837
  // src/codegen/transforms/addID.ts
58394
- var graphql21 = __toESM(require_graphql2(), 1);
58838
+ var graphql22 = __toESM(require_graphql2(), 1);
58395
58839
  async function addID(config2, documents) {
58396
58840
  for (const doc of documents) {
58397
- doc.document = graphql21.visit(doc.document, {
58841
+ doc.document = graphql22.visit(doc.document, {
58398
58842
  Field(node, key, parent, path2, ancestors) {
58399
58843
  if (!node.selectionSet) {
58400
58844
  return;
@@ -58407,7 +58851,7 @@ async function addID(config2, documents) {
58407
58851
  const field = type.getFields()[node.name.value];
58408
58852
  const fieldType = unwrapType(config2, field.type).type;
58409
58853
  if (node.selectionSet?.selections.length > 0) {
58410
- if (!graphql21.isObjectType(fieldType) && !graphql21.isInterfaceType(fieldType)) {
58854
+ if (!graphql22.isObjectType(fieldType) && !graphql22.isInterfaceType(fieldType)) {
58411
58855
  return;
58412
58856
  }
58413
58857
  const keyFields = config2.keyFieldsForType(fieldType.name);
@@ -58422,9 +58866,9 @@ async function addID(config2, documents) {
58422
58866
  continue;
58423
58867
  }
58424
58868
  selections.push({
58425
- kind: graphql21.Kind.FIELD,
58869
+ kind: graphql22.Kind.FIELD,
58426
58870
  name: {
58427
- kind: graphql21.Kind.NAME,
58871
+ kind: graphql22.Kind.NAME,
58428
58872
  value: keyField
58429
58873
  }
58430
58874
  });
@@ -58442,266 +58886,6 @@ async function addID(config2, documents) {
58442
58886
  }
58443
58887
  }
58444
58888
 
58445
- // src/codegen/transforms/fragmentVariables.ts
58446
- var graphql22 = __toESM(require_graphql2(), 1);
58447
- var GraphqlKinds2 = graphql22.Kind;
58448
- async function fragmentVariables(config2, documents) {
58449
- const fragments = collectFragments(config2, documents);
58450
- const generatedFragments = {};
58451
- const visitedFragments = /* @__PURE__ */ new Set();
58452
- for (const doc2 of documents) {
58453
- const operation = doc2.document.definitions.find(
58454
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
58455
- );
58456
- if (!operation) {
58457
- continue;
58458
- }
58459
- doc2.document = inlineFragmentArgs({
58460
- config: config2,
58461
- filepath: doc2.filename,
58462
- fragmentDefinitions: fragments,
58463
- document: doc2.document,
58464
- generatedFragments,
58465
- visitedFragments,
58466
- scope: null
58467
- });
58468
- }
58469
- const doc = {
58470
- kind: graphql22.Kind.DOCUMENT,
58471
- definitions: Object.values(generatedFragments)
58472
- };
58473
- documents.push({
58474
- name: "generated::fragmentVariables",
58475
- kind: "HoudiniFragment" /* Fragment */,
58476
- document: doc,
58477
- originalDocument: doc,
58478
- generateStore: false,
58479
- generateArtifact: false,
58480
- filename: "generated::fragmentVariables",
58481
- originalString: ""
58482
- });
58483
- }
58484
- function inlineFragmentArgs({
58485
- config: config2,
58486
- filepath,
58487
- fragmentDefinitions,
58488
- document,
58489
- generatedFragments,
58490
- visitedFragments,
58491
- scope,
58492
- newName
58493
- }) {
58494
- if (!scope) {
58495
- scope = operationScope(
58496
- document.definitions.find(
58497
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
58498
- )
58499
- );
58500
- }
58501
- const definitionArgs = fragmentArguments(
58502
- config2,
58503
- filepath,
58504
- document
58505
- ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
58506
- const result = graphql22.visit(document, {
58507
- FragmentSpread(node) {
58508
- const { definition } = fragmentDefinitions[node.name.value];
58509
- let { args, hash } = collectWithArguments(config2, filepath, node, scope);
58510
- const newFragmentName = `${node.name.value}${hash}`;
58511
- if (!visitedFragments.has(newFragmentName)) {
58512
- visitedFragments.add(newFragmentName);
58513
- const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
58514
- if (args) {
58515
- for (const [field, value] of Object.entries(defaultArguments || {})) {
58516
- if (!args[field]) {
58517
- args[field] = value;
58518
- }
58519
- }
58520
- generatedFragments[newFragmentName] = inlineFragmentArgs({
58521
- config: config2,
58522
- filepath,
58523
- fragmentDefinitions,
58524
- document: fragmentDefinitions[node.name.value].definition,
58525
- generatedFragments,
58526
- visitedFragments,
58527
- scope: args,
58528
- newName: newFragmentName
58529
- });
58530
- } else {
58531
- const doc = fragmentDefinitions[node.name.value].document;
58532
- const definitionIndex = doc.document.definitions.findIndex(
58533
- (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
58534
- );
58535
- const localDefinitions = [...doc.document.definitions];
58536
- localDefinitions.splice(definitionIndex, 1);
58537
- localDefinitions.push(
58538
- inlineFragmentArgs({
58539
- config: config2,
58540
- filepath,
58541
- fragmentDefinitions,
58542
- document: fragmentDefinitions[node.name.value].definition,
58543
- generatedFragments,
58544
- visitedFragments,
58545
- scope: defaultArguments,
58546
- newName: ""
58547
- })
58548
- );
58549
- doc.document = {
58550
- ...doc.document,
58551
- definitions: localDefinitions
58552
- };
58553
- }
58554
- if (node.name.value !== newFragmentName) {
58555
- return {
58556
- ...node,
58557
- name: {
58558
- kind: "Name",
58559
- value: newFragmentName
58560
- }
58561
- };
58562
- }
58563
- }
58564
- },
58565
- Argument(node) {
58566
- const value = node.value;
58567
- if (value.kind !== "Variable") {
58568
- return;
58569
- }
58570
- if (!scope) {
58571
- throw new HoudiniError({
58572
- filepath,
58573
- message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
58574
- });
58575
- }
58576
- const newValue = scope[value.name.value];
58577
- if (newValue) {
58578
- return {
58579
- ...node,
58580
- value: newValue
58581
- };
58582
- }
58583
- if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
58584
- throw new HoudiniError({
58585
- filepath,
58586
- message: "Missing value for required arg: " + value.name.value
58587
- });
58588
- }
58589
- return null;
58590
- }
58591
- });
58592
- if (newName) {
58593
- result.name = {
58594
- kind: graphql22.Kind.NAME,
58595
- value: newName
58596
- };
58597
- }
58598
- return result;
58599
- }
58600
- function withArguments(config2, node) {
58601
- const withDirectives = node.directives?.filter(
58602
- (directive) => directive.name.value === config2.withDirective
58603
- );
58604
- if (!withDirectives || withDirectives.length === 0) {
58605
- return [];
58606
- }
58607
- return withDirectives.flatMap((directive) => directive.arguments || []);
58608
- }
58609
- function fragmentArguments(config2, filepath, definition) {
58610
- const directives = definition.directives?.filter(
58611
- (directive) => directive.name.value === config2.argumentsDirective
58612
- );
58613
- if (!directives || directives.length === 0) {
58614
- return [];
58615
- }
58616
- return directives.flatMap(
58617
- (directive) => directive.arguments?.flatMap((arg) => {
58618
- if (arg.value.kind !== "ObjectValue") {
58619
- throw new HoudiniError({
58620
- filepath,
58621
- message: "values of @argument must be objects"
58622
- });
58623
- }
58624
- const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
58625
- if (!typeArg || typeArg.kind !== "StringValue") {
58626
- return [];
58627
- }
58628
- let type = typeArg.value;
58629
- let name2 = arg.name.value;
58630
- let required = false;
58631
- let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
58632
- if (type[type.length - 1] === "!") {
58633
- type = type.slice(0, -1);
58634
- required = true;
58635
- defaultValue = null;
58636
- }
58637
- return [
58638
- {
58639
- name: name2,
58640
- type,
58641
- required,
58642
- defaultValue
58643
- }
58644
- ];
58645
- }) || []
58646
- );
58647
- }
58648
- function collectDefaultArgumentValues(config2, filepath, definition) {
58649
- let result = {};
58650
- for (const { name: name2, required, defaultValue } of fragmentArguments(
58651
- config2,
58652
- filepath,
58653
- definition
58654
- )) {
58655
- if (required || !defaultValue) {
58656
- continue;
58657
- }
58658
- result[name2] = defaultValue;
58659
- }
58660
- return result;
58661
- }
58662
- function collectWithArguments(config2, filepath, node, scope = {}) {
58663
- const withArgs = withArguments(config2, node);
58664
- if (withArgs.length === 0) {
58665
- return { args: null, hash: "" };
58666
- }
58667
- let args = {};
58668
- for (const arg of withArgs) {
58669
- let value = arg.value;
58670
- if (value.kind === GraphqlKinds2.VARIABLE) {
58671
- if (!scope || !scope[value.name.value]) {
58672
- throw new HoudiniError({
58673
- filepath,
58674
- message: "Encountered undefined variable: " + value.name.value
58675
- });
58676
- }
58677
- value = scope[value.name.value];
58678
- }
58679
- args[arg.name.value] = {
58680
- ...value,
58681
- loc: void 0
58682
- };
58683
- }
58684
- return {
58685
- args,
58686
- hash: "_" + murmurHash(JSON.stringify(args))
58687
- };
58688
- }
58689
- function operationScope(operation) {
58690
- return operation.variableDefinitions?.reduce(
58691
- (scope, definition) => ({
58692
- ...scope,
58693
- [definition.variable.name.value]: {
58694
- kind: "Variable",
58695
- name: {
58696
- kind: "Name",
58697
- value: definition.variable.name.value
58698
- }
58699
- }
58700
- }),
58701
- {}
58702
- ) || {};
58703
- }
58704
-
58705
58889
  // src/codegen/validators/typeCheck.ts
58706
58890
  var graphql23 = __toESM(require_graphql2(), 1);
58707
58891
  async function typeCheck(config2, docs) {
@@ -59881,7 +60065,6 @@ function testConfigFile({ plugins, ...config2 } = {}) {
59881
60065
  }
59882
60066
  }
59883
60067
  },
59884
- framework: "kit",
59885
60068
  types: {
59886
60069
  Ghost: {
59887
60070
  keys: ["name", "aka"],