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
@@ -69857,8 +69857,7 @@ var Config = class {
69857
69857
  types: types16 = {},
69858
69858
  logLevel,
69859
69859
  defaultFragmentMasking = "enable",
69860
- schemaPollInterval = 2e3,
69861
- schemaPollHeaders = {},
69860
+ watchSchema,
69862
69861
  projectDir
69863
69862
  } = this.configFile;
69864
69863
  if (typeof schema === "string") {
@@ -69891,8 +69890,8 @@ var Config = class {
69891
69890
  this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
69892
69891
  this.defaultFragmentMasking = defaultFragmentMasking;
69893
69892
  this.routesDir = join2(this.projectRoot, "src", "routes");
69894
- this.schemaPollInterval = schemaPollInterval;
69895
- this.schemaPollHeaders = schemaPollHeaders;
69893
+ this.schemaPollInterval = watchSchema?.interval ?? 2e3;
69894
+ this.schemaPollHeaders = watchSchema?.headers ?? {};
69896
69895
  this.rootDir = join2(this.projectRoot, "$houdini");
69897
69896
  if (defaultKeys) {
69898
69897
  this.defaultKeys = defaultKeys;
@@ -69905,11 +69904,12 @@ var Config = class {
69905
69904
  }
69906
69905
  }
69907
69906
  async apiURL() {
69908
- if (!this.configFile.apiUrl) {
69907
+ const apiURL = this.configFile.watchSchema?.url;
69908
+ if (!apiURL) {
69909
69909
  return "";
69910
69910
  }
69911
69911
  const env = await this.getEnv();
69912
- return this.processEnvValues(env, this.configFile.apiUrl);
69912
+ return this.processEnvValues(env, apiURL);
69913
69913
  }
69914
69914
  get include() {
69915
69915
  if (this.configFile.include) {
@@ -70113,8 +70113,8 @@ var Config = class {
70113
70113
  pluginDirectory(name2) {
70114
70114
  return join2(this.pluginRootDirectory, name2);
70115
70115
  }
70116
- get manualLoadDirective() {
70117
- return "manual_load";
70116
+ get loadDirective() {
70117
+ return "load";
70118
70118
  }
70119
70119
  get maskEnableDirective() {
70120
70120
  return "mask_enable";
@@ -70231,7 +70231,7 @@ var Config = class {
70231
70231
  this.withDirective,
70232
70232
  this.paginateDirective,
70233
70233
  this.cacheDirective,
70234
- this.manualLoadDirective,
70234
+ this.loadDirective,
70235
70235
  this.maskEnableDirective,
70236
70236
  this.maskDisableDirective
70237
70237
  ].includes(name2.value) || this.isDeleteDirective(name2.value);
@@ -70820,7 +70820,7 @@ async function find_graphql(config2, parsedScript, walker) {
70820
70820
  return;
70821
70821
  }
70822
70822
  const parsedTag = graphql4.parse(documentString);
70823
- if (walker.where && !walker.where(parsedTag)) {
70823
+ if (walker.where && !walker.where(parsedTag, { node, parent })) {
70824
70824
  return;
70825
70825
  }
70826
70826
  const definition = config2.extractDefinition(parsedTag);
@@ -70864,7 +70864,7 @@ async function find_graphql(config2, parsedScript, walker) {
70864
70864
  var graphql27 = __toESM(require_graphql2(), 1);
70865
70865
 
70866
70866
  // src/codegen/generators/artifacts/index.ts
70867
- var graphql13 = __toESM(require_graphql2(), 1);
70867
+ var graphql14 = __toESM(require_graphql2(), 1);
70868
70868
  var recast5 = __toESM(require_main2(), 1);
70869
70869
 
70870
70870
  // src/codegen/utils/commonjs.ts
@@ -71122,159 +71122,534 @@ function murmurHash(str) {
71122
71122
  return s2;
71123
71123
  }
71124
71124
 
71125
- // src/codegen/generators/artifacts/indexFile.ts
71126
- async function writeIndexFile(config2, docs) {
71127
- const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
71128
- let body = config2.module === "esm" ? docsToGenerate.reduce(
71129
- (content, doc) => content + `
71130
- export { default as ${doc.name}} from './${doc.name}'`,
71131
- ""
71132
- ) : docsToGenerate.reduce(
71133
- (content, doc) => content + `
71134
- ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
71135
- cjsIndexFilePreamble
71136
- );
71137
- await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
71138
- }
71139
-
71140
- // src/codegen/generators/artifacts/inputs.ts
71125
+ // src/codegen/transforms/fragmentVariables.ts
71141
71126
  var graphql5 = __toESM(require_graphql2(), 1);
71142
- var recast3 = __toESM(require_main2(), 1);
71143
- var AST3 = recast3.types.builders;
71144
- function inputObject(config2, inputs) {
71145
- const visitedTypes = /* @__PURE__ */ new Set();
71146
- const inputObj = {
71147
- fields: inputs.reduce((fields, input) => {
71148
- const { type } = unwrapType(config2, input.type);
71149
- return {
71150
- ...fields,
71151
- [input.variable.name.value]: type.name
71152
- };
71153
- }, {}),
71154
- types: {}
71155
- };
71156
- for (const input of inputs) {
71157
- walkInputs(config2, visitedTypes, inputObj, input.type);
71158
- }
71159
- return inputObj;
71160
- }
71161
- function walkInputs(config2, visitedTypes, inputObj, rootType) {
71162
- const { type } = unwrapType(config2, rootType);
71163
- if (visitedTypes.has(type.name)) {
71164
- return;
71165
- }
71166
- if (graphql5.isEnumType(type) || graphql5.isScalarType(type)) {
71167
- return;
71168
- }
71169
- if (graphql5.isUnionType(type)) {
71170
- return;
71171
- }
71172
- visitedTypes.add(type.name);
71173
- inputObj.types[type.name] = Object.values(type.getFields()).reduce(
71174
- (typeFields, field) => {
71175
- const { type: fieldType } = unwrapType(config2, field.type);
71176
- walkInputs(config2, visitedTypes, inputObj, fieldType);
71177
- return {
71178
- ...typeFields,
71179
- [field.name]: fieldType.toString()
71180
- };
71181
- },
71182
- {}
71183
- );
71184
- }
71185
71127
 
71186
- // src/codegen/generators/artifacts/operations.ts
71187
- var graphql7 = __toESM(require_graphql2(), 1);
71188
-
71189
- // src/codegen/generators/artifacts/utils.ts
71190
- var graphql6 = __toESM(require_graphql2(), 1);
71191
- var recast4 = __toESM(require_main2(), 1);
71192
- var AST4 = recast4.types.builders;
71193
- function serializeValue(value) {
71194
- if (Array.isArray(value)) {
71195
- return AST4.arrayExpression(value.map(serializeValue));
71128
+ // src/codegen/transforms/composeQueries.ts
71129
+ var import_graphql30 = __toESM(require_graphql2(), 1);
71130
+ async function includeFragmentDefinitions(config2, documents) {
71131
+ const fragments = collectFragments(config2, documents);
71132
+ for (const [index, { name: name2, document, filename }] of documents.entries()) {
71133
+ const operation = document.definitions.find(
71134
+ ({ kind }) => kind === import_graphql30.Kind.OPERATION_DEFINITION
71135
+ );
71136
+ if (!operation) {
71137
+ continue;
71138
+ }
71139
+ const allFragments = flattenFragments(
71140
+ filename,
71141
+ { requiredFragments: findRequiredFragments(operation.selectionSet) },
71142
+ fragments
71143
+ );
71144
+ documents[index].document = {
71145
+ ...document,
71146
+ definitions: [
71147
+ operation,
71148
+ ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
71149
+ ]
71150
+ };
71196
71151
  }
71197
- if (typeof value === "object" && value !== null) {
71198
- return AST4.objectExpression(
71199
- Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
71200
- ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
71201
- )
71152
+ }
71153
+ function collectFragments(config2, docs) {
71154
+ return docs.reduce((acc, doc) => {
71155
+ const definitions = doc.document.definitions.reduce(
71156
+ (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
71157
+ ...prev,
71158
+ [definition.name.value]: {
71159
+ definition,
71160
+ requiredFragments: findRequiredFragments(definition.selectionSet),
71161
+ document: doc
71162
+ }
71163
+ },
71164
+ {}
71202
71165
  );
71166
+ return {
71167
+ ...acc,
71168
+ ...definitions
71169
+ };
71170
+ }, {});
71171
+ }
71172
+ function findRequiredFragments(selectionSet) {
71173
+ if (selectionSet.selections.length === 0) {
71174
+ return [];
71203
71175
  }
71204
- if (typeof value === "string") {
71205
- if (value.indexOf("\n") !== -1) {
71206
- return AST4.templateLiteral(
71207
- [AST4.templateElement({ raw: value, cooked: value }, true)],
71208
- []
71209
- );
71176
+ const referencedFragments = [];
71177
+ for (const selection2 of selectionSet.selections) {
71178
+ if (selection2.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
71179
+ referencedFragments.push(selection2.name.value);
71180
+ } else if (selection2.selectionSet) {
71181
+ referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
71210
71182
  }
71211
- return AST4.stringLiteral(value);
71212
71183
  }
71213
- return AST4.literal(value);
71184
+ return referencedFragments;
71214
71185
  }
71215
- function deepMerge(filepath, ...targets) {
71216
- if (typeof targets[0] !== "object") {
71217
- const matches = targets.filter((val) => val !== targets[0]).length === 0;
71218
- if (!matches) {
71219
- throw new HoudiniError({ filepath, message: "could not merge: " + targets });
71186
+ function flattenFragments(filepath, operation, fragments) {
71187
+ const frags = /* @__PURE__ */ new Set();
71188
+ const remaining = [...operation.requiredFragments];
71189
+ while (remaining.length > 0) {
71190
+ const nextFragment = remaining.shift();
71191
+ if (!nextFragment) {
71192
+ continue;
71220
71193
  }
71221
- return targets[0];
71222
- }
71223
- if (Array.isArray(targets[0])) {
71224
- return targets[0].concat(...targets.slice(1));
71225
- }
71226
- const fields = {};
71227
- for (const target of targets) {
71228
- for (const [key, value] of Object.entries(target)) {
71229
- if (!fields[key]) {
71230
- fields[key] = [];
71231
- }
71232
- fields[key].push(value);
71194
+ if (!frags.has(nextFragment)) {
71195
+ frags.add(nextFragment);
71196
+ } else {
71197
+ continue;
71198
+ }
71199
+ const targetFragment = fragments[nextFragment];
71200
+ if (!targetFragment) {
71201
+ throw new HoudiniError({
71202
+ filepath,
71203
+ message: "compose: could not find definition for fragment " + nextFragment
71204
+ });
71233
71205
  }
71206
+ remaining.push(...targetFragment.requiredFragments);
71234
71207
  }
71235
- return Object.fromEntries(
71236
- Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
71237
- );
71208
+ return [...frags];
71238
71209
  }
71239
- function convertValue(config2, val) {
71240
- let value;
71241
- let kind;
71242
- if (val.kind === graphql6.Kind.INT) {
71243
- value = parseInt(val.value, 10);
71244
- kind = "Int";
71245
- } else if (val.kind === graphql6.Kind.FLOAT) {
71246
- value = parseFloat(val.value);
71247
- kind = "Float";
71248
- } else if (val.kind === graphql6.Kind.BOOLEAN) {
71249
- value = val.value;
71250
- kind = "Boolean";
71251
- } else if (val.kind === graphql6.Kind.VARIABLE) {
71252
- value = val.name.value;
71253
- kind = "Variable";
71254
- } else if (val.kind === graphql6.Kind.STRING) {
71255
- value = val.value;
71256
- kind = "String";
71210
+
71211
+ // src/codegen/transforms/fragmentVariables.ts
71212
+ var GraphqlKinds2 = graphql5.Kind;
71213
+ async function fragmentVariables(config2, documents) {
71214
+ const fragments = collectFragments(config2, documents);
71215
+ const generatedFragments = {};
71216
+ const visitedFragments = /* @__PURE__ */ new Set();
71217
+ for (const doc2 of documents) {
71218
+ const operation = doc2.document.definitions.find(
71219
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
71220
+ );
71221
+ if (!operation) {
71222
+ continue;
71223
+ }
71224
+ doc2.document = inlineFragmentArgs({
71225
+ config: config2,
71226
+ filepath: doc2.filename,
71227
+ fragmentDefinitions: fragments,
71228
+ document: doc2.document,
71229
+ generatedFragments,
71230
+ visitedFragments,
71231
+ scope: null
71232
+ });
71257
71233
  }
71258
- return { kind, value };
71234
+ const doc = {
71235
+ kind: graphql5.Kind.DOCUMENT,
71236
+ definitions: Object.values(generatedFragments)
71237
+ };
71238
+ documents.push({
71239
+ name: "generated::fragmentVariables",
71240
+ kind: "HoudiniFragment" /* Fragment */,
71241
+ document: doc,
71242
+ originalDocument: doc,
71243
+ generateStore: false,
71244
+ generateArtifact: false,
71245
+ filename: "generated::fragmentVariables",
71246
+ originalString: ""
71247
+ });
71259
71248
  }
71260
-
71261
- // src/codegen/generators/artifacts/operations.ts
71262
- function operationsByPath(config2, filepath, definition, filterTypes) {
71263
- if (!definition) {
71264
- return {};
71249
+ function inlineFragmentArgs({
71250
+ config: config2,
71251
+ filepath,
71252
+ fragmentDefinitions,
71253
+ document,
71254
+ generatedFragments,
71255
+ visitedFragments,
71256
+ scope,
71257
+ newName
71258
+ }) {
71259
+ if (!scope) {
71260
+ scope = operationScope(
71261
+ document.definitions.find(
71262
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
71263
+ )
71264
+ );
71265
71265
  }
71266
- const pathOperations = {};
71267
- graphql7.visit(definition, {
71268
- FragmentSpread(node, _, __, ___, ancestors) {
71269
- if (!config2.isListFragment(node.name.value)) {
71270
- return;
71271
- }
71272
- const path2 = ancestorKey(ancestors);
71273
- if (!pathOperations[path2]) {
71274
- pathOperations[path2] = [];
71275
- }
71276
- pathOperations[path2].push(
71277
- operationObject({
71266
+ const definitionArgs = fragmentArguments(
71267
+ config2,
71268
+ filepath,
71269
+ document
71270
+ ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
71271
+ const result = graphql5.visit(document, {
71272
+ FragmentSpread(node) {
71273
+ const { definition } = fragmentDefinitions[node.name.value];
71274
+ let { args, hash } = collectWithArguments(config2, filepath, node, scope);
71275
+ const newFragmentName = `${node.name.value}${hash}`;
71276
+ if (!visitedFragments.has(newFragmentName)) {
71277
+ visitedFragments.add(newFragmentName);
71278
+ const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
71279
+ if (args) {
71280
+ for (const [field, value] of Object.entries(defaultArguments || {})) {
71281
+ if (!args[field]) {
71282
+ args[field] = value;
71283
+ }
71284
+ }
71285
+ generatedFragments[newFragmentName] = inlineFragmentArgs({
71286
+ config: config2,
71287
+ filepath,
71288
+ fragmentDefinitions,
71289
+ document: fragmentDefinitions[node.name.value].definition,
71290
+ generatedFragments,
71291
+ visitedFragments,
71292
+ scope: args,
71293
+ newName: newFragmentName
71294
+ });
71295
+ } else {
71296
+ const doc = fragmentDefinitions[node.name.value].document;
71297
+ const definitionIndex = doc.document.definitions.findIndex(
71298
+ (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
71299
+ );
71300
+ const localDefinitions = [...doc.document.definitions];
71301
+ localDefinitions.splice(definitionIndex, 1);
71302
+ localDefinitions.push(
71303
+ inlineFragmentArgs({
71304
+ config: config2,
71305
+ filepath,
71306
+ fragmentDefinitions,
71307
+ document: fragmentDefinitions[node.name.value].definition,
71308
+ generatedFragments,
71309
+ visitedFragments,
71310
+ scope: defaultArguments,
71311
+ newName: ""
71312
+ })
71313
+ );
71314
+ doc.document = {
71315
+ ...doc.document,
71316
+ definitions: localDefinitions
71317
+ };
71318
+ }
71319
+ if (node.name.value !== newFragmentName) {
71320
+ return {
71321
+ ...node,
71322
+ name: {
71323
+ kind: "Name",
71324
+ value: newFragmentName
71325
+ }
71326
+ };
71327
+ }
71328
+ }
71329
+ },
71330
+ Argument(node) {
71331
+ const value = node.value;
71332
+ if (value.kind !== "Variable") {
71333
+ return;
71334
+ }
71335
+ if (!scope) {
71336
+ throw new HoudiniError({
71337
+ filepath,
71338
+ message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
71339
+ });
71340
+ }
71341
+ const newValue = scope[value.name.value];
71342
+ if (newValue) {
71343
+ return {
71344
+ ...node,
71345
+ value: newValue
71346
+ };
71347
+ }
71348
+ if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
71349
+ throw new HoudiniError({
71350
+ filepath,
71351
+ message: "Missing value for required arg: " + value.name.value
71352
+ });
71353
+ }
71354
+ return null;
71355
+ }
71356
+ });
71357
+ if (newName) {
71358
+ result.name = {
71359
+ kind: graphql5.Kind.NAME,
71360
+ value: newName
71361
+ };
71362
+ }
71363
+ return result;
71364
+ }
71365
+ function withArguments(config2, node) {
71366
+ const withDirectives = node.directives?.filter(
71367
+ (directive) => directive.name.value === config2.withDirective
71368
+ );
71369
+ if (!withDirectives || withDirectives.length === 0) {
71370
+ return [];
71371
+ }
71372
+ return withDirectives.flatMap((directive) => directive.arguments || []);
71373
+ }
71374
+ function fragmentArguments(config2, filepath, definition) {
71375
+ const directives = definition.directives?.filter(
71376
+ (directive) => directive.name.value === config2.argumentsDirective
71377
+ );
71378
+ if (!directives || directives.length === 0) {
71379
+ return [];
71380
+ }
71381
+ return directives.flatMap(
71382
+ (directive) => directive.arguments?.flatMap((arg) => {
71383
+ if (arg.value.kind !== "ObjectValue") {
71384
+ throw new HoudiniError({
71385
+ filepath,
71386
+ message: "values of @argument must be objects"
71387
+ });
71388
+ }
71389
+ const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
71390
+ if (!typeArg || typeArg.kind !== "StringValue") {
71391
+ return [];
71392
+ }
71393
+ let type = typeArg.value;
71394
+ let name2 = arg.name.value;
71395
+ let required = false;
71396
+ let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
71397
+ if (type[type.length - 1] === "!") {
71398
+ type = type.slice(0, -1);
71399
+ required = true;
71400
+ defaultValue = null;
71401
+ }
71402
+ return [
71403
+ {
71404
+ name: name2,
71405
+ type,
71406
+ required,
71407
+ defaultValue
71408
+ }
71409
+ ];
71410
+ }) || []
71411
+ );
71412
+ }
71413
+ function collectDefaultArgumentValues(config2, filepath, definition) {
71414
+ let result = {};
71415
+ for (const { name: name2, required, defaultValue } of fragmentArguments(
71416
+ config2,
71417
+ filepath,
71418
+ definition
71419
+ )) {
71420
+ if (required || !defaultValue) {
71421
+ continue;
71422
+ }
71423
+ result[name2] = defaultValue;
71424
+ }
71425
+ return result;
71426
+ }
71427
+ function collectWithArguments(config2, filepath, node, scope = {}) {
71428
+ const withArgs = withArguments(config2, node);
71429
+ if (withArgs.length === 0) {
71430
+ return { args: null, hash: "" };
71431
+ }
71432
+ let args = {};
71433
+ for (const arg of withArgs) {
71434
+ let value = arg.value;
71435
+ if (value.kind === GraphqlKinds2.VARIABLE) {
71436
+ if (!scope || !scope[value.name.value]) {
71437
+ throw new HoudiniError({
71438
+ filepath,
71439
+ message: "Encountered undefined variable: " + value.name.value
71440
+ });
71441
+ }
71442
+ value = scope[value.name.value];
71443
+ }
71444
+ args[arg.name.value] = {
71445
+ ...value,
71446
+ loc: void 0
71447
+ };
71448
+ }
71449
+ return {
71450
+ args,
71451
+ hash: "_" + murmurHash(JSON.stringify(args))
71452
+ };
71453
+ }
71454
+ function operationScope(operation) {
71455
+ return operation.variableDefinitions?.reduce(
71456
+ (scope, definition) => ({
71457
+ ...scope,
71458
+ [definition.variable.name.value]: {
71459
+ kind: "Variable",
71460
+ name: {
71461
+ kind: "Name",
71462
+ value: definition.variable.name.value
71463
+ }
71464
+ }
71465
+ }),
71466
+ {}
71467
+ ) || {};
71468
+ }
71469
+ function fragmentArgumentsDefinitions(config2, filepath, definition) {
71470
+ const args = fragmentArguments(config2, filepath, definition);
71471
+ if (args.length === 0) {
71472
+ return [];
71473
+ }
71474
+ return args.map((arg) => {
71475
+ const innerType = {
71476
+ kind: "NamedType",
71477
+ name: {
71478
+ kind: "Name",
71479
+ value: arg.type
71480
+ }
71481
+ };
71482
+ return {
71483
+ kind: "VariableDefinition",
71484
+ type: arg.required ? innerType : {
71485
+ kind: "NonNullType",
71486
+ type: innerType
71487
+ },
71488
+ variable: {
71489
+ kind: "Variable",
71490
+ name: {
71491
+ kind: "Name",
71492
+ value: arg.name
71493
+ }
71494
+ },
71495
+ defaultValue: arg.defaultValue ?? void 0
71496
+ };
71497
+ });
71498
+ }
71499
+
71500
+ // src/codegen/generators/artifacts/indexFile.ts
71501
+ async function writeIndexFile(config2, docs) {
71502
+ const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
71503
+ let body = config2.module === "esm" ? docsToGenerate.reduce(
71504
+ (content, doc) => content + `
71505
+ export { default as ${doc.name}} from './${doc.name}'`,
71506
+ ""
71507
+ ) : docsToGenerate.reduce(
71508
+ (content, doc) => content + `
71509
+ ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
71510
+ cjsIndexFilePreamble
71511
+ );
71512
+ await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
71513
+ }
71514
+
71515
+ // src/codegen/generators/artifacts/inputs.ts
71516
+ var graphql6 = __toESM(require_graphql2(), 1);
71517
+ var recast3 = __toESM(require_main2(), 1);
71518
+ var AST3 = recast3.types.builders;
71519
+ function inputObject(config2, inputs) {
71520
+ const visitedTypes = /* @__PURE__ */ new Set();
71521
+ const inputObj = {
71522
+ fields: inputs.reduce((fields, input) => {
71523
+ const { type } = unwrapType(config2, input.type);
71524
+ return {
71525
+ ...fields,
71526
+ [input.variable.name.value]: type.name
71527
+ };
71528
+ }, {}),
71529
+ types: {}
71530
+ };
71531
+ for (const input of inputs) {
71532
+ walkInputs(config2, visitedTypes, inputObj, input.type);
71533
+ }
71534
+ return inputObj;
71535
+ }
71536
+ function walkInputs(config2, visitedTypes, inputObj, rootType) {
71537
+ const { type } = unwrapType(config2, rootType);
71538
+ if (visitedTypes.has(type.name)) {
71539
+ return;
71540
+ }
71541
+ if (graphql6.isEnumType(type) || graphql6.isScalarType(type)) {
71542
+ return;
71543
+ }
71544
+ if (graphql6.isUnionType(type)) {
71545
+ return;
71546
+ }
71547
+ visitedTypes.add(type.name);
71548
+ inputObj.types[type.name] = Object.values(type.getFields()).reduce(
71549
+ (typeFields, field) => {
71550
+ const { type: fieldType } = unwrapType(config2, field.type);
71551
+ walkInputs(config2, visitedTypes, inputObj, fieldType);
71552
+ return {
71553
+ ...typeFields,
71554
+ [field.name]: fieldType.toString()
71555
+ };
71556
+ },
71557
+ {}
71558
+ );
71559
+ }
71560
+
71561
+ // src/codegen/generators/artifacts/operations.ts
71562
+ var graphql8 = __toESM(require_graphql2(), 1);
71563
+
71564
+ // src/codegen/generators/artifacts/utils.ts
71565
+ var graphql7 = __toESM(require_graphql2(), 1);
71566
+ var recast4 = __toESM(require_main2(), 1);
71567
+ var AST4 = recast4.types.builders;
71568
+ function serializeValue(value) {
71569
+ if (Array.isArray(value)) {
71570
+ return AST4.arrayExpression(value.map(serializeValue));
71571
+ }
71572
+ if (typeof value === "object" && value !== null) {
71573
+ return AST4.objectExpression(
71574
+ Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
71575
+ ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
71576
+ )
71577
+ );
71578
+ }
71579
+ if (typeof value === "string") {
71580
+ if (value.indexOf("\n") !== -1) {
71581
+ return AST4.templateLiteral(
71582
+ [AST4.templateElement({ raw: value, cooked: value }, true)],
71583
+ []
71584
+ );
71585
+ }
71586
+ return AST4.stringLiteral(value);
71587
+ }
71588
+ return AST4.literal(value);
71589
+ }
71590
+ function deepMerge(filepath, ...targets) {
71591
+ if (typeof targets[0] !== "object") {
71592
+ const matches = targets.filter((val) => val !== targets[0]).length === 0;
71593
+ if (!matches) {
71594
+ throw new HoudiniError({ filepath, message: "could not merge: " + targets });
71595
+ }
71596
+ return targets[0];
71597
+ }
71598
+ if (Array.isArray(targets[0])) {
71599
+ return targets[0].concat(...targets.slice(1));
71600
+ }
71601
+ const fields = {};
71602
+ for (const target of targets) {
71603
+ for (const [key, value] of Object.entries(target)) {
71604
+ if (!fields[key]) {
71605
+ fields[key] = [];
71606
+ }
71607
+ fields[key].push(value);
71608
+ }
71609
+ }
71610
+ return Object.fromEntries(
71611
+ Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
71612
+ );
71613
+ }
71614
+ function convertValue(config2, val) {
71615
+ let value;
71616
+ let kind;
71617
+ if (val.kind === graphql7.Kind.INT) {
71618
+ value = parseInt(val.value, 10);
71619
+ kind = "Int";
71620
+ } else if (val.kind === graphql7.Kind.FLOAT) {
71621
+ value = parseFloat(val.value);
71622
+ kind = "Float";
71623
+ } else if (val.kind === graphql7.Kind.BOOLEAN) {
71624
+ value = val.value;
71625
+ kind = "Boolean";
71626
+ } else if (val.kind === graphql7.Kind.VARIABLE) {
71627
+ value = val.name.value;
71628
+ kind = "Variable";
71629
+ } else if (val.kind === graphql7.Kind.STRING) {
71630
+ value = val.value;
71631
+ kind = "String";
71632
+ }
71633
+ return { kind, value };
71634
+ }
71635
+
71636
+ // src/codegen/generators/artifacts/operations.ts
71637
+ function operationsByPath(config2, filepath, definition, filterTypes) {
71638
+ if (!definition) {
71639
+ return {};
71640
+ }
71641
+ const pathOperations = {};
71642
+ graphql8.visit(definition, {
71643
+ FragmentSpread(node, _, __, ___, ancestors) {
71644
+ if (!config2.isListFragment(node.name.value)) {
71645
+ return;
71646
+ }
71647
+ const path2 = ancestorKey(ancestors);
71648
+ if (!pathOperations[path2]) {
71649
+ pathOperations[path2] = [];
71650
+ }
71651
+ pathOperations[path2].push(
71652
+ operationObject({
71278
71653
  config: config2,
71279
71654
  filepath,
71280
71655
  listName: config2.listNameFromFragment(node.name.value),
@@ -71423,7 +71798,7 @@ function ancestorKey(ancestors) {
71423
71798
  }
71424
71799
 
71425
71800
  // src/codegen/generators/artifacts/selection.ts
71426
- var graphql12 = __toESM(require_graphql2(), 1);
71801
+ var graphql13 = __toESM(require_graphql2(), 1);
71427
71802
 
71428
71803
  // ../../node_modules/.pnpm/@kitql+helper@0.5.0/node_modules/@kitql/helper/index.mjs
71429
71804
  var config = {
@@ -71463,16 +71838,16 @@ function logYellow(str) {
71463
71838
  }
71464
71839
 
71465
71840
  // src/codegen/transforms/list.ts
71466
- var graphql10 = __toESM(require_graphql2(), 1);
71841
+ var graphql11 = __toESM(require_graphql2(), 1);
71467
71842
 
71468
71843
  // src/codegen/utils/objectIdentificationSelection.ts
71469
- var graphql8 = __toESM(require_graphql2(), 1);
71844
+ var graphql9 = __toESM(require_graphql2(), 1);
71470
71845
  var objectIdentificationSelection = (config2, type) => {
71471
71846
  return config2.keyFieldsForType(type.name).map((key) => {
71472
71847
  return {
71473
- kind: graphql8.Kind.FIELD,
71848
+ kind: graphql9.Kind.FIELD,
71474
71849
  name: {
71475
- kind: graphql8.Kind.NAME,
71850
+ kind: graphql9.Kind.NAME,
71476
71851
  value: key
71477
71852
  }
71478
71853
  };
@@ -71480,7 +71855,7 @@ var objectIdentificationSelection = (config2, type) => {
71480
71855
  };
71481
71856
 
71482
71857
  // src/codegen/transforms/paginate.ts
71483
- var graphql9 = __toESM(require_graphql2(), 1);
71858
+ var graphql10 = __toESM(require_graphql2(), 1);
71484
71859
  async function paginate(config2, documents) {
71485
71860
  const newDocs = [];
71486
71861
  for (const doc of documents) {
@@ -71513,7 +71888,7 @@ async function paginate(config2, documents) {
71513
71888
  };
71514
71889
  let cursorType = "String";
71515
71890
  let paginationPath = [];
71516
- doc.document = graphql9.visit(doc.document, {
71891
+ doc.document = graphql10.visit(doc.document, {
71517
71892
  Field(node, _, __, ___, ancestors) {
71518
71893
  const paginateDirective = node.directives?.find(
71519
71894
  (directive) => directive.name.value === config2.paginateDirective
@@ -71524,23 +71899,22 @@ async function paginate(config2, documents) {
71524
71899
  paginated = true;
71525
71900
  const fieldTypeFields = parentTypeFromAncestors(config2.schema, doc.filename, ancestors).getFields()[node.name.value];
71526
71901
  const args = new Set(fieldTypeFields.args.map((arg) => arg.name));
71527
- const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
71528
- const specifiedForwards = passedArgs.has("first");
71529
- const specifiedBackwards = passedArgs.has("last");
71530
71902
  cursorType = fieldTypeFields.args?.find((arg) => ["before", "after"].includes(arg.name))?.type?.name || "String";
71531
71903
  flags.after.type = cursorType;
71532
71904
  flags.before.type = cursorType;
71533
- const forwardPagination = !specifiedBackwards && args.has("first") && args.has("after");
71534
- const backwardsPagination = !specifiedForwards && args.has("last") && args.has("before");
71535
- const offsetPagination = !forwardPagination && !backwardsPagination && args.has("offset") && args.has("limit");
71536
- flags.first.enabled = forwardPagination;
71537
- flags.after.enabled = forwardPagination;
71538
- flags.last.enabled = backwardsPagination;
71539
- flags.before.enabled = backwardsPagination;
71905
+ const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
71906
+ const forwards = args.has("first") && args.has("after");
71907
+ const backwards = args.has("last") && args.has("after");
71908
+ const cursorPagination = passedArgs.has("last") || passedArgs.has("first");
71909
+ const offsetPagination = !cursorPagination && args.has("offset") && args.has("limit");
71910
+ flags.first.enabled = forwards;
71911
+ flags.after.enabled = forwards;
71912
+ flags.last.enabled = backwards;
71913
+ flags.before.enabled = backwards;
71540
71914
  flags.offset.enabled = offsetPagination;
71541
71915
  flags.limit.enabled = offsetPagination;
71542
71916
  paginationPath = ancestors.filter(
71543
- (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql9.Kind.FIELD
71917
+ (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql10.Kind.FIELD
71544
71918
  ).concat(node).map((field) => field.alias?.value || field.name.value);
71545
71919
  return {
71546
71920
  ...node,
@@ -71556,12 +71930,8 @@ async function paginate(config2, documents) {
71556
71930
  let fragmentName = "";
71557
71931
  let refetchQueryName = "";
71558
71932
  let nodeQuery = false;
71559
- let refetchUpdate = "append" /* append */;
71560
- if (flags.last.enabled) {
71561
- refetchUpdate = "prepend" /* prepend */;
71562
- }
71563
71933
  let fragment = "";
71564
- doc.document = graphql9.visit(doc.document, {
71934
+ doc.document = graphql10.visit(doc.document, {
71565
71935
  OperationDefinition(node) {
71566
71936
  if (node.operation !== "query") {
71567
71937
  throw new HoudiniError({
@@ -71615,9 +71985,9 @@ async function paginate(config2, documents) {
71615
71985
  directives: [
71616
71986
  ...node.directives || [],
71617
71987
  {
71618
- kind: graphql9.Kind.DIRECTIVE,
71988
+ kind: graphql10.Kind.DIRECTIVE,
71619
71989
  name: {
71620
- kind: graphql9.Kind.NAME,
71990
+ kind: graphql10.Kind.NAME,
71621
71991
  value: config2.argumentsDirective
71622
71992
  }
71623
71993
  }
@@ -71654,42 +72024,40 @@ async function paginate(config2, documents) {
71654
72024
  targetType = fragment;
71655
72025
  }
71656
72026
  }
72027
+ const pageSize = flags.first.defaultValue ?? flags.last.defaultValue ?? flags.limit.defaultValue;
72028
+ const start = flags.after.defaultValue ?? flags.before.defaultValue ?? flags.offset.defaultValue;
72029
+ let direction = "forward";
72030
+ if (flags.before.enabled && flags.after.enabled) {
72031
+ direction = "both";
72032
+ } else if (flags.before.enabled) {
72033
+ direction = "backward";
72034
+ }
71657
72035
  doc.refetch = {
71658
- update: refetchUpdate,
71659
72036
  path: paginationPath,
71660
72037
  method: flags.first.enabled || flags.last.enabled ? "cursor" : "offset",
71661
- pageSize: 0,
72038
+ pageSize,
71662
72039
  embedded: nodeQuery,
71663
72040
  targetType,
71664
72041
  paginated: true,
71665
- direction: flags.last.enabled ? "backwards" : "forward"
71666
- };
71667
- if (flags.first.enabled) {
71668
- doc.refetch.pageSize = flags.first.defaultValue;
71669
- doc.refetch.start = flags.after.defaultValue;
71670
- } else if (flags.last.enabled) {
71671
- doc.refetch.pageSize = flags.last.defaultValue;
71672
- doc.refetch.start = flags.before.defaultValue;
71673
- } else if (flags.limit.enabled) {
71674
- doc.refetch.pageSize = flags.limit.defaultValue;
71675
- doc.refetch.start = flags.offset.defaultValue;
71676
- }
72042
+ direction,
72043
+ start
72044
+ };
71677
72045
  if (!fragment) {
71678
72046
  continue;
71679
72047
  }
71680
72048
  const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
71681
72049
  const fragmentSpreadSelection = [
71682
72050
  {
71683
- kind: graphql9.Kind.FRAGMENT_SPREAD,
72051
+ kind: graphql10.Kind.FRAGMENT_SPREAD,
71684
72052
  name: {
71685
- kind: graphql9.Kind.NAME,
72053
+ kind: graphql10.Kind.NAME,
71686
72054
  value: fragmentName
71687
72055
  },
71688
72056
  directives: [
71689
72057
  {
71690
- kind: graphql9.Kind.DIRECTIVE,
72058
+ kind: graphql10.Kind.DIRECTIVE,
71691
72059
  name: {
71692
- kind: graphql9.Kind.NAME,
72060
+ kind: graphql10.Kind.NAME,
71693
72061
  value: config2.withDirective
71694
72062
  },
71695
72063
  ["arguments"]: paginationArgs.map(
@@ -71717,29 +72085,29 @@ async function paginate(config2, documents) {
71717
72085
  });
71718
72086
  const typeConfig = config2.typeConfig?.[fragment];
71719
72087
  const queryDoc = {
71720
- kind: graphql9.Kind.DOCUMENT,
72088
+ kind: graphql10.Kind.DOCUMENT,
71721
72089
  definitions: [
71722
72090
  {
71723
- kind: graphql9.Kind.OPERATION_DEFINITION,
72091
+ kind: graphql10.Kind.OPERATION_DEFINITION,
71724
72092
  name: {
71725
- kind: graphql9.Kind.NAME,
72093
+ kind: graphql10.Kind.NAME,
71726
72094
  value: refetchQueryName
71727
72095
  },
71728
72096
  operation: "query",
71729
72097
  variableDefinitions: paginationArgs.map(
71730
72098
  (arg) => ({
71731
- kind: graphql9.Kind.VARIABLE_DEFINITION,
72099
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
71732
72100
  type: {
71733
- kind: graphql9.Kind.NAMED_TYPE,
72101
+ kind: graphql10.Kind.NAMED_TYPE,
71734
72102
  name: {
71735
- kind: graphql9.Kind.NAME,
72103
+ kind: graphql10.Kind.NAME,
71736
72104
  value: arg.type
71737
72105
  }
71738
72106
  },
71739
72107
  variable: {
71740
- kind: graphql9.Kind.VARIABLE,
72108
+ kind: graphql10.Kind.VARIABLE,
71741
72109
  name: {
71742
- kind: graphql9.Kind.NAME,
72110
+ kind: graphql10.Kind.NAME,
71743
72111
  value: arg.name
71744
72112
  }
71745
72113
  },
@@ -71751,12 +72119,12 @@ async function paginate(config2, documents) {
71751
72119
  ).concat(
71752
72120
  !nodeQuery ? [] : keys.map(
71753
72121
  (key) => ({
71754
- kind: graphql9.Kind.VARIABLE_DEFINITION,
72122
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
71755
72123
  type: key.type,
71756
72124
  variable: {
71757
- kind: graphql9.Kind.VARIABLE,
72125
+ kind: graphql10.Kind.VARIABLE,
71758
72126
  name: {
71759
- kind: graphql9.Kind.NAME,
72127
+ kind: graphql10.Kind.NAME,
71760
72128
  value: key.name
71761
72129
  }
71762
72130
  }
@@ -71764,42 +72132,42 @@ async function paginate(config2, documents) {
71764
72132
  )
71765
72133
  ),
71766
72134
  selectionSet: {
71767
- kind: graphql9.Kind.SELECTION_SET,
72135
+ kind: graphql10.Kind.SELECTION_SET,
71768
72136
  selections: !nodeQuery ? fragmentSpreadSelection : [
71769
72137
  {
71770
- kind: graphql9.Kind.FIELD,
72138
+ kind: graphql10.Kind.FIELD,
71771
72139
  name: {
71772
- kind: graphql9.Kind.NAME,
72140
+ kind: graphql10.Kind.NAME,
71773
72141
  value: typeConfig?.resolve?.queryField || "node"
71774
72142
  },
71775
72143
  ["arguments"]: keys.map((key) => ({
71776
- kind: graphql9.Kind.ARGUMENT,
72144
+ kind: graphql10.Kind.ARGUMENT,
71777
72145
  name: {
71778
- kind: graphql9.Kind.NAME,
72146
+ kind: graphql10.Kind.NAME,
71779
72147
  value: key.name
71780
72148
  },
71781
72149
  value: {
71782
- kind: graphql9.Kind.VARIABLE,
72150
+ kind: graphql10.Kind.VARIABLE,
71783
72151
  name: {
71784
- kind: graphql9.Kind.NAME,
72152
+ kind: graphql10.Kind.NAME,
71785
72153
  value: key.name
71786
72154
  }
71787
72155
  }
71788
72156
  })),
71789
72157
  selectionSet: {
71790
- kind: graphql9.Kind.SELECTION_SET,
72158
+ kind: graphql10.Kind.SELECTION_SET,
71791
72159
  selections: [
71792
72160
  {
71793
- kind: graphql9.Kind.FIELD,
72161
+ kind: graphql10.Kind.FIELD,
71794
72162
  name: {
71795
- kind: graphql9.Kind.NAME,
72163
+ kind: graphql10.Kind.NAME,
71796
72164
  value: "__typename"
71797
72165
  }
71798
72166
  },
71799
72167
  ...(typeConfig?.keys || ["id"]).map((key) => ({
71800
- kind: graphql9.Kind.FIELD,
72168
+ kind: graphql10.Kind.FIELD,
71801
72169
  name: {
71802
- kind: graphql9.Kind.NAME,
72170
+ kind: graphql10.Kind.NAME,
71803
72171
  value: key
71804
72172
  }
71805
72173
  })),
@@ -71849,27 +72217,21 @@ function replaceArgumentsWithVariables(args, flags) {
71849
72217
  if (flags[name2].defaultValue || !spec.enabled || seenArgs[name2]) {
71850
72218
  continue;
71851
72219
  }
71852
- if (["first", "after"].includes(name2) && flags["before"].enabled) {
71853
- continue;
71854
- }
71855
- if (["last", "before"].includes(name2) && flags["first"].enabled) {
71856
- continue;
71857
- }
71858
72220
  newArgs.push(variableAsArgument(name2));
71859
72221
  }
71860
72222
  return newArgs;
71861
72223
  }
71862
72224
  function variableAsArgument(name2, variable) {
71863
72225
  return {
71864
- kind: graphql9.Kind.ARGUMENT,
72226
+ kind: graphql10.Kind.ARGUMENT,
71865
72227
  name: {
71866
- kind: graphql9.Kind.NAME,
72228
+ kind: graphql10.Kind.NAME,
71867
72229
  value: name2
71868
72230
  },
71869
72231
  value: {
71870
- kind: graphql9.Kind.VARIABLE,
72232
+ kind: graphql10.Kind.VARIABLE,
71871
72233
  name: {
71872
- kind: graphql9.Kind.NAME,
72234
+ kind: graphql10.Kind.NAME,
71873
72235
  value: variable ?? name2
71874
72236
  }
71875
72237
  }
@@ -71877,18 +72239,18 @@ function variableAsArgument(name2, variable) {
71877
72239
  }
71878
72240
  function staticVariableDefinition(name2, type, defaultValue, variableName) {
71879
72241
  return {
71880
- kind: graphql9.Kind.VARIABLE_DEFINITION,
72242
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
71881
72243
  type: {
71882
- kind: graphql9.Kind.NAMED_TYPE,
72244
+ kind: graphql10.Kind.NAMED_TYPE,
71883
72245
  name: {
71884
- kind: graphql9.Kind.NAME,
72246
+ kind: graphql10.Kind.NAME,
71885
72247
  value: type
71886
72248
  }
71887
72249
  },
71888
72250
  variable: {
71889
- kind: graphql9.Kind.VARIABLE,
72251
+ kind: graphql10.Kind.VARIABLE,
71890
72252
  name: {
71891
- kind: graphql9.Kind.NAME,
72253
+ kind: graphql10.Kind.NAME,
71892
72254
  value: variableName ?? name2
71893
72255
  }
71894
72256
  },
@@ -71900,9 +72262,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
71900
72262
  }
71901
72263
  function argumentNode(name2, value) {
71902
72264
  return {
71903
- kind: graphql9.Kind.ARGUMENT,
72265
+ kind: graphql10.Kind.ARGUMENT,
71904
72266
  name: {
71905
- kind: graphql9.Kind.NAME,
72267
+ kind: graphql10.Kind.NAME,
71906
72268
  value: name2
71907
72269
  },
71908
72270
  value: objectNode(value)
@@ -71910,16 +72272,16 @@ function argumentNode(name2, value) {
71910
72272
  }
71911
72273
  function objectNode([type, defaultValue]) {
71912
72274
  const node = {
71913
- kind: graphql9.Kind.OBJECT,
72275
+ kind: graphql10.Kind.OBJECT,
71914
72276
  fields: [
71915
72277
  {
71916
- kind: graphql9.Kind.OBJECT_FIELD,
72278
+ kind: graphql10.Kind.OBJECT_FIELD,
71917
72279
  name: {
71918
- kind: graphql9.Kind.NAME,
72280
+ kind: graphql10.Kind.NAME,
71919
72281
  value: "type"
71920
72282
  },
71921
72283
  value: {
71922
- kind: graphql9.Kind.STRING,
72284
+ kind: graphql10.Kind.STRING,
71923
72285
  value: type
71924
72286
  }
71925
72287
  }
@@ -71927,8 +72289,8 @@ function objectNode([type, defaultValue]) {
71927
72289
  };
71928
72290
  if (defaultValue) {
71929
72291
  node.fields.push({
71930
- kind: graphql9.Kind.OBJECT_FIELD,
71931
- name: { kind: graphql9.Kind.NAME, value: "default" },
72292
+ kind: graphql10.Kind.OBJECT_FIELD,
72293
+ name: { kind: graphql10.Kind.NAME, value: "default" },
71932
72294
  value: {
71933
72295
  kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
71934
72296
  value: defaultValue.toString()
@@ -71939,34 +72301,34 @@ function objectNode([type, defaultValue]) {
71939
72301
  }
71940
72302
  var pageInfoSelection = [
71941
72303
  {
71942
- kind: graphql9.Kind.FIELD,
72304
+ kind: graphql10.Kind.FIELD,
71943
72305
  name: {
71944
- kind: graphql9.Kind.NAME,
72306
+ kind: graphql10.Kind.NAME,
71945
72307
  value: "edges"
71946
72308
  },
71947
72309
  selectionSet: {
71948
- kind: graphql9.Kind.SELECTION_SET,
72310
+ kind: graphql10.Kind.SELECTION_SET,
71949
72311
  selections: [
71950
72312
  {
71951
- kind: graphql9.Kind.FIELD,
72313
+ kind: graphql10.Kind.FIELD,
71952
72314
  name: {
71953
- kind: graphql9.Kind.NAME,
72315
+ kind: graphql10.Kind.NAME,
71954
72316
  value: "cursor"
71955
72317
  }
71956
72318
  },
71957
72319
  {
71958
- kind: graphql9.Kind.FIELD,
72320
+ kind: graphql10.Kind.FIELD,
71959
72321
  name: {
71960
- kind: graphql9.Kind.NAME,
72322
+ kind: graphql10.Kind.NAME,
71961
72323
  value: "node"
71962
72324
  },
71963
72325
  selectionSet: {
71964
- kind: graphql9.Kind.SELECTION_SET,
72326
+ kind: graphql10.Kind.SELECTION_SET,
71965
72327
  selections: [
71966
72328
  {
71967
- kind: graphql9.Kind.FIELD,
72329
+ kind: graphql10.Kind.FIELD,
71968
72330
  name: {
71969
- kind: graphql9.Kind.NAME,
72331
+ kind: graphql10.Kind.NAME,
71970
72332
  value: "__typename"
71971
72333
  }
71972
72334
  }
@@ -71977,39 +72339,39 @@ var pageInfoSelection = [
71977
72339
  }
71978
72340
  },
71979
72341
  {
71980
- kind: graphql9.Kind.FIELD,
72342
+ kind: graphql10.Kind.FIELD,
71981
72343
  name: {
71982
- kind: graphql9.Kind.NAME,
72344
+ kind: graphql10.Kind.NAME,
71983
72345
  value: "pageInfo"
71984
72346
  },
71985
72347
  selectionSet: {
71986
- kind: graphql9.Kind.SELECTION_SET,
72348
+ kind: graphql10.Kind.SELECTION_SET,
71987
72349
  selections: [
71988
72350
  {
71989
- kind: graphql9.Kind.FIELD,
72351
+ kind: graphql10.Kind.FIELD,
71990
72352
  name: {
71991
- kind: graphql9.Kind.NAME,
72353
+ kind: graphql10.Kind.NAME,
71992
72354
  value: "hasPreviousPage"
71993
72355
  }
71994
72356
  },
71995
72357
  {
71996
- kind: graphql9.Kind.FIELD,
72358
+ kind: graphql10.Kind.FIELD,
71997
72359
  name: {
71998
- kind: graphql9.Kind.NAME,
72360
+ kind: graphql10.Kind.NAME,
71999
72361
  value: "hasNextPage"
72000
72362
  }
72001
72363
  },
72002
72364
  {
72003
- kind: graphql9.Kind.FIELD,
72365
+ kind: graphql10.Kind.FIELD,
72004
72366
  name: {
72005
- kind: graphql9.Kind.NAME,
72367
+ kind: graphql10.Kind.NAME,
72006
72368
  value: "startCursor"
72007
72369
  }
72008
72370
  },
72009
72371
  {
72010
- kind: graphql9.Kind.FIELD,
72372
+ kind: graphql10.Kind.FIELD,
72011
72373
  name: {
72012
- kind: graphql9.Kind.NAME,
72374
+ kind: graphql10.Kind.NAME,
72013
72375
  value: "endCursor"
72014
72376
  }
72015
72377
  }
@@ -72023,15 +72385,15 @@ async function addListFragments(config2, documents) {
72023
72385
  const lists = {};
72024
72386
  const errors = [];
72025
72387
  for (const doc of documents) {
72026
- doc.document = graphql10.visit(doc.document, {
72388
+ doc.document = graphql11.visit(doc.document, {
72027
72389
  Directive(node, key, parent, path2, ancestors) {
72028
72390
  if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
72029
72391
  const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
72030
72392
  let error = {
72031
- ...new graphql10.GraphQLError(
72393
+ ...new graphql11.GraphQLError(
72032
72394
  "",
72033
72395
  node,
72034
- new graphql10.Source(""),
72396
+ new graphql11.Source(""),
72035
72397
  node.loc ? [node.loc.start, node.loc.end] : null,
72036
72398
  path2
72037
72399
  ),
@@ -72083,7 +72445,7 @@ async function addListFragments(config2, documents) {
72083
72445
  {
72084
72446
  kind: "Argument",
72085
72447
  name: {
72086
- kind: graphql10.Kind.NAME,
72448
+ kind: graphql11.Kind.NAME,
72087
72449
  value: "connection"
72088
72450
  },
72089
72451
  value: {
@@ -72133,7 +72495,7 @@ async function addListFragments(config2, documents) {
72133
72495
  const validDeletes = [
72134
72496
  ...new Set(
72135
72497
  Object.values(lists).map(({ type }) => {
72136
- if (!(type instanceof graphql10.GraphQLObjectType)) {
72498
+ if (!(type instanceof graphql11.GraphQLObjectType)) {
72137
72499
  return "";
72138
72500
  }
72139
72501
  if (config2.keyFieldsForType(type.name).length !== 1) {
@@ -72147,7 +72509,7 @@ async function addListFragments(config2, documents) {
72147
72509
  return;
72148
72510
  }
72149
72511
  const generatedDoc = {
72150
- kind: graphql10.Kind.DOCUMENT,
72512
+ kind: graphql11.Kind.DOCUMENT,
72151
72513
  definitions: Object.entries(lists).flatMap(
72152
72514
  ([name2, { selection: selection2, type }]) => {
72153
72515
  const schemaType = config2.schema.getType(type.name);
@@ -72155,7 +72517,7 @@ async function addListFragments(config2, documents) {
72155
72517
  throw new HoudiniError({ message: "Lists must have a selection" });
72156
72518
  }
72157
72519
  const fragmentSelection = {
72158
- kind: graphql10.Kind.SELECTION_SET,
72520
+ kind: graphql11.Kind.SELECTION_SET,
72159
72521
  selections: [...selection2.selections]
72160
72522
  };
72161
72523
  if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
@@ -72170,14 +72532,14 @@ async function addListFragments(config2, documents) {
72170
72532
  {
72171
72533
  name: {
72172
72534
  value: config2.listInsertFragment(name2),
72173
- kind: graphql10.Kind.NAME
72535
+ kind: graphql11.Kind.NAME
72174
72536
  },
72175
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
72537
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
72176
72538
  selectionSet: fragmentSelection,
72177
72539
  typeCondition: {
72178
- kind: graphql10.Kind.NAMED_TYPE,
72540
+ kind: graphql11.Kind.NAMED_TYPE,
72179
72541
  name: {
72180
- kind: graphql10.Kind.NAME,
72542
+ kind: graphql11.Kind.NAME,
72181
72543
  value: type.name
72182
72544
  }
72183
72545
  }
@@ -72185,32 +72547,32 @@ async function addListFragments(config2, documents) {
72185
72547
  {
72186
72548
  name: {
72187
72549
  value: config2.listToggleFragment(name2),
72188
- kind: graphql10.Kind.NAME
72550
+ kind: graphql11.Kind.NAME
72189
72551
  },
72190
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
72552
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
72191
72553
  selectionSet: fragmentSelection,
72192
72554
  typeCondition: {
72193
- kind: graphql10.Kind.NAMED_TYPE,
72555
+ kind: graphql11.Kind.NAMED_TYPE,
72194
72556
  name: {
72195
- kind: graphql10.Kind.NAME,
72557
+ kind: graphql11.Kind.NAME,
72196
72558
  value: type.name
72197
72559
  }
72198
72560
  }
72199
72561
  },
72200
72562
  {
72201
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
72563
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
72202
72564
  name: {
72203
72565
  value: config2.listRemoveFragment(name2),
72204
- kind: graphql10.Kind.NAME
72566
+ kind: graphql11.Kind.NAME
72205
72567
  },
72206
72568
  selectionSet: {
72207
- kind: graphql10.Kind.SELECTION_SET,
72569
+ kind: graphql11.Kind.SELECTION_SET,
72208
72570
  selections: [...objectIdentificationSelection(config2, type)]
72209
72571
  },
72210
72572
  typeCondition: {
72211
- kind: graphql10.Kind.NAMED_TYPE,
72573
+ kind: graphql11.Kind.NAMED_TYPE,
72212
72574
  name: {
72213
- kind: graphql10.Kind.NAME,
72575
+ kind: graphql11.Kind.NAME,
72214
72576
  value: type.name
72215
72577
  }
72216
72578
  }
@@ -72219,14 +72581,14 @@ async function addListFragments(config2, documents) {
72219
72581
  }
72220
72582
  ).concat(
72221
72583
  ...validDeletes.map((typeName) => ({
72222
- kind: graphql10.Kind.DIRECTIVE_DEFINITION,
72584
+ kind: graphql11.Kind.DIRECTIVE_DEFINITION,
72223
72585
  name: {
72224
- kind: graphql10.Kind.NAME,
72586
+ kind: graphql11.Kind.NAME,
72225
72587
  value: config2.listDeleteDirective(typeName)
72226
72588
  },
72227
72589
  locations: [
72228
72590
  {
72229
- kind: graphql10.Kind.NAME,
72591
+ kind: graphql11.Kind.NAME,
72230
72592
  value: "FIELD"
72231
72593
  }
72232
72594
  ],
@@ -72234,8 +72596,8 @@ async function addListFragments(config2, documents) {
72234
72596
  }))
72235
72597
  )
72236
72598
  };
72237
- config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql10.print).join("\n\n");
72238
- config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql10.print).join("\n\n");
72599
+ config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql11.print).join("\n\n");
72600
+ config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql11.print).join("\n\n");
72239
72601
  documents.push({
72240
72602
  name: "generated::lists",
72241
72603
  kind: "HoudiniFragment" /* Fragment */,
@@ -72320,11 +72682,11 @@ var nodeNotDefinedMessage = (config2) => `Looks like you are trying to use the $
72320
72682
  For more information, visit this link: ${siteURL}/guides/pagination`;
72321
72683
 
72322
72684
  // src/codegen/generators/artifacts/fieldKey.ts
72323
- var graphql11 = __toESM(require_graphql2(), 1);
72685
+ var graphql12 = __toESM(require_graphql2(), 1);
72324
72686
  function fieldKey(config2, field) {
72325
72687
  const attributeName = field.alias?.value || field.name.value;
72326
- const printed = graphql11.print(field);
72327
- const secondParse = graphql11.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
72688
+ const printed = graphql12.print(field);
72689
+ const secondParse = graphql12.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
72328
72690
  const paginated = !!field.directives?.find(
72329
72691
  (directive) => directive.name.value === config2.paginateDirective
72330
72692
  );
@@ -72362,7 +72724,7 @@ function selection({
72362
72724
  path: path2 = [],
72363
72725
  includeFragments,
72364
72726
  document,
72365
- markEdges
72727
+ inConnection
72366
72728
  }) {
72367
72729
  let object = {};
72368
72730
  const typeMap = {};
@@ -72419,8 +72781,8 @@ function selection({
72419
72781
  const typeConditionName = field.typeCondition.name.value;
72420
72782
  const typeCondition = config2.schema.getType(typeConditionName);
72421
72783
  const possibleTypes = [];
72422
- if (!graphql12.isAbstractType(typeCondition)) {
72423
- } else if (graphql12.isAbstractType(parentType)) {
72784
+ if (!graphql13.isAbstractType(typeCondition)) {
72785
+ } else if (graphql13.isAbstractType(parentType)) {
72424
72786
  const possibleParentTypes = config2.schema.getPossibleTypes(parentType).map((type) => type.name);
72425
72787
  for (const possible of config2.schema.getPossibleTypes(typeCondition)) {
72426
72788
  if (possibleParentTypes.includes(possible.name)) {
@@ -72468,7 +72830,7 @@ function selection({
72468
72830
  } else {
72469
72831
  let typeRef = type.getFields()[field.name.value].type;
72470
72832
  fieldType = getRootType(typeRef);
72471
- nullable = !graphql12.isNonNullType(typeRef);
72833
+ nullable = !graphql13.isNonNullType(typeRef);
72472
72834
  }
72473
72835
  const typeName = fieldType.toString();
72474
72836
  const pathSoFar = path2.concat(attributeName);
@@ -72504,14 +72866,23 @@ function selection({
72504
72866
  (directive) => directive.name.value === config2.paginateDirective
72505
72867
  );
72506
72868
  if (paginated && document.refetch && document.refetch.method === "offset") {
72507
- fieldObj.update = document.refetch.update;
72869
+ fieldObj.updates = ["append" /* append */];
72870
+ }
72871
+ let continueConnection = inConnection;
72872
+ if ([
72873
+ "edges",
72874
+ "endCursor",
72875
+ "startCursor",
72876
+ "hasNextPage",
72877
+ "hasPreviousPage"
72878
+ ].includes(attributeName) && inConnection && document.refetch) {
72879
+ fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
72508
72880
  }
72509
- if (attributeName === "edges" && markEdges && document.refetch) {
72510
- fieldObj.update = document.refetch.update;
72511
- markEdges = "";
72881
+ if (attributeName === "node" && inConnection) {
72882
+ continueConnection = false;
72512
72883
  }
72513
72884
  if (field.selectionSet) {
72514
- const edgesMark = paginated && document.refetch?.method === "cursor" ? document.refetch.update : markEdges;
72885
+ const connectionState = paginated && document.refetch?.method === "cursor" || continueConnection;
72515
72886
  fieldObj.selection = selection({
72516
72887
  config: config2,
72517
72888
  filepath,
@@ -72521,7 +72892,7 @@ function selection({
72521
72892
  path: pathSoFar,
72522
72893
  includeFragments,
72523
72894
  document,
72524
- markEdges: edgesMark
72895
+ inConnection: connectionState
72525
72896
  });
72526
72897
  }
72527
72898
  if (field.arguments?.length && fieldObj.list) {
@@ -72533,7 +72904,7 @@ function selection({
72533
72904
  {}
72534
72905
  );
72535
72906
  }
72536
- if (graphql12.isInterfaceType(fieldType) || graphql12.isUnionType(fieldType)) {
72907
+ if (graphql13.isInterfaceType(fieldType) || graphql13.isUnionType(fieldType)) {
72537
72908
  fieldObj.abstract = true;
72538
72909
  }
72539
72910
  object.fields = {
@@ -72590,7 +72961,7 @@ function artifactGenerator(stats) {
72590
72961
  return async function(config2, docs) {
72591
72962
  const filterTypes = {};
72592
72963
  for (const doc of docs) {
72593
- graphql13.visit(doc.document, {
72964
+ graphql14.visit(doc.document, {
72594
72965
  Directive(node, _, __, ___, ancestors) {
72595
72966
  if (node.name.value !== config2.listDirective) {
72596
72967
  return;
@@ -72649,7 +73020,7 @@ function artifactGenerator(stats) {
72649
73020
  return;
72650
73021
  }
72651
73022
  const usedVariableNames = /* @__PURE__ */ new Set();
72652
- let documentWithoutInternalDirectives = graphql13.visit(document, {
73023
+ let documentWithoutInternalDirectives = graphql14.visit(document, {
72653
73024
  Directive(node) {
72654
73025
  if (config2.isInternalDirective(node)) {
72655
73026
  return null;
@@ -72662,7 +73033,7 @@ function artifactGenerator(stats) {
72662
73033
  }
72663
73034
  }
72664
73035
  });
72665
- let documentWithoutExtraVariables = graphql13.visit(
73036
+ let documentWithoutExtraVariables = graphql14.visit(
72666
73037
  documentWithoutInternalDirectives,
72667
73038
  {
72668
73039
  VariableDefinition(variableDefinitionNode) {
@@ -72673,13 +73044,13 @@ function artifactGenerator(stats) {
72673
73044
  }
72674
73045
  }
72675
73046
  );
72676
- let rawString = graphql13.print(documentWithoutExtraVariables);
73047
+ let rawString = graphql14.print(documentWithoutExtraVariables);
72677
73048
  let docKind = doc.kind;
72678
73049
  const operations = document.definitions.filter(
72679
- ({ kind }) => kind === graphql13.Kind.OPERATION_DEFINITION
73050
+ ({ kind }) => kind === graphql14.Kind.OPERATION_DEFINITION
72680
73051
  );
72681
73052
  const fragments = document.definitions.filter(
72682
- ({ kind }) => kind === graphql13.Kind.FRAGMENT_DEFINITION
73053
+ ({ kind }) => kind === graphql14.Kind.FRAGMENT_DEFINITION
72683
73054
  );
72684
73055
  let rootType = "";
72685
73056
  let selectionSet;
@@ -72712,7 +73083,13 @@ function artifactGenerator(stats) {
72712
73083
  rootType = matchingFragment.typeCondition.name.value;
72713
73084
  selectionSet = matchingFragment.selectionSet;
72714
73085
  }
72715
- const inputs = operations[0]?.variableDefinitions;
73086
+ let inputs = operations[0]?.variableDefinitions;
73087
+ let directive = fragments[0]?.directives?.find(
73088
+ (directive2) => directive2.name.value === config2.argumentsDirective
73089
+ );
73090
+ if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
73091
+ inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
73092
+ }
72716
73093
  const mergedSelection = flattenSelections({
72717
73094
  config: config2,
72718
73095
  filepath: doc.filename,
@@ -72773,7 +73150,7 @@ function artifactGenerator(stats) {
72773
73150
  }
72774
73151
  if (docKind === "HoudiniQuery") {
72775
73152
  const cacheDirective = operations[0].directives?.find(
72776
- (directive) => directive.name.value === config2.cacheDirective
73153
+ (directive2) => directive2.name.value === config2.cacheDirective
72777
73154
  );
72778
73155
  if (cacheDirective) {
72779
73156
  const args = cacheDirective.arguments?.reduce(
@@ -72989,19 +73366,19 @@ async function generatePluginRuntime(config2, plugin) {
72989
73366
  );
72990
73367
  }
72991
73368
 
72992
- // src/codegen/generators/typescript/index.ts
72993
- var recast12 = __toESM(require_main2(), 1);
73369
+ // src/codegen/generators/typescript/documentTypes.ts
73370
+ var recast11 = __toESM(require_main2(), 1);
72994
73371
 
72995
73372
  // src/codegen/generators/typescript/addReferencedInputTypes.ts
72996
- var graphql16 = __toESM(require_graphql2(), 1);
73373
+ var graphql17 = __toESM(require_graphql2(), 1);
72997
73374
  var recast9 = __toESM(require_main2(), 1);
72998
73375
 
72999
73376
  // src/codegen/generators/typescript/typeReference.ts
73000
- var graphql15 = __toESM(require_graphql2(), 1);
73377
+ var graphql16 = __toESM(require_graphql2(), 1);
73001
73378
  var recast8 = __toESM(require_main2(), 1);
73002
73379
 
73003
73380
  // src/codegen/generators/typescript/types.ts
73004
- var graphql14 = __toESM(require_graphql2(), 1);
73381
+ var graphql15 = __toESM(require_graphql2(), 1);
73005
73382
  var recast7 = __toESM(require_main2(), 1);
73006
73383
  var AST7 = recast7.types.builders;
73007
73384
  function readonlyProperty(prop, enable = true) {
@@ -73017,351 +73394,104 @@ function nullableField(inner, input = false) {
73017
73394
  }
73018
73395
  return AST7.tsUnionType(members);
73019
73396
  }
73020
- function scalarPropertyValue(config2, missingScalars, target) {
73021
- switch (target.name) {
73022
- case "String": {
73023
- return AST7.tsStringKeyword();
73024
- }
73025
- case "Int": {
73026
- return AST7.tsNumberKeyword();
73027
- }
73028
- case "Float": {
73029
- return AST7.tsNumberKeyword();
73030
- }
73031
- case "Boolean": {
73032
- return AST7.tsBooleanKeyword();
73033
- }
73034
- case "ID": {
73035
- return AST7.tsStringKeyword();
73036
- }
73037
- default: {
73038
- if (graphql14.isNonNullType(target) && "ofType" in target) {
73039
- return scalarPropertyValue(
73040
- config2,
73041
- missingScalars,
73042
- target.ofType
73043
- );
73044
- }
73045
- if (config2.scalars?.[target.name]) {
73046
- return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
73047
- }
73048
- missingScalars.add(target.name);
73049
- return AST7.tsAnyKeyword();
73050
- }
73051
- }
73052
- }
73053
-
73054
- // src/codegen/generators/typescript/typeReference.ts
73055
- var AST8 = recast8.types.builders;
73056
- function tsTypeReference(config2, missingScalars, definition) {
73057
- const { type, wrappers } = unwrapType(config2, definition.type);
73058
- let result;
73059
- if (graphql15.isScalarType(type)) {
73060
- result = scalarPropertyValue(config2, missingScalars, type);
73061
- } else {
73062
- result = AST8.tsTypeReference(AST8.identifier(type.name));
73063
- }
73064
- for (const toWrap of wrappers) {
73065
- if (toWrap === "NonNull" /* NonNull */) {
73066
- continue;
73067
- } else if (toWrap === "Nullable" /* Nullable */) {
73068
- result = nullableField(result, true);
73069
- } else if (toWrap === "List" /* List */) {
73070
- result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
73071
- }
73072
- }
73073
- return result;
73074
- }
73075
-
73076
- // src/codegen/generators/typescript/addReferencedInputTypes.ts
73077
- var AST9 = recast9.types.builders;
73078
- function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
73079
- const { type } = unwrapType(config2, rootType);
73080
- if (graphql16.isScalarType(type)) {
73081
- return;
73082
- }
73083
- if (visitedTypes.has(type.name)) {
73084
- return;
73085
- }
73086
- if (graphql16.isUnionType(type)) {
73087
- throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
73088
- }
73089
- visitedTypes.add(type.name);
73090
- if (graphql16.isEnumType(type)) {
73091
- ensureImports({
73092
- config: config2,
73093
- body,
73094
- import: [type.name],
73095
- sourceModule: "$houdini/graphql/enums",
73096
- importKind: "type"
73097
- });
73098
- return;
73099
- }
73100
- const members = [];
73101
- for (const field of Object.values(type.getFields())) {
73102
- addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
73103
- members.push(
73104
- AST9.tsPropertySignature(
73105
- AST9.identifier(field.name),
73106
- AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
73107
- graphql16.isNullableType(field.type)
73108
- )
73109
- );
73110
- }
73111
- body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
73112
- }
73113
-
73114
- // src/codegen/generators/typescript/imperativeCache.ts
73115
- var graphql17 = __toESM(require_graphql2(), 1);
73116
- var recast10 = __toESM(require_main2(), 1);
73117
- var AST10 = recast10.types.builders;
73118
- async function imperativeCacheTypef(config2, docs) {
73119
- const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
73120
- const body = [];
73121
- const declaration = AST10.tsTypeAliasDeclaration(
73122
- AST10.identifier(CacheTypeDefName),
73123
- AST10.tsTypeLiteral([
73124
- AST10.tsPropertySignature(
73125
- AST10.identifier("types"),
73126
- AST10.tsTypeAnnotation(typeDefinitions(config2, body))
73127
- ),
73128
- AST10.tsPropertySignature(
73129
- AST10.identifier("lists"),
73130
- AST10.tsTypeAnnotation(listDefinitions(config2, docs))
73131
- )
73132
- ])
73133
- );
73134
- declaration.declare = true;
73135
- const importRecord = AST10.importDeclaration(
73136
- [AST10.importSpecifier(AST10.identifier("Record"))],
73137
- AST10.stringLiteral("./public/record")
73138
- );
73139
- importRecord.importKind = "type";
73140
- await fs_exports.writeFile(
73141
- target,
73142
- recast10.prettyPrint(
73143
- AST10.program([importRecord, ...body, AST10.exportNamedDeclaration(declaration)])
73144
- ).code
73145
- );
73146
- }
73147
- function typeDefinitions(config2, body) {
73148
- const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
73149
- const visitedTypes = /* @__PURE__ */ new Set();
73150
- const types16 = Object.values(config2.schema.getTypeMap()).filter(
73151
- (type) => !graphql17.isAbstractType(type) && !graphql17.isScalarType(type) && !graphql17.isEnumType(type) && !graphql17.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
73152
- );
73153
- return AST10.tsTypeLiteral(
73154
- types16.map((type) => {
73155
- let typeName = type.name;
73156
- if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
73157
- typeName = "__ROOT__";
73158
- }
73159
- let idFields = AST10.tsNeverKeyword();
73160
- const keys = keyFieldsForType(config2.configFile, type.name);
73161
- if (graphql17.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
73162
- idFields = AST10.tsTypeLiteral(
73163
- keys.map((key) => {
73164
- const fieldType = type.getFields()[key];
73165
- const unwrapped = unwrapType(config2, fieldType.type);
73166
- return AST10.tsPropertySignature(
73167
- AST10.identifier(key),
73168
- AST10.tsTypeAnnotation(
73169
- scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
73170
- )
73171
- );
73172
- })
73173
- );
73174
- } else if (typeName === "__ROOT__") {
73175
- idFields = AST10.tsTypeLiteral([]);
73176
- }
73177
- let fields = AST10.tsTypeLiteral([]);
73178
- if (graphql17.isObjectType(type)) {
73179
- fields = AST10.tsTypeLiteral(
73180
- Object.entries(type.getFields()).map(
73181
- ([key, fieldType]) => {
73182
- const unwrapped = unwrapType(config2, fieldType.type);
73183
- let typeOptions = AST10.tsUnionType([]);
73184
- if (graphql17.isScalarType(unwrapped.type)) {
73185
- typeOptions.types.push(
73186
- scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
73187
- );
73188
- } else if (graphql17.isEnumType(unwrapped.type)) {
73189
- typeOptions.types.push(
73190
- AST10.tsTypeReference(AST10.identifier(unwrapped.type.name))
73191
- );
73192
- } else if (!graphql17.isAbstractType(unwrapped.type)) {
73193
- typeOptions.types.push(record(unwrapped.type.name));
73194
- } else {
73195
- typeOptions.types.push(
73196
- ...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
73197
- );
73198
- }
73199
- for (const wrapper of unwrapped.wrappers) {
73200
- if (wrapper === "Nullable" /* Nullable */) {
73201
- typeOptions = AST10.tsParenthesizedType(
73202
- AST10.tsUnionType([typeOptions, AST10.tsNullKeyword()])
73203
- );
73204
- } else if (wrapper === "List" /* List */) {
73205
- typeOptions = AST10.tsArrayType(
73206
- AST10.tsParenthesizedType(typeOptions)
73207
- );
73208
- }
73209
- }
73210
- if (typeOptions.type === "TSParenthesizedType") {
73211
- typeOptions = typeOptions.typeAnnotation;
73212
- }
73213
- let args = AST10.tsNeverKeyword();
73214
- if (fieldType.args?.length > 0) {
73215
- args = AST10.tsTypeLiteral(
73216
- fieldType.args.map((arg) => {
73217
- addReferencedInputTypes(
73218
- config2,
73219
- "",
73220
- body,
73221
- visitedTypes,
73222
- /* @__PURE__ */ new Set(),
73223
- arg.type
73224
- );
73225
- const prop = AST10.tsPropertySignature(
73226
- AST10.identifier(arg.name),
73227
- AST10.tsTypeAnnotation(
73228
- tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
73229
- )
73230
- );
73231
- const unwrapped2 = unwrapType(config2, arg.type);
73232
- prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
73233
- return prop;
73234
- })
73235
- );
73236
- }
73237
- return AST10.tsPropertySignature(
73238
- AST10.identifier(key),
73239
- AST10.tsTypeAnnotation(
73240
- AST10.tsTypeLiteral([
73241
- AST10.tsPropertySignature(
73242
- AST10.identifier("type"),
73243
- AST10.tsTypeAnnotation(typeOptions)
73244
- ),
73245
- AST10.tsPropertySignature(
73246
- AST10.identifier("args"),
73247
- AST10.tsTypeAnnotation(args)
73248
- )
73249
- ])
73250
- )
73251
- );
73252
- }
73253
- )
73254
- );
73255
- }
73256
- return AST10.tsPropertySignature(
73257
- AST10.identifier(typeName),
73258
- AST10.tsTypeAnnotation(
73259
- AST10.tsTypeLiteral([
73260
- AST10.tsPropertySignature(
73261
- AST10.identifier("idFields"),
73262
- AST10.tsTypeAnnotation(idFields)
73263
- ),
73264
- AST10.tsPropertySignature(
73265
- AST10.identifier("fields"),
73266
- AST10.tsTypeAnnotation(fields)
73267
- )
73268
- ])
73269
- )
73270
- );
73271
- })
73272
- );
73273
- }
73274
- function listDefinitions(config2, docs) {
73275
- const lists = [];
73276
- const visitedLists = /* @__PURE__ */ new Set();
73277
- for (const doc of docs) {
73278
- graphql17.visit(doc.document, {
73279
- Directive(node, key, parent, path2, ancestors) {
73280
- if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
73281
- return;
73282
- }
73283
- const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
73284
- const nameValue = nameArg?.value?.value || "";
73285
- if (!nameValue || visitedLists.has(nameValue)) {
73286
- return;
73287
- }
73288
- visitedLists.add(nameValue);
73289
- const parentType = parentTypeFromAncestors(
73290
- config2.schema,
73291
- doc.filename,
73292
- ancestors.slice(0, -1)
73293
- );
73294
- const targetField = ancestors[ancestors.length - 1];
73295
- const targetFieldDefinition = parentType.getFields()[targetField.name.value];
73296
- const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
73297
- const possibleTypes = [];
73298
- if (graphql17.isAbstractType(listType)) {
73299
- possibleTypes.push(
73300
- ...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
73301
- );
73302
- } else {
73303
- possibleTypes.push(listType.name);
73304
- }
73305
- lists.push(
73306
- AST10.tsPropertySignature(
73307
- AST10.identifier(nameValue),
73308
- AST10.tsTypeAnnotation(
73309
- AST10.tsTypeLiteral([
73310
- AST10.tsPropertySignature(
73311
- AST10.identifier("types"),
73312
- AST10.tsTypeAnnotation(
73313
- AST10.tsUnionType(
73314
- possibleTypes.map(
73315
- (possible) => AST10.tsLiteralType(AST10.stringLiteral(possible))
73316
- )
73317
- )
73318
- )
73319
- ),
73320
- AST10.tsPropertySignature(
73321
- AST10.identifier("filters"),
73322
- AST10.tsTypeAnnotation(
73323
- targetFieldDefinition.args.length === 0 ? AST10.tsNeverKeyword() : AST10.tsTypeLiteral(
73324
- targetFieldDefinition.args.map((arg) => {
73325
- const argDef = AST10.tsPropertySignature(
73326
- AST10.identifier(arg.name),
73327
- AST10.tsTypeAnnotation(
73328
- tsTypeReference(
73329
- config2,
73330
- /* @__PURE__ */ new Set(),
73331
- arg
73332
- )
73333
- )
73334
- );
73335
- argDef.optional = true;
73336
- return argDef;
73337
- })
73338
- )
73339
- )
73340
- )
73341
- ])
73342
- )
73343
- )
73397
+ function scalarPropertyValue(config2, missingScalars, target) {
73398
+ switch (target.name) {
73399
+ case "String": {
73400
+ return AST7.tsStringKeyword();
73401
+ }
73402
+ case "Int": {
73403
+ return AST7.tsNumberKeyword();
73404
+ }
73405
+ case "Float": {
73406
+ return AST7.tsNumberKeyword();
73407
+ }
73408
+ case "Boolean": {
73409
+ return AST7.tsBooleanKeyword();
73410
+ }
73411
+ case "ID": {
73412
+ return AST7.tsStringKeyword();
73413
+ }
73414
+ default: {
73415
+ if (graphql15.isNonNullType(target) && "ofType" in target) {
73416
+ return scalarPropertyValue(
73417
+ config2,
73418
+ missingScalars,
73419
+ target.ofType
73344
73420
  );
73345
73421
  }
73346
- });
73422
+ if (config2.scalars?.[target.name]) {
73423
+ return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
73424
+ }
73425
+ missingScalars.add(target.name);
73426
+ return AST7.tsAnyKeyword();
73427
+ }
73347
73428
  }
73348
- return AST10.tsTypeLiteral(lists);
73349
73429
  }
73350
- var CacheTypeDefName = "CacheTypeDef";
73351
- function record(name2) {
73352
- return AST10.tsTypeReference(
73353
- AST10.identifier("Record"),
73354
- AST10.tsTypeParameterInstantiation([
73355
- AST10.tsTypeReference(AST10.identifier(CacheTypeDefName)),
73356
- AST10.tsLiteralType(AST10.stringLiteral(name2))
73357
- ])
73358
- );
73430
+
73431
+ // src/codegen/generators/typescript/typeReference.ts
73432
+ var AST8 = recast8.types.builders;
73433
+ function tsTypeReference(config2, missingScalars, definition) {
73434
+ const { type, wrappers } = unwrapType(config2, definition.type);
73435
+ let result;
73436
+ if (graphql16.isScalarType(type)) {
73437
+ result = scalarPropertyValue(config2, missingScalars, type);
73438
+ } else {
73439
+ result = AST8.tsTypeReference(AST8.identifier(type.name));
73440
+ }
73441
+ for (const toWrap of wrappers) {
73442
+ if (toWrap === "NonNull" /* NonNull */) {
73443
+ continue;
73444
+ } else if (toWrap === "Nullable" /* Nullable */) {
73445
+ result = nullableField(result, true);
73446
+ } else if (toWrap === "List" /* List */) {
73447
+ result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
73448
+ }
73449
+ }
73450
+ return result;
73451
+ }
73452
+
73453
+ // src/codegen/generators/typescript/addReferencedInputTypes.ts
73454
+ var AST9 = recast9.types.builders;
73455
+ function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
73456
+ const { type } = unwrapType(config2, rootType);
73457
+ if (graphql17.isScalarType(type)) {
73458
+ return;
73459
+ }
73460
+ if (visitedTypes.has(type.name)) {
73461
+ return;
73462
+ }
73463
+ if (graphql17.isUnionType(type)) {
73464
+ throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
73465
+ }
73466
+ visitedTypes.add(type.name);
73467
+ if (graphql17.isEnumType(type)) {
73468
+ ensureImports({
73469
+ config: config2,
73470
+ body,
73471
+ import: [type.name],
73472
+ sourceModule: "$houdini/graphql/enums",
73473
+ importKind: "type"
73474
+ });
73475
+ return;
73476
+ }
73477
+ const members = [];
73478
+ for (const field of Object.values(type.getFields())) {
73479
+ addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
73480
+ members.push(
73481
+ AST9.tsPropertySignature(
73482
+ AST9.identifier(field.name),
73483
+ AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
73484
+ graphql17.isNullableType(field.type)
73485
+ )
73486
+ );
73487
+ }
73488
+ body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
73359
73489
  }
73360
73490
 
73361
73491
  // src/codegen/generators/typescript/inlineType.ts
73362
73492
  var graphql18 = __toESM(require_graphql2(), 1);
73363
- var recast11 = __toESM(require_main2(), 1);
73364
- var AST11 = recast11.types.builders;
73493
+ var recast10 = __toESM(require_main2(), 1);
73494
+ var AST10 = recast10.types.builders;
73365
73495
  var fragmentKey = "$fragments";
73366
73496
  function inlineType({
73367
73497
  config: config2,
@@ -73390,7 +73520,7 @@ function inlineType({
73390
73520
  });
73391
73521
  visitedTypes.add(type.name);
73392
73522
  }
73393
- result = AST11.tsTypeReference(AST11.identifier(type.name));
73523
+ result = AST10.tsTypeReference(AST10.identifier(type.name));
73394
73524
  } else if (selections) {
73395
73525
  const rootObj = type;
73396
73526
  const inlineFragments = {};
@@ -73441,7 +73571,7 @@ function inlineType({
73441
73571
  selectedFields.push(selection2);
73442
73572
  }
73443
73573
  }
73444
- result = AST11.tsTypeLiteral([
73574
+ result = AST10.tsTypeLiteral([
73445
73575
  ...(selectedFields || []).filter(
73446
73576
  (field) => field.kind === "Field"
73447
73577
  ).map((selection2) => {
@@ -73461,9 +73591,9 @@ function inlineType({
73461
73591
  allOptional
73462
73592
  });
73463
73593
  const prop = readonlyProperty(
73464
- AST11.tsPropertySignature(
73465
- AST11.identifier(attributeName),
73466
- AST11.tsTypeAnnotation(attributeType)
73594
+ AST10.tsPropertySignature(
73595
+ AST10.identifier(attributeName),
73596
+ AST10.tsTypeAnnotation(attributeType)
73467
73597
  ),
73468
73598
  allowReadonly
73469
73599
  );
@@ -73477,15 +73607,15 @@ function inlineType({
73477
73607
  if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
73478
73608
  result.members.push(
73479
73609
  readonlyProperty(
73480
- AST11.tsPropertySignature(
73481
- AST11.identifier(fragmentKey),
73482
- AST11.tsTypeAnnotation(
73483
- AST11.tsTypeLiteral(
73610
+ AST10.tsPropertySignature(
73611
+ AST10.identifier(fragmentKey),
73612
+ AST10.tsTypeAnnotation(
73613
+ AST10.tsTypeLiteral(
73484
73614
  (fragmentSpreads || []).map(
73485
- (fragmentSpread) => AST11.tsPropertySignature(
73486
- AST11.identifier(fragmentSpread.name.value),
73487
- AST11.tsTypeAnnotation(
73488
- AST11.tsLiteralType(AST11.booleanLiteral(true))
73615
+ (fragmentSpread) => AST10.tsPropertySignature(
73616
+ AST10.identifier(fragmentSpread.name.value),
73617
+ AST10.tsTypeAnnotation(
73618
+ AST10.tsLiteralType(AST10.booleanLiteral(true))
73489
73619
  )
73490
73620
  )
73491
73621
  )
@@ -73531,9 +73661,9 @@ function inlineType({
73531
73661
  }
73532
73662
  objectType.members.push(
73533
73663
  readonlyProperty(
73534
- AST11.tsPropertySignature(
73535
- AST11.identifier("__typename"),
73536
- AST11.tsTypeAnnotation(AST11.tsLiteralType(AST11.stringLiteral(typeName)))
73664
+ AST10.tsPropertySignature(
73665
+ AST10.identifier("__typename"),
73666
+ AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
73537
73667
  ),
73538
73668
  allowReadonly
73539
73669
  )
@@ -73544,8 +73674,8 @@ function inlineType({
73544
73674
  if (Object.keys(inlineFragmentSelections).length > 0) {
73545
73675
  let selectionTypes = Object.entries(inlineFragmentSelections).map(
73546
73676
  ([typeName, { type: type2, tsType }]) => {
73547
- return AST11.tsParenthesizedType(
73548
- AST11.tsIntersectionType(
73677
+ return AST10.tsParenthesizedType(
73678
+ AST10.tsIntersectionType(
73549
73679
  [tsType].flatMap((type3) => {
73550
73680
  if (type3.type === "TSUnionType") {
73551
73681
  return type3.types.filter(
@@ -73558,9 +73688,9 @@ function inlineType({
73558
73688
  );
73559
73689
  }
73560
73690
  );
73561
- result = AST11.tsIntersectionType([
73691
+ result = AST10.tsIntersectionType([
73562
73692
  result,
73563
- AST11.tsParenthesizedType(AST11.tsUnionType(selectionTypes))
73693
+ AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
73564
73694
  ]);
73565
73695
  }
73566
73696
  } else {
@@ -73572,7 +73702,7 @@ function inlineType({
73572
73702
  } else if (toWrap === "NonNull" /* NonNull */) {
73573
73703
  continue;
73574
73704
  } else if (toWrap === "List" /* List */) {
73575
- result = AST11.tsArrayType(AST11.tsParenthesizedType(result));
73705
+ result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
73576
73706
  }
73577
73707
  }
73578
73708
  return result;
@@ -73616,9 +73746,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
73616
73746
  return { field, type: selectionType };
73617
73747
  }
73618
73748
 
73619
- // src/codegen/generators/typescript/index.ts
73620
- var AST12 = recast12.types.builders;
73621
- async function typescriptGenerator(config2, docs) {
73749
+ // src/codegen/generators/typescript/documentTypes.ts
73750
+ var AST11 = recast11.types.builders;
73751
+ async function generateDocumentTypes(config2, docs) {
73622
73752
  const typePaths = [];
73623
73753
  const fragmentDefinitions = {};
73624
73754
  for (const document of docs) {
@@ -73635,7 +73765,7 @@ async function typescriptGenerator(config2, docs) {
73635
73765
  return;
73636
73766
  }
73637
73767
  const typeDefPath = config2.artifactTypePath(originalDocument);
73638
- const program3 = AST12.program([]);
73768
+ const program3 = AST11.program([]);
73639
73769
  const visitedTypes = /* @__PURE__ */ new Set();
73640
73770
  let definition = originalDocument.definitions.find(
73641
73771
  (def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
@@ -73668,21 +73798,21 @@ async function typescriptGenerator(config2, docs) {
73668
73798
  missingScalars
73669
73799
  );
73670
73800
  }
73671
- await fs_exports.writeFile(typeDefPath, recast12.print(program3).code);
73801
+ await fs_exports.writeFile(typeDefPath, recast11.print(program3).code);
73672
73802
  typePaths.push(typeDefPath);
73673
73803
  })
73674
73804
  );
73675
- const typeIndex = AST12.program(
73805
+ const typeIndex = AST11.program(
73676
73806
  typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
73677
- return AST12.exportAllDeclaration(
73678
- AST12.literal(
73807
+ return AST11.exportAllDeclaration(
73808
+ AST11.literal(
73679
73809
  "./" + path_exports.relative(path_exports.resolve(config2.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
73680
73810
  ),
73681
73811
  null
73682
73812
  );
73683
73813
  }).concat([
73684
- AST12.exportAllDeclaration(AST12.literal("./runtime"), null),
73685
- AST12.exportAllDeclaration(AST12.literal("./graphql"), null)
73814
+ AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
73815
+ AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
73686
73816
  ])
73687
73817
  );
73688
73818
  const export_default_as = ({ module: module2, as }) => `
@@ -73691,7 +73821,7 @@ export { default as ${as} } from "${module2}"
73691
73821
  const export_star_from = ({ module: module2 }) => `
73692
73822
  export * from "${module2}"
73693
73823
  `;
73694
- let indexContent = recast12.print(typeIndex).code;
73824
+ let indexContent = recast11.print(typeIndex).code;
73695
73825
  for (const plugin of config2.plugins) {
73696
73826
  if (!plugin.index_file) {
73697
73827
  continue;
@@ -73712,7 +73842,6 @@ export * from "${module2}"
73712
73842
  }
73713
73843
  }
73714
73844
  await fs_exports.writeFile(config2.typeIndexPath, indexContent);
73715
- await imperativeCacheTypef(config2, docs);
73716
73845
  if (missingScalars.size > 0) {
73717
73846
  console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
73718
73847
  ", "
@@ -73754,23 +73883,23 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73754
73883
  const optimisticTypeName = `${definition.name.value}$optimistic`;
73755
73884
  const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
73756
73885
  body.push(
73757
- AST12.exportNamedDeclaration(
73758
- AST12.tsTypeAliasDeclaration(
73759
- AST12.identifier(definition.name.value),
73760
- AST12.tsTypeLiteral([
73886
+ AST11.exportNamedDeclaration(
73887
+ AST11.tsTypeAliasDeclaration(
73888
+ AST11.identifier(definition.name.value),
73889
+ AST11.tsTypeLiteral([
73761
73890
  readonlyProperty(
73762
- AST12.tsPropertySignature(
73763
- AST12.stringLiteral("input"),
73764
- AST12.tsTypeAnnotation(AST12.tsTypeReference(AST12.identifier(inputTypeName)))
73891
+ AST11.tsPropertySignature(
73892
+ AST11.stringLiteral("input"),
73893
+ AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
73765
73894
  )
73766
73895
  ),
73767
73896
  readonlyProperty(
73768
- AST12.tsPropertySignature(
73769
- AST12.stringLiteral("result"),
73770
- AST12.tsTypeAnnotation(
73771
- definition.operation === "mutation" ? AST12.tsTypeReference(AST12.identifier(shapeTypeName)) : AST12.tsUnionType([
73772
- AST12.tsTypeReference(AST12.identifier(shapeTypeName)),
73773
- AST12.tsUndefinedKeyword()
73897
+ AST11.tsPropertySignature(
73898
+ AST11.stringLiteral("result"),
73899
+ AST11.tsTypeAnnotation(
73900
+ definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
73901
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
73902
+ AST11.tsUndefinedKeyword()
73774
73903
  ])
73775
73904
  )
73776
73905
  )
@@ -73778,9 +73907,9 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73778
73907
  ])
73779
73908
  )
73780
73909
  ),
73781
- AST12.exportNamedDeclaration(
73782
- AST12.tsTypeAliasDeclaration(
73783
- AST12.identifier(shapeTypeName),
73910
+ AST11.exportNamedDeclaration(
73911
+ AST11.tsTypeAliasDeclaration(
73912
+ AST11.identifier(shapeTypeName),
73784
73913
  inlineType({
73785
73914
  config: config2,
73786
73915
  filepath,
@@ -73808,15 +73937,15 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73808
73937
  );
73809
73938
  }
73810
73939
  body.push(
73811
- AST12.exportNamedDeclaration(
73812
- AST12.tsTypeAliasDeclaration(
73813
- AST12.identifier(inputTypeName),
73814
- AST12.tsTypeLiteral(
73940
+ AST11.exportNamedDeclaration(
73941
+ AST11.tsTypeAliasDeclaration(
73942
+ AST11.identifier(inputTypeName),
73943
+ AST11.tsTypeLiteral(
73815
73944
  (definition.variableDefinitions || []).map(
73816
73945
  (definition2) => {
73817
- return AST12.tsPropertySignature(
73818
- AST12.identifier(definition2.variable.name.value),
73819
- AST12.tsTypeAnnotation(
73946
+ return AST11.tsPropertySignature(
73947
+ AST11.identifier(definition2.variable.name.value),
73948
+ AST11.tsTypeAnnotation(
73820
73949
  tsTypeReference(config2, missingScalars, definition2)
73821
73950
  ),
73822
73951
  definition2.type.kind !== "NonNullType"
@@ -73829,16 +73958,16 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73829
73958
  );
73830
73959
  } else {
73831
73960
  body.push(
73832
- AST12.exportNamedDeclaration(
73833
- AST12.tsTypeAliasDeclaration(AST12.identifier(inputTypeName), AST12.tsNullKeyword())
73961
+ AST11.exportNamedDeclaration(
73962
+ AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
73834
73963
  )
73835
73964
  );
73836
73965
  }
73837
73966
  if (definition.operation === "mutation") {
73838
73967
  body.push(
73839
- AST12.exportNamedDeclaration(
73840
- AST12.tsTypeAliasDeclaration(
73841
- AST12.identifier(optimisticTypeName),
73968
+ AST11.exportNamedDeclaration(
73969
+ AST11.tsTypeAliasDeclaration(
73970
+ AST11.identifier(optimisticTypeName),
73842
73971
  inlineType({
73843
73972
  config: config2,
73844
73973
  filepath,
@@ -73864,65 +73993,463 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
73864
73993
  }
73865
73994
  const propTypeName = definition.name.value;
73866
73995
  const shapeTypeName = `${definition.name.value}$data`;
73996
+ const inputTypeName = `${definition.name.value}$input`;
73867
73997
  const type = config2.schema.getType(definition.typeCondition.name.value);
73868
73998
  if (!type) {
73869
73999
  throw new Error("Should not get here");
73870
74000
  }
74001
+ let extraExports = [];
74002
+ let directive = definition.directives?.find(
74003
+ (directive2) => directive2.name.value === config2.argumentsDirective
74004
+ );
74005
+ if (directive) {
74006
+ extraExports.push(
74007
+ AST11.exportNamedDeclaration(
74008
+ AST11.tsTypeAliasDeclaration(
74009
+ AST11.identifier(inputTypeName),
74010
+ AST11.tsTypeLiteral(
74011
+ (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
74012
+ (definition2) => {
74013
+ return AST11.tsPropertySignature(
74014
+ AST11.identifier(definition2.variable.name.value),
74015
+ AST11.tsTypeAnnotation(
74016
+ tsTypeReference(config2, missingScalars, definition2)
74017
+ ),
74018
+ definition2.type.kind !== "NonNullType"
74019
+ );
74020
+ }
74021
+ )
74022
+ )
74023
+ )
74024
+ )
74025
+ );
74026
+ }
73871
74027
  body.push(
73872
- AST12.exportNamedDeclaration(
73873
- AST12.tsTypeAliasDeclaration(
73874
- AST12.identifier(propTypeName),
73875
- AST12.tsTypeLiteral([
74028
+ ...extraExports,
74029
+ AST11.exportNamedDeclaration(
74030
+ AST11.tsTypeAliasDeclaration(
74031
+ AST11.identifier(propTypeName),
74032
+ AST11.tsTypeLiteral([
73876
74033
  readonlyProperty(
73877
- AST12.tsPropertySignature(
73878
- AST12.stringLiteral("shape"),
73879
- AST12.tsTypeAnnotation(
73880
- AST12.tsTypeReference(AST12.identifier(shapeTypeName))
74034
+ AST11.tsPropertySignature(
74035
+ AST11.stringLiteral("shape"),
74036
+ AST11.tsTypeAnnotation(
74037
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName))
73881
74038
  ),
73882
74039
  true
73883
74040
  )
73884
74041
  ),
73885
74042
  readonlyProperty(
73886
- AST12.tsPropertySignature(
73887
- AST12.stringLiteral(fragmentKey),
74043
+ AST11.tsPropertySignature(
74044
+ AST11.stringLiteral(fragmentKey),
74045
+ AST11.tsTypeAnnotation(
74046
+ AST11.tsTypeLiteral([
74047
+ AST11.tsPropertySignature(
74048
+ AST11.stringLiteral(propTypeName),
74049
+ AST11.tsTypeAnnotation(
74050
+ AST11.tsLiteralType(AST11.booleanLiteral(true))
74051
+ )
74052
+ )
74053
+ ])
74054
+ )
74055
+ )
74056
+ )
74057
+ ])
74058
+ )
74059
+ ),
74060
+ AST11.exportNamedDeclaration(
74061
+ AST11.tsTypeAliasDeclaration(
74062
+ AST11.identifier(shapeTypeName),
74063
+ inlineType({
74064
+ config: config2,
74065
+ filepath,
74066
+ rootType: type,
74067
+ selections,
74068
+ root: true,
74069
+ allowReadonly: true,
74070
+ body,
74071
+ visitedTypes,
74072
+ missingScalars,
74073
+ includeFragments: true
74074
+ })
74075
+ )
74076
+ )
74077
+ );
74078
+ }
74079
+ }
74080
+
74081
+ // src/codegen/generators/typescript/imperativeTypeDef.ts
74082
+ var graphql19 = __toESM(require_graphql2(), 1);
74083
+ var recast12 = __toESM(require_main2(), 1);
74084
+ var AST12 = recast12.types.builders;
74085
+ async function imperativeCacheTypef(config2, docs) {
74086
+ const returnType = (doc) => config2.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
74087
+ config: config2,
74088
+ doc,
74089
+ ensure_import({ identifier, module: module2 }) {
74090
+ ensureImports({
74091
+ config: config2,
74092
+ body,
74093
+ sourceModule: module2,
74094
+ import: [identifier]
74095
+ });
74096
+ }
74097
+ }) ?? "any";
74098
+ const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
74099
+ const body = [];
74100
+ const declaration = AST12.tsTypeAliasDeclaration(
74101
+ AST12.identifier(CacheTypeDefName),
74102
+ AST12.tsTypeLiteral([
74103
+ AST12.tsPropertySignature(
74104
+ AST12.identifier("types"),
74105
+ AST12.tsTypeAnnotation(typeDefinitions(config2, body, docs, returnType))
74106
+ ),
74107
+ AST12.tsPropertySignature(
74108
+ AST12.identifier("lists"),
74109
+ AST12.tsTypeAnnotation(listDefinitions(config2, docs))
74110
+ ),
74111
+ AST12.tsPropertySignature(
74112
+ AST12.identifier("queries"),
74113
+ AST12.tsTypeAnnotation(queryDefinitions(config2, body, docs, returnType))
74114
+ )
74115
+ ])
74116
+ );
74117
+ declaration.declare = true;
74118
+ const importRecord = AST12.importDeclaration(
74119
+ [AST12.importSpecifier(AST12.identifier("Record"))],
74120
+ AST12.stringLiteral("./public/record")
74121
+ );
74122
+ importRecord.importKind = "type";
74123
+ await fs_exports.writeFile(
74124
+ target,
74125
+ recast12.prettyPrint(
74126
+ AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
74127
+ ).code
74128
+ );
74129
+ }
74130
+ function typeDefinitions(config2, body, docs, returnType) {
74131
+ const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
74132
+ const visitedTypes = /* @__PURE__ */ new Set();
74133
+ const types16 = Object.values(config2.schema.getTypeMap()).filter(
74134
+ (type) => !graphql19.isAbstractType(type) && !graphql19.isScalarType(type) && !graphql19.isEnumType(type) && !graphql19.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
74135
+ );
74136
+ const fragmentMap = fragmentListMap(
74137
+ config2,
74138
+ types16.map((type) => type.name),
74139
+ body,
74140
+ docs,
74141
+ returnType
74142
+ );
74143
+ return AST12.tsTypeLiteral(
74144
+ types16.map((type) => {
74145
+ let typeName = type.name;
74146
+ if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
74147
+ typeName = "__ROOT__";
74148
+ }
74149
+ let idFields = AST12.tsNeverKeyword();
74150
+ const keys = keyFieldsForType(config2.configFile, type.name);
74151
+ if (graphql19.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
74152
+ idFields = AST12.tsTypeLiteral(
74153
+ keys.map((key) => {
74154
+ const fieldType = type.getFields()[key];
74155
+ const unwrapped = unwrapType(config2, fieldType.type);
74156
+ return AST12.tsPropertySignature(
74157
+ AST12.identifier(key),
74158
+ AST12.tsTypeAnnotation(
74159
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
74160
+ )
74161
+ );
74162
+ })
74163
+ );
74164
+ } else if (typeName === "__ROOT__") {
74165
+ idFields = AST12.tsTypeLiteral([]);
74166
+ }
74167
+ let fields = AST12.tsTypeLiteral([]);
74168
+ if (graphql19.isObjectType(type)) {
74169
+ fields = AST12.tsTypeLiteral(
74170
+ Object.entries(type.getFields()).map(
74171
+ ([key, fieldType]) => {
74172
+ const unwrapped = unwrapType(config2, fieldType.type);
74173
+ let typeOptions = AST12.tsUnionType([]);
74174
+ if (graphql19.isScalarType(unwrapped.type)) {
74175
+ typeOptions.types.push(
74176
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
74177
+ );
74178
+ } else if (graphql19.isEnumType(unwrapped.type)) {
74179
+ typeOptions.types.push(
74180
+ AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
74181
+ );
74182
+ } else if (!graphql19.isAbstractType(unwrapped.type)) {
74183
+ typeOptions.types.push(record(unwrapped.type.name));
74184
+ } else {
74185
+ typeOptions.types.push(
74186
+ ...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
74187
+ );
74188
+ }
74189
+ for (const wrapper of unwrapped.wrappers) {
74190
+ if (wrapper === "Nullable" /* Nullable */) {
74191
+ typeOptions = AST12.tsParenthesizedType(
74192
+ AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
74193
+ );
74194
+ } else if (wrapper === "List" /* List */) {
74195
+ typeOptions = AST12.tsArrayType(
74196
+ AST12.tsParenthesizedType(typeOptions)
74197
+ );
74198
+ }
74199
+ }
74200
+ if (typeOptions.type === "TSParenthesizedType") {
74201
+ typeOptions = typeOptions.typeAnnotation;
74202
+ }
74203
+ let args = AST12.tsNeverKeyword();
74204
+ if (fieldType.args?.length > 0) {
74205
+ args = AST12.tsTypeLiteral(
74206
+ fieldType.args.map((arg) => {
74207
+ addReferencedInputTypes(
74208
+ config2,
74209
+ "",
74210
+ body,
74211
+ visitedTypes,
74212
+ /* @__PURE__ */ new Set(),
74213
+ arg.type
74214
+ );
74215
+ const prop = AST12.tsPropertySignature(
74216
+ AST12.identifier(arg.name),
74217
+ AST12.tsTypeAnnotation(
74218
+ tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
74219
+ )
74220
+ );
74221
+ const unwrapped2 = unwrapType(config2, arg.type);
74222
+ prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
74223
+ return prop;
74224
+ })
74225
+ );
74226
+ }
74227
+ return AST12.tsPropertySignature(
74228
+ AST12.identifier(key),
73888
74229
  AST12.tsTypeAnnotation(
73889
74230
  AST12.tsTypeLiteral([
73890
74231
  AST12.tsPropertySignature(
73891
- AST12.stringLiteral(propTypeName),
73892
- AST12.tsTypeAnnotation(
73893
- AST12.tsLiteralType(AST12.booleanLiteral(true))
73894
- )
74232
+ AST12.identifier("type"),
74233
+ AST12.tsTypeAnnotation(typeOptions)
74234
+ ),
74235
+ AST12.tsPropertySignature(
74236
+ AST12.identifier("args"),
74237
+ AST12.tsTypeAnnotation(args)
73895
74238
  )
73896
74239
  ])
73897
74240
  )
73898
- )
74241
+ );
74242
+ }
74243
+ )
74244
+ );
74245
+ }
74246
+ return AST12.tsPropertySignature(
74247
+ AST12.identifier(typeName),
74248
+ AST12.tsTypeAnnotation(
74249
+ AST12.tsTypeLiteral([
74250
+ AST12.tsPropertySignature(
74251
+ AST12.identifier("idFields"),
74252
+ AST12.tsTypeAnnotation(idFields)
74253
+ ),
74254
+ AST12.tsPropertySignature(
74255
+ AST12.identifier("fields"),
74256
+ AST12.tsTypeAnnotation(fields)
74257
+ ),
74258
+ AST12.tsPropertySignature(
74259
+ AST12.identifier("fragments"),
74260
+ AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
73899
74261
  )
73900
74262
  ])
73901
74263
  )
74264
+ );
74265
+ })
74266
+ );
74267
+ }
74268
+ function listDefinitions(config2, docs) {
74269
+ const lists = [];
74270
+ const visitedLists = /* @__PURE__ */ new Set();
74271
+ for (const doc of docs) {
74272
+ graphql19.visit(doc.document, {
74273
+ Directive(node, key, parent, path2, ancestors) {
74274
+ if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
74275
+ return;
74276
+ }
74277
+ const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
74278
+ const nameValue = nameArg?.value?.value || "";
74279
+ if (!nameValue || visitedLists.has(nameValue)) {
74280
+ return;
74281
+ }
74282
+ visitedLists.add(nameValue);
74283
+ const parentType = parentTypeFromAncestors(
74284
+ config2.schema,
74285
+ doc.filename,
74286
+ ancestors.slice(0, -1)
74287
+ );
74288
+ const targetField = ancestors[ancestors.length - 1];
74289
+ const targetFieldDefinition = parentType.getFields()[targetField.name.value];
74290
+ const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
74291
+ const possibleTypes = [];
74292
+ if (graphql19.isAbstractType(listType)) {
74293
+ possibleTypes.push(
74294
+ ...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
74295
+ );
74296
+ } else {
74297
+ possibleTypes.push(listType.name);
74298
+ }
74299
+ lists.push(
74300
+ AST12.tsPropertySignature(
74301
+ AST12.identifier(nameValue),
74302
+ AST12.tsTypeAnnotation(
74303
+ AST12.tsTypeLiteral([
74304
+ AST12.tsPropertySignature(
74305
+ AST12.identifier("types"),
74306
+ AST12.tsTypeAnnotation(
74307
+ AST12.tsUnionType(
74308
+ possibleTypes.map(
74309
+ (possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
74310
+ )
74311
+ )
74312
+ )
74313
+ ),
74314
+ AST12.tsPropertySignature(
74315
+ AST12.identifier("filters"),
74316
+ AST12.tsTypeAnnotation(
74317
+ targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
74318
+ targetFieldDefinition.args.map((arg) => {
74319
+ const argDef = AST12.tsPropertySignature(
74320
+ AST12.identifier(arg.name),
74321
+ AST12.tsTypeAnnotation(
74322
+ tsTypeReference(
74323
+ config2,
74324
+ /* @__PURE__ */ new Set(),
74325
+ arg
74326
+ )
74327
+ )
74328
+ );
74329
+ argDef.optional = true;
74330
+ return argDef;
74331
+ })
74332
+ )
74333
+ )
74334
+ )
74335
+ ])
74336
+ )
74337
+ )
74338
+ );
74339
+ }
74340
+ });
74341
+ }
74342
+ return AST12.tsTypeLiteral(lists);
74343
+ }
74344
+ function queryDefinitions(config2, body, docs, returnType) {
74345
+ return AST12.tsTupleType(
74346
+ docs.reduce((prev, doc) => {
74347
+ if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
74348
+ return prev;
74349
+ }
74350
+ const definition = doc.document.definitions.find(
74351
+ (def) => def.kind === "OperationDefinition" && def.operation === "query"
74352
+ );
74353
+ if (!definition) {
74354
+ return prev;
74355
+ }
74356
+ const runtimeType = returnType(doc);
74357
+ const [shapeType, inputType] = ensureImports({
74358
+ config: config2,
74359
+ body,
74360
+ sourceModule: path_exports.relative(
74361
+ config2.runtimeDirectory,
74362
+ config2.artifactImportPath(doc.name)
74363
+ ),
74364
+ import: [`${doc.name}$result`, `${doc.name}$input`]
74365
+ });
74366
+ return prev.concat(
74367
+ AST12.tsTupleType([
74368
+ AST12.tsTypeReference(AST12.identifier(runtimeType)),
74369
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
74370
+ AST12.tsTypeReference(AST12.identifier(inputType))
74371
+ ])
74372
+ );
74373
+ }, [])
74374
+ );
74375
+ }
74376
+ function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
74377
+ return docs.reduce((prev, doc) => {
74378
+ if (doc.kind !== "HoudiniFragment" /* Fragment */) {
74379
+ return prev;
74380
+ }
74381
+ const definition = doc.document.definitions.find(
74382
+ (def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
74383
+ );
74384
+ if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
74385
+ return prev;
74386
+ }
74387
+ const typeName = definition.typeCondition.name.value;
74388
+ const previousValue = prev[typeName]?.elementTypes ?? [];
74389
+ const tagResult = return_type(doc);
74390
+ const [shapeType] = ensureImports({
74391
+ config: config2,
74392
+ body,
74393
+ sourceModule: path_exports.relative(
74394
+ config2.runtimeDirectory,
74395
+ config2.artifactImportPath(doc.name)
73902
74396
  ),
73903
- AST12.exportNamedDeclaration(
73904
- AST12.tsTypeAliasDeclaration(
73905
- AST12.identifier(shapeTypeName),
73906
- inlineType({
74397
+ import: [`${definition.name.value}$data`]
74398
+ });
74399
+ let inputType = AST12.tsNeverKeyword();
74400
+ let directive = definition.directives?.find(
74401
+ (directive2) => directive2.name.value === config2.argumentsDirective
74402
+ );
74403
+ if (directive) {
74404
+ inputType = AST12.tsTypeReference(
74405
+ AST12.identifier(
74406
+ ensureImports({
73907
74407
  config: config2,
73908
- filepath,
73909
- rootType: type,
73910
- selections,
73911
- root: true,
73912
- allowReadonly: true,
73913
74408
  body,
73914
- visitedTypes,
73915
- missingScalars,
73916
- includeFragments: true
73917
- })
74409
+ sourceModule: path_exports.relative(
74410
+ config2.runtimeDirectory,
74411
+ config2.artifactImportPath(doc.name)
74412
+ ),
74413
+ import: [`${definition.name.value}$input`]
74414
+ })[0]
74415
+ )
74416
+ );
74417
+ }
74418
+ return {
74419
+ ...prev,
74420
+ [typeName]: AST12.tsTupleType(
74421
+ previousValue.concat(
74422
+ AST12.tsTupleType([
74423
+ AST12.tsTypeReference(AST12.identifier(tagResult)),
74424
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
74425
+ inputType
74426
+ ])
73918
74427
  )
73919
74428
  )
73920
- );
73921
- }
74429
+ };
74430
+ }, {});
74431
+ }
74432
+ var CacheTypeDefName = "CacheTypeDef";
74433
+ function record(name2) {
74434
+ return AST12.tsTypeReference(
74435
+ AST12.identifier("Record"),
74436
+ AST12.tsTypeParameterInstantiation([
74437
+ AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
74438
+ AST12.tsLiteralType(AST12.stringLiteral(name2))
74439
+ ])
74440
+ );
74441
+ }
74442
+
74443
+ // src/codegen/generators/typescript/index.ts
74444
+ async function typescriptGenerator(config2, docs) {
74445
+ await Promise.all([
74446
+ generateDocumentTypes(config2, docs),
74447
+ imperativeCacheTypef(config2, docs)
74448
+ ]);
73922
74449
  }
73923
74450
 
73924
74451
  // src/codegen/generators/persistedQueries/index.ts
73925
- var graphql19 = __toESM(require_graphql2(), 1);
74452
+ var graphql20 = __toESM(require_graphql2(), 1);
73926
74453
  async function persistOutputGenerator(config2, docs) {
73927
74454
  if (typeof config2.persistedQueryPath !== "string" || config2.persistedQueryPath.length === 0)
73928
74455
  return;
@@ -73934,8 +74461,8 @@ async function persistOutputGenerator(config2, docs) {
73934
74461
  if (!generateArtifact) {
73935
74462
  return acc;
73936
74463
  }
73937
- let rawString = graphql19.print(
73938
- graphql19.visit(document, {
74464
+ let rawString = graphql20.print(
74465
+ graphql20.visit(document, {
73939
74466
  Directive(node) {
73940
74467
  if (config2.isInternalDirective(node)) {
73941
74468
  return null;
@@ -73944,7 +74471,7 @@ async function persistOutputGenerator(config2, docs) {
73944
74471
  })
73945
74472
  );
73946
74473
  const operations = document.definitions.filter(
73947
- ({ kind }) => kind === graphql19.Kind.OPERATION_DEFINITION
74474
+ ({ kind }) => kind === graphql20.Kind.OPERATION_DEFINITION
73948
74475
  );
73949
74476
  if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
73950
74477
  acc[hashDocument(rawString)] = rawString;
@@ -73957,11 +74484,11 @@ async function persistOutputGenerator(config2, docs) {
73957
74484
  }
73958
74485
 
73959
74486
  // src/codegen/generators/definitions/enums.ts
73960
- var graphql20 = __toESM(require_graphql2(), 1);
74487
+ var graphql21 = __toESM(require_graphql2(), 1);
73961
74488
  var recast13 = __toESM(require_main2(), 1);
73962
74489
  var AST13 = recast13.types.builders;
73963
74490
  async function definitionsGenerator(config2) {
73964
- const enums = graphql20.parse(graphql20.printSchema(config2.schema)).definitions.filter(
74491
+ const enums = graphql21.parse(graphql21.printSchema(config2.schema)).definitions.filter(
73965
74492
  (definition) => definition.kind === "EnumTypeDefinition"
73966
74493
  ).filter((def) => !config2.isInternalEnum(def));
73967
74494
  const runtimeDefinitions = recast13.print(
@@ -74035,107 +74562,24 @@ async function writeIndexFile2(config2, docs) {
74035
74562
  export_default_as,
74036
74563
  export_star_from,
74037
74564
  plugin_root: config2.pluginDirectory(plugin.name),
74038
- typedef: false,
74039
- documents: docs
74040
- });
74041
- }
74042
- if (plugin.include_runtime) {
74043
- body += export_star_from({
74044
- module: relative2(config2.pluginRuntimeDirectory(plugin.name))
74045
- });
74046
- }
74047
- if (!plugin.index_file) {
74048
- continue;
74049
- }
74050
- }
74051
- await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
74052
- }
74053
-
74054
- // src/codegen/transforms/composeQueries.ts
74055
- var import_graphql30 = __toESM(require_graphql2(), 1);
74056
- async function includeFragmentDefinitions(config2, documents) {
74057
- const fragments = collectFragments(config2, documents);
74058
- for (const [index, { name: name2, document, filename }] of documents.entries()) {
74059
- const operation = document.definitions.find(
74060
- ({ kind }) => kind === import_graphql30.Kind.OPERATION_DEFINITION
74061
- );
74062
- if (!operation) {
74063
- continue;
74064
- }
74065
- const allFragments = flattenFragments(
74066
- filename,
74067
- { requiredFragments: findRequiredFragments(operation.selectionSet) },
74068
- fragments
74069
- );
74070
- documents[index].document = {
74071
- ...document,
74072
- definitions: [
74073
- operation,
74074
- ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
74075
- ]
74076
- };
74077
- }
74078
- }
74079
- function collectFragments(config2, docs) {
74080
- return docs.reduce((acc, doc) => {
74081
- const definitions = doc.document.definitions.reduce(
74082
- (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
74083
- ...prev,
74084
- [definition.name.value]: {
74085
- definition,
74086
- requiredFragments: findRequiredFragments(definition.selectionSet),
74087
- document: doc
74088
- }
74089
- },
74090
- {}
74091
- );
74092
- return {
74093
- ...acc,
74094
- ...definitions
74095
- };
74096
- }, {});
74097
- }
74098
- function findRequiredFragments(selectionSet) {
74099
- if (selectionSet.selections.length === 0) {
74100
- return [];
74101
- }
74102
- const referencedFragments = [];
74103
- for (const selection2 of selectionSet.selections) {
74104
- if (selection2.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
74105
- referencedFragments.push(selection2.name.value);
74106
- } else if (selection2.selectionSet) {
74107
- referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
74108
- }
74109
- }
74110
- return referencedFragments;
74111
- }
74112
- function flattenFragments(filepath, operation, fragments) {
74113
- const frags = /* @__PURE__ */ new Set();
74114
- const remaining = [...operation.requiredFragments];
74115
- while (remaining.length > 0) {
74116
- const nextFragment = remaining.shift();
74117
- if (!nextFragment) {
74118
- continue;
74119
- }
74120
- if (!frags.has(nextFragment)) {
74121
- frags.add(nextFragment);
74122
- } else {
74123
- continue;
74565
+ typedef: false,
74566
+ documents: docs
74567
+ });
74124
74568
  }
74125
- const targetFragment = fragments[nextFragment];
74126
- if (!targetFragment) {
74127
- throw new HoudiniError({
74128
- filepath,
74129
- message: "compose: could not find definition for fragment " + nextFragment
74569
+ if (plugin.include_runtime) {
74570
+ body += export_star_from({
74571
+ module: relative2(config2.pluginRuntimeDirectory(plugin.name))
74130
74572
  });
74131
74573
  }
74132
- remaining.push(...targetFragment.requiredFragments);
74574
+ if (!plugin.index_file) {
74575
+ continue;
74576
+ }
74133
74577
  }
74134
- return [...frags];
74578
+ await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
74135
74579
  }
74136
74580
 
74137
74581
  // src/codegen/transforms/schema.ts
74138
- var graphql21 = __toESM(require_graphql2(), 1);
74582
+ var graphql22 = __toESM(require_graphql2(), 1);
74139
74583
  async function graphqlExtensions(config2, documents) {
74140
74584
  const internalSchema = `
74141
74585
  enum CachePolicy {
@@ -74169,407 +74613,147 @@ directive @${config2.listAppendDirective} on FRAGMENT_SPREAD
74169
74613
 
74170
74614
  """
74171
74615
  @${config2.listAllListsDirective} is used to tell the runtime to add the result to all list
74172
- """
74173
- directive @${config2.listAllListsDirective} on FRAGMENT_SPREAD
74174
-
74175
- """
74176
- @${config2.listParentDirective} is used to provide a parentID without specifying position or in situations
74177
- where it doesn't make sense (eg when deleting a node.)
74178
- """
74179
- directive @${config2.listParentDirective}(value: ID!) on FRAGMENT_SPREAD
74180
-
74181
- """
74182
- @${config2.whenDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
74183
- """
74184
- directive @${config2.whenDirective} on FRAGMENT_SPREAD
74185
-
74186
- """
74187
- @${config2.whenNotDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
74188
- """
74189
- directive @${config2.whenNotDirective} on FRAGMENT_SPREAD
74190
-
74191
- """
74192
- @${config2.argumentsDirective} is used to define the arguments of a fragment
74193
- """
74194
- directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
74195
-
74196
- """
74197
- @${config2.cacheDirective} is used to specify cache rules for a query
74198
- """
74199
- directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
74200
-
74201
- """
74202
- @${config2.manualLoadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
74203
- """
74204
- directive @${config2.manualLoadDirective} on QUERY
74205
-
74206
- """
74207
- @${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
74208
- """
74209
- directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
74210
-
74211
- """
74212
- @${config2.maskDisableDirective} to disable masking on fragment (overwriting the global conf)
74213
- """
74214
- directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
74215
- `;
74216
- let currentSchema = graphql21.printSchema(config2.schema);
74217
- if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
74218
- currentSchema += internalSchema;
74219
- }
74220
- config2.newSchema += internalSchema;
74221
- config2.schema = graphql21.buildSchema(currentSchema);
74222
- }
74223
-
74224
- // src/codegen/transforms/typename.ts
74225
- var graphql22 = __toESM(require_graphql2(), 1);
74226
- async function addTypename(config2, documents) {
74227
- for (const doc of documents) {
74228
- doc.document = graphql22.visit(doc.document, {
74229
- Field(node, key, parent, path2, ancestors) {
74230
- if (!node.selectionSet) {
74231
- return;
74232
- }
74233
- const type = parentTypeFromAncestors(
74234
- config2.schema,
74235
- doc.filename,
74236
- ancestors.slice(0, -1)
74237
- );
74238
- const field = type.getFields()[node.name.value];
74239
- const fieldType = unwrapType(config2, field.type).type;
74240
- if (graphql22.isInterfaceType(fieldType) || graphql22.isUnionType(fieldType)) {
74241
- return {
74242
- ...node,
74243
- selectionSet: {
74244
- ...node.selectionSet,
74245
- selections: [
74246
- ...node.selectionSet.selections,
74247
- {
74248
- kind: graphql22.Kind.FIELD,
74249
- name: {
74250
- kind: graphql22.Kind.NAME,
74251
- value: "__typename"
74252
- }
74253
- }
74254
- ]
74255
- }
74256
- };
74257
- }
74258
- }
74259
- });
74260
- }
74261
- }
74262
-
74263
- // src/codegen/transforms/addID.ts
74264
- var graphql23 = __toESM(require_graphql2(), 1);
74265
- async function addID(config2, documents) {
74266
- for (const doc of documents) {
74267
- doc.document = graphql23.visit(doc.document, {
74268
- Field(node, key, parent, path2, ancestors) {
74269
- if (!node.selectionSet) {
74270
- return;
74271
- }
74272
- const type = parentTypeFromAncestors(
74273
- config2.schema,
74274
- doc.filename,
74275
- ancestors.slice(0, -1)
74276
- );
74277
- const field = type.getFields()[node.name.value];
74278
- const fieldType = unwrapType(config2, field.type).type;
74279
- if (node.selectionSet?.selections.length > 0) {
74280
- if (!graphql23.isObjectType(fieldType) && !graphql23.isInterfaceType(fieldType)) {
74281
- return;
74282
- }
74283
- const keyFields = config2.keyFieldsForType(fieldType.name);
74284
- if (keyFields.find((key2) => !fieldType.getFields()[key2])) {
74285
- return;
74286
- }
74287
- const selections = [...node.selectionSet.selections];
74288
- for (const keyField of keyFields) {
74289
- if (node.selectionSet.selections.find(
74290
- (selection2) => selection2.kind === "Field" && !selection2.alias && selection2.name.value === keyField
74291
- )) {
74292
- continue;
74293
- }
74294
- selections.push({
74295
- kind: graphql23.Kind.FIELD,
74296
- name: {
74297
- kind: graphql23.Kind.NAME,
74298
- value: keyField
74299
- }
74300
- });
74301
- }
74302
- return {
74303
- ...node,
74304
- selectionSet: {
74305
- ...node.selectionSet,
74306
- selections
74307
- }
74308
- };
74309
- }
74310
- }
74311
- });
74312
- }
74313
- }
74314
-
74315
- // src/codegen/transforms/fragmentVariables.ts
74316
- var graphql24 = __toESM(require_graphql2(), 1);
74317
- var GraphqlKinds2 = graphql24.Kind;
74318
- async function fragmentVariables(config2, documents) {
74319
- const fragments = collectFragments(config2, documents);
74320
- const generatedFragments = {};
74321
- const visitedFragments = /* @__PURE__ */ new Set();
74322
- for (const doc2 of documents) {
74323
- const operation = doc2.document.definitions.find(
74324
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
74325
- );
74326
- if (!operation) {
74327
- continue;
74328
- }
74329
- doc2.document = inlineFragmentArgs({
74330
- config: config2,
74331
- filepath: doc2.filename,
74332
- fragmentDefinitions: fragments,
74333
- document: doc2.document,
74334
- generatedFragments,
74335
- visitedFragments,
74336
- scope: null
74337
- });
74338
- }
74339
- const doc = {
74340
- kind: graphql24.Kind.DOCUMENT,
74341
- definitions: Object.values(generatedFragments)
74342
- };
74343
- documents.push({
74344
- name: "generated::fragmentVariables",
74345
- kind: "HoudiniFragment" /* Fragment */,
74346
- document: doc,
74347
- originalDocument: doc,
74348
- generateStore: false,
74349
- generateArtifact: false,
74350
- filename: "generated::fragmentVariables",
74351
- originalString: ""
74352
- });
74353
- }
74354
- function inlineFragmentArgs({
74355
- config: config2,
74356
- filepath,
74357
- fragmentDefinitions,
74358
- document,
74359
- generatedFragments,
74360
- visitedFragments,
74361
- scope,
74362
- newName
74363
- }) {
74364
- if (!scope) {
74365
- scope = operationScope(
74366
- document.definitions.find(
74367
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
74368
- )
74369
- );
74370
- }
74371
- const definitionArgs = fragmentArguments(
74372
- config2,
74373
- filepath,
74374
- document
74375
- ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
74376
- const result = graphql24.visit(document, {
74377
- FragmentSpread(node) {
74378
- const { definition } = fragmentDefinitions[node.name.value];
74379
- let { args, hash } = collectWithArguments(config2, filepath, node, scope);
74380
- const newFragmentName = `${node.name.value}${hash}`;
74381
- if (!visitedFragments.has(newFragmentName)) {
74382
- visitedFragments.add(newFragmentName);
74383
- const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
74384
- if (args) {
74385
- for (const [field, value] of Object.entries(defaultArguments || {})) {
74386
- if (!args[field]) {
74387
- args[field] = value;
74388
- }
74389
- }
74390
- generatedFragments[newFragmentName] = inlineFragmentArgs({
74391
- config: config2,
74392
- filepath,
74393
- fragmentDefinitions,
74394
- document: fragmentDefinitions[node.name.value].definition,
74395
- generatedFragments,
74396
- visitedFragments,
74397
- scope: args,
74398
- newName: newFragmentName
74399
- });
74400
- } else {
74401
- const doc = fragmentDefinitions[node.name.value].document;
74402
- const definitionIndex = doc.document.definitions.findIndex(
74403
- (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
74404
- );
74405
- const localDefinitions = [...doc.document.definitions];
74406
- localDefinitions.splice(definitionIndex, 1);
74407
- localDefinitions.push(
74408
- inlineFragmentArgs({
74409
- config: config2,
74410
- filepath,
74411
- fragmentDefinitions,
74412
- document: fragmentDefinitions[node.name.value].definition,
74413
- generatedFragments,
74414
- visitedFragments,
74415
- scope: defaultArguments,
74416
- newName: ""
74417
- })
74418
- );
74419
- doc.document = {
74420
- ...doc.document,
74421
- definitions: localDefinitions
74422
- };
74616
+ """
74617
+ directive @${config2.listAllListsDirective} on FRAGMENT_SPREAD
74618
+
74619
+ """
74620
+ @${config2.listParentDirective} is used to provide a parentID without specifying position or in situations
74621
+ where it doesn't make sense (eg when deleting a node.)
74622
+ """
74623
+ directive @${config2.listParentDirective}(value: ID!) on FRAGMENT_SPREAD
74624
+
74625
+ """
74626
+ @${config2.whenDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
74627
+ """
74628
+ directive @${config2.whenDirective} on FRAGMENT_SPREAD
74629
+
74630
+ """
74631
+ @${config2.whenNotDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
74632
+ """
74633
+ directive @${config2.whenNotDirective} on FRAGMENT_SPREAD
74634
+
74635
+ """
74636
+ @${config2.argumentsDirective} is used to define the arguments of a fragment
74637
+ """
74638
+ directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
74639
+
74640
+ """
74641
+ @${config2.cacheDirective} is used to specify cache rules for a query
74642
+ """
74643
+ directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
74644
+
74645
+ """
74646
+ @${config2.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
74647
+ """
74648
+ directive @${config2.loadDirective} on QUERY
74649
+
74650
+ """
74651
+ @${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
74652
+ """
74653
+ directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
74654
+
74655
+ """
74656
+ @${config2.maskDisableDirective} to disable masking on fragment (overwriting the global conf)
74657
+ """
74658
+ directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
74659
+ `;
74660
+ let currentSchema = graphql22.printSchema(config2.schema);
74661
+ if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
74662
+ currentSchema += internalSchema;
74663
+ }
74664
+ config2.newSchema += internalSchema;
74665
+ config2.schema = graphql22.buildSchema(currentSchema);
74666
+ }
74667
+
74668
+ // src/codegen/transforms/typename.ts
74669
+ var graphql23 = __toESM(require_graphql2(), 1);
74670
+ async function addTypename(config2, documents) {
74671
+ for (const doc of documents) {
74672
+ doc.document = graphql23.visit(doc.document, {
74673
+ Field(node, key, parent, path2, ancestors) {
74674
+ if (!node.selectionSet) {
74675
+ return;
74423
74676
  }
74424
- if (node.name.value !== newFragmentName) {
74677
+ const type = parentTypeFromAncestors(
74678
+ config2.schema,
74679
+ doc.filename,
74680
+ ancestors.slice(0, -1)
74681
+ );
74682
+ const field = type.getFields()[node.name.value];
74683
+ const fieldType = unwrapType(config2, field.type).type;
74684
+ if (graphql23.isInterfaceType(fieldType) || graphql23.isUnionType(fieldType)) {
74425
74685
  return {
74426
74686
  ...node,
74427
- name: {
74428
- kind: "Name",
74429
- value: newFragmentName
74687
+ selectionSet: {
74688
+ ...node.selectionSet,
74689
+ selections: [
74690
+ ...node.selectionSet.selections,
74691
+ {
74692
+ kind: graphql23.Kind.FIELD,
74693
+ name: {
74694
+ kind: graphql23.Kind.NAME,
74695
+ value: "__typename"
74696
+ }
74697
+ }
74698
+ ]
74430
74699
  }
74431
74700
  };
74432
74701
  }
74433
74702
  }
74434
- },
74435
- Argument(node) {
74436
- const value = node.value;
74437
- if (value.kind !== "Variable") {
74438
- return;
74439
- }
74440
- if (!scope) {
74441
- throw new HoudiniError({
74442
- filepath,
74443
- message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
74444
- });
74445
- }
74446
- const newValue = scope[value.name.value];
74447
- if (newValue) {
74448
- return {
74449
- ...node,
74450
- value: newValue
74451
- };
74452
- }
74453
- if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
74454
- throw new HoudiniError({
74455
- filepath,
74456
- message: "Missing value for required arg: " + value.name.value
74457
- });
74458
- }
74459
- return null;
74460
- }
74461
- });
74462
- if (newName) {
74463
- result.name = {
74464
- kind: graphql24.Kind.NAME,
74465
- value: newName
74466
- };
74467
- }
74468
- return result;
74469
- }
74470
- function withArguments(config2, node) {
74471
- const withDirectives = node.directives?.filter(
74472
- (directive) => directive.name.value === config2.withDirective
74473
- );
74474
- if (!withDirectives || withDirectives.length === 0) {
74475
- return [];
74703
+ });
74476
74704
  }
74477
- return withDirectives.flatMap((directive) => directive.arguments || []);
74478
74705
  }
74479
- function fragmentArguments(config2, filepath, definition) {
74480
- const directives = definition.directives?.filter(
74481
- (directive) => directive.name.value === config2.argumentsDirective
74482
- );
74483
- if (!directives || directives.length === 0) {
74484
- return [];
74485
- }
74486
- return directives.flatMap(
74487
- (directive) => directive.arguments?.flatMap((arg) => {
74488
- if (arg.value.kind !== "ObjectValue") {
74489
- throw new HoudiniError({
74490
- filepath,
74491
- message: "values of @argument must be objects"
74492
- });
74493
- }
74494
- const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
74495
- if (!typeArg || typeArg.kind !== "StringValue") {
74496
- return [];
74497
- }
74498
- let type = typeArg.value;
74499
- let name2 = arg.name.value;
74500
- let required = false;
74501
- let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
74502
- if (type[type.length - 1] === "!") {
74503
- type = type.slice(0, -1);
74504
- required = true;
74505
- defaultValue = null;
74506
- }
74507
- return [
74508
- {
74509
- name: name2,
74510
- type,
74511
- required,
74512
- defaultValue
74706
+
74707
+ // src/codegen/transforms/addID.ts
74708
+ var graphql24 = __toESM(require_graphql2(), 1);
74709
+ async function addID(config2, documents) {
74710
+ for (const doc of documents) {
74711
+ doc.document = graphql24.visit(doc.document, {
74712
+ Field(node, key, parent, path2, ancestors) {
74713
+ if (!node.selectionSet) {
74714
+ return;
74513
74715
  }
74514
- ];
74515
- }) || []
74516
- );
74517
- }
74518
- function collectDefaultArgumentValues(config2, filepath, definition) {
74519
- let result = {};
74520
- for (const { name: name2, required, defaultValue } of fragmentArguments(
74521
- config2,
74522
- filepath,
74523
- definition
74524
- )) {
74525
- if (required || !defaultValue) {
74526
- continue;
74527
- }
74528
- result[name2] = defaultValue;
74529
- }
74530
- return result;
74531
- }
74532
- function collectWithArguments(config2, filepath, node, scope = {}) {
74533
- const withArgs = withArguments(config2, node);
74534
- if (withArgs.length === 0) {
74535
- return { args: null, hash: "" };
74536
- }
74537
- let args = {};
74538
- for (const arg of withArgs) {
74539
- let value = arg.value;
74540
- if (value.kind === GraphqlKinds2.VARIABLE) {
74541
- if (!scope || !scope[value.name.value]) {
74542
- throw new HoudiniError({
74543
- filepath,
74544
- message: "Encountered undefined variable: " + value.name.value
74545
- });
74546
- }
74547
- value = scope[value.name.value];
74548
- }
74549
- args[arg.name.value] = {
74550
- ...value,
74551
- loc: void 0
74552
- };
74553
- }
74554
- return {
74555
- args,
74556
- hash: "_" + murmurHash(JSON.stringify(args))
74557
- };
74558
- }
74559
- function operationScope(operation) {
74560
- return operation.variableDefinitions?.reduce(
74561
- (scope, definition) => ({
74562
- ...scope,
74563
- [definition.variable.name.value]: {
74564
- kind: "Variable",
74565
- name: {
74566
- kind: "Name",
74567
- value: definition.variable.name.value
74716
+ const type = parentTypeFromAncestors(
74717
+ config2.schema,
74718
+ doc.filename,
74719
+ ancestors.slice(0, -1)
74720
+ );
74721
+ const field = type.getFields()[node.name.value];
74722
+ const fieldType = unwrapType(config2, field.type).type;
74723
+ if (node.selectionSet?.selections.length > 0) {
74724
+ if (!graphql24.isObjectType(fieldType) && !graphql24.isInterfaceType(fieldType)) {
74725
+ return;
74726
+ }
74727
+ const keyFields = config2.keyFieldsForType(fieldType.name);
74728
+ if (keyFields.find((key2) => !fieldType.getFields()[key2])) {
74729
+ return;
74730
+ }
74731
+ const selections = [...node.selectionSet.selections];
74732
+ for (const keyField of keyFields) {
74733
+ if (node.selectionSet.selections.find(
74734
+ (selection2) => selection2.kind === "Field" && !selection2.alias && selection2.name.value === keyField
74735
+ )) {
74736
+ continue;
74737
+ }
74738
+ selections.push({
74739
+ kind: graphql24.Kind.FIELD,
74740
+ name: {
74741
+ kind: graphql24.Kind.NAME,
74742
+ value: keyField
74743
+ }
74744
+ });
74745
+ }
74746
+ return {
74747
+ ...node,
74748
+ selectionSet: {
74749
+ ...node.selectionSet,
74750
+ selections
74751
+ }
74752
+ };
74568
74753
  }
74569
74754
  }
74570
- }),
74571
- {}
74572
- ) || {};
74755
+ });
74756
+ }
74573
74757
  }
74574
74758
 
74575
74759
  // src/codegen/validators/typeCheck.ts
@@ -75922,7 +76106,9 @@ var writeConfigFile = async ({
75922
76106
  }) => {
75923
76107
  const config2 = {};
75924
76108
  if (url !== null) {
75925
- config2.apiUrl = url;
76109
+ config2.watchSchema = {
76110
+ url
76111
+ };
75926
76112
  }
75927
76113
  if (schemaPath !== "./schema.graphql") {
75928
76114
  config2.schemaPath = schemaPath;
@@ -76088,8 +76274,8 @@ async function updatePackageJSON(targetPath) {
76088
76274
  }
76089
76275
  packageJSON.devDependencies = {
76090
76276
  ...packageJSON.devDependencies,
76091
- houdini: "^1.0.0-next.2",
76092
- "houdini-svelte": "^1.0.0-next.2",
76277
+ houdini: "^1.0.0-next.4",
76278
+ "houdini-svelte": "^1.0.0-next.4",
76093
76279
  graphql: "^15.8.0"
76094
76280
  };
76095
76281
  await fs_exports.writeFile(packagePath, JSON.stringify(packageJSON, null, 4));