houdini 1.0.0-next.2 → 1.0.0-next.3

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 (53) hide show
  1. package/build/cmd-cjs/index.js +1380 -1190
  2. package/build/cmd-esm/index.js +1380 -1190
  3. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  4. package/build/codegen/generators/typescript/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
  5. package/build/codegen/transforms/fragmentVariables.d.ts +1 -0
  6. package/build/codegen-cjs/index.js +1225 -1037
  7. package/build/codegen-esm/index.js +1225 -1037
  8. package/build/lib/config.d.ts +1 -1
  9. package/build/lib/walk.d.ts +4 -1
  10. package/build/lib-cjs/index.js +10 -10
  11. package/build/lib-esm/index.js +10 -10
  12. package/build/runtime/cache/lists.d.ts +1 -0
  13. package/build/runtime/generated.d.ts +1 -0
  14. package/build/runtime/index.d.ts +1 -1
  15. package/build/runtime/lib/config.d.ts +21 -22
  16. package/build/runtime/lib/scalars.d.ts +2 -2
  17. package/build/runtime/public/cache.d.ts +19 -6
  18. package/build/runtime/public/record.d.ts +17 -17
  19. package/build/runtime/public/tests/test.d.ts +43 -0
  20. package/build/runtime/public/types.d.ts +8 -0
  21. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  22. package/build/runtime-cjs/cache/lists.js +3 -0
  23. package/build/runtime-cjs/generated.d.ts +1 -0
  24. package/build/runtime-cjs/index.d.ts +1 -1
  25. package/build/runtime-cjs/lib/config.d.ts +21 -22
  26. package/build/runtime-cjs/lib/scalars.d.ts +2 -2
  27. package/build/runtime-cjs/public/cache.d.ts +19 -6
  28. package/build/runtime-cjs/public/cache.js +29 -32
  29. package/build/runtime-cjs/public/list.js +6 -28
  30. package/build/runtime-cjs/public/record.d.ts +17 -17
  31. package/build/runtime-cjs/public/record.js +22 -188
  32. package/build/runtime-cjs/public/tests/test.d.ts +43 -0
  33. package/build/runtime-cjs/public/tests/test.js +27 -2
  34. package/build/runtime-cjs/public/types.d.ts +8 -0
  35. package/build/runtime-esm/cache/lists.d.ts +1 -0
  36. package/build/runtime-esm/cache/lists.js +3 -0
  37. package/build/runtime-esm/generated.d.ts +1 -0
  38. package/build/runtime-esm/index.d.ts +1 -1
  39. package/build/runtime-esm/lib/config.d.ts +21 -22
  40. package/build/runtime-esm/lib/scalars.d.ts +2 -2
  41. package/build/runtime-esm/public/cache.d.ts +19 -6
  42. package/build/runtime-esm/public/cache.js +28 -30
  43. package/build/runtime-esm/public/list.js +6 -28
  44. package/build/runtime-esm/public/record.d.ts +17 -17
  45. package/build/runtime-esm/public/record.js +21 -184
  46. package/build/runtime-esm/public/tests/test.d.ts +43 -0
  47. package/build/runtime-esm/public/tests/test.js +26 -1
  48. package/build/runtime-esm/public/types.d.ts +8 -0
  49. package/build/test-cjs/index.js +1233 -1046
  50. package/build/test-esm/index.js +1233 -1046
  51. package/build/vite-cjs/index.js +1234 -1046
  52. package/build/vite-esm/index.js +1234 -1046
  53. 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
@@ -71540,7 +71915,7 @@ async function paginate(config2, documents) {
71540
71915
  flags.offset.enabled = offsetPagination;
71541
71916
  flags.limit.enabled = offsetPagination;
71542
71917
  paginationPath = ancestors.filter(
71543
- (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql9.Kind.FIELD
71918
+ (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql10.Kind.FIELD
71544
71919
  ).concat(node).map((field) => field.alias?.value || field.name.value);
71545
71920
  return {
71546
71921
  ...node,
@@ -71561,7 +71936,7 @@ async function paginate(config2, documents) {
71561
71936
  refetchUpdate = "prepend" /* prepend */;
71562
71937
  }
71563
71938
  let fragment = "";
71564
- doc.document = graphql9.visit(doc.document, {
71939
+ doc.document = graphql10.visit(doc.document, {
71565
71940
  OperationDefinition(node) {
71566
71941
  if (node.operation !== "query") {
71567
71942
  throw new HoudiniError({
@@ -71615,9 +71990,9 @@ async function paginate(config2, documents) {
71615
71990
  directives: [
71616
71991
  ...node.directives || [],
71617
71992
  {
71618
- kind: graphql9.Kind.DIRECTIVE,
71993
+ kind: graphql10.Kind.DIRECTIVE,
71619
71994
  name: {
71620
- kind: graphql9.Kind.NAME,
71995
+ kind: graphql10.Kind.NAME,
71621
71996
  value: config2.argumentsDirective
71622
71997
  }
71623
71998
  }
@@ -71680,16 +72055,16 @@ async function paginate(config2, documents) {
71680
72055
  const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
71681
72056
  const fragmentSpreadSelection = [
71682
72057
  {
71683
- kind: graphql9.Kind.FRAGMENT_SPREAD,
72058
+ kind: graphql10.Kind.FRAGMENT_SPREAD,
71684
72059
  name: {
71685
- kind: graphql9.Kind.NAME,
72060
+ kind: graphql10.Kind.NAME,
71686
72061
  value: fragmentName
71687
72062
  },
71688
72063
  directives: [
71689
72064
  {
71690
- kind: graphql9.Kind.DIRECTIVE,
72065
+ kind: graphql10.Kind.DIRECTIVE,
71691
72066
  name: {
71692
- kind: graphql9.Kind.NAME,
72067
+ kind: graphql10.Kind.NAME,
71693
72068
  value: config2.withDirective
71694
72069
  },
71695
72070
  ["arguments"]: paginationArgs.map(
@@ -71717,29 +72092,29 @@ async function paginate(config2, documents) {
71717
72092
  });
71718
72093
  const typeConfig = config2.typeConfig?.[fragment];
71719
72094
  const queryDoc = {
71720
- kind: graphql9.Kind.DOCUMENT,
72095
+ kind: graphql10.Kind.DOCUMENT,
71721
72096
  definitions: [
71722
72097
  {
71723
- kind: graphql9.Kind.OPERATION_DEFINITION,
72098
+ kind: graphql10.Kind.OPERATION_DEFINITION,
71724
72099
  name: {
71725
- kind: graphql9.Kind.NAME,
72100
+ kind: graphql10.Kind.NAME,
71726
72101
  value: refetchQueryName
71727
72102
  },
71728
72103
  operation: "query",
71729
72104
  variableDefinitions: paginationArgs.map(
71730
72105
  (arg) => ({
71731
- kind: graphql9.Kind.VARIABLE_DEFINITION,
72106
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
71732
72107
  type: {
71733
- kind: graphql9.Kind.NAMED_TYPE,
72108
+ kind: graphql10.Kind.NAMED_TYPE,
71734
72109
  name: {
71735
- kind: graphql9.Kind.NAME,
72110
+ kind: graphql10.Kind.NAME,
71736
72111
  value: arg.type
71737
72112
  }
71738
72113
  },
71739
72114
  variable: {
71740
- kind: graphql9.Kind.VARIABLE,
72115
+ kind: graphql10.Kind.VARIABLE,
71741
72116
  name: {
71742
- kind: graphql9.Kind.NAME,
72117
+ kind: graphql10.Kind.NAME,
71743
72118
  value: arg.name
71744
72119
  }
71745
72120
  },
@@ -71751,12 +72126,12 @@ async function paginate(config2, documents) {
71751
72126
  ).concat(
71752
72127
  !nodeQuery ? [] : keys.map(
71753
72128
  (key) => ({
71754
- kind: graphql9.Kind.VARIABLE_DEFINITION,
72129
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
71755
72130
  type: key.type,
71756
72131
  variable: {
71757
- kind: graphql9.Kind.VARIABLE,
72132
+ kind: graphql10.Kind.VARIABLE,
71758
72133
  name: {
71759
- kind: graphql9.Kind.NAME,
72134
+ kind: graphql10.Kind.NAME,
71760
72135
  value: key.name
71761
72136
  }
71762
72137
  }
@@ -71764,42 +72139,42 @@ async function paginate(config2, documents) {
71764
72139
  )
71765
72140
  ),
71766
72141
  selectionSet: {
71767
- kind: graphql9.Kind.SELECTION_SET,
72142
+ kind: graphql10.Kind.SELECTION_SET,
71768
72143
  selections: !nodeQuery ? fragmentSpreadSelection : [
71769
72144
  {
71770
- kind: graphql9.Kind.FIELD,
72145
+ kind: graphql10.Kind.FIELD,
71771
72146
  name: {
71772
- kind: graphql9.Kind.NAME,
72147
+ kind: graphql10.Kind.NAME,
71773
72148
  value: typeConfig?.resolve?.queryField || "node"
71774
72149
  },
71775
72150
  ["arguments"]: keys.map((key) => ({
71776
- kind: graphql9.Kind.ARGUMENT,
72151
+ kind: graphql10.Kind.ARGUMENT,
71777
72152
  name: {
71778
- kind: graphql9.Kind.NAME,
72153
+ kind: graphql10.Kind.NAME,
71779
72154
  value: key.name
71780
72155
  },
71781
72156
  value: {
71782
- kind: graphql9.Kind.VARIABLE,
72157
+ kind: graphql10.Kind.VARIABLE,
71783
72158
  name: {
71784
- kind: graphql9.Kind.NAME,
72159
+ kind: graphql10.Kind.NAME,
71785
72160
  value: key.name
71786
72161
  }
71787
72162
  }
71788
72163
  })),
71789
72164
  selectionSet: {
71790
- kind: graphql9.Kind.SELECTION_SET,
72165
+ kind: graphql10.Kind.SELECTION_SET,
71791
72166
  selections: [
71792
72167
  {
71793
- kind: graphql9.Kind.FIELD,
72168
+ kind: graphql10.Kind.FIELD,
71794
72169
  name: {
71795
- kind: graphql9.Kind.NAME,
72170
+ kind: graphql10.Kind.NAME,
71796
72171
  value: "__typename"
71797
72172
  }
71798
72173
  },
71799
72174
  ...(typeConfig?.keys || ["id"]).map((key) => ({
71800
- kind: graphql9.Kind.FIELD,
72175
+ kind: graphql10.Kind.FIELD,
71801
72176
  name: {
71802
- kind: graphql9.Kind.NAME,
72177
+ kind: graphql10.Kind.NAME,
71803
72178
  value: key
71804
72179
  }
71805
72180
  })),
@@ -71861,15 +72236,15 @@ function replaceArgumentsWithVariables(args, flags) {
71861
72236
  }
71862
72237
  function variableAsArgument(name2, variable) {
71863
72238
  return {
71864
- kind: graphql9.Kind.ARGUMENT,
72239
+ kind: graphql10.Kind.ARGUMENT,
71865
72240
  name: {
71866
- kind: graphql9.Kind.NAME,
72241
+ kind: graphql10.Kind.NAME,
71867
72242
  value: name2
71868
72243
  },
71869
72244
  value: {
71870
- kind: graphql9.Kind.VARIABLE,
72245
+ kind: graphql10.Kind.VARIABLE,
71871
72246
  name: {
71872
- kind: graphql9.Kind.NAME,
72247
+ kind: graphql10.Kind.NAME,
71873
72248
  value: variable ?? name2
71874
72249
  }
71875
72250
  }
@@ -71877,18 +72252,18 @@ function variableAsArgument(name2, variable) {
71877
72252
  }
71878
72253
  function staticVariableDefinition(name2, type, defaultValue, variableName) {
71879
72254
  return {
71880
- kind: graphql9.Kind.VARIABLE_DEFINITION,
72255
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
71881
72256
  type: {
71882
- kind: graphql9.Kind.NAMED_TYPE,
72257
+ kind: graphql10.Kind.NAMED_TYPE,
71883
72258
  name: {
71884
- kind: graphql9.Kind.NAME,
72259
+ kind: graphql10.Kind.NAME,
71885
72260
  value: type
71886
72261
  }
71887
72262
  },
71888
72263
  variable: {
71889
- kind: graphql9.Kind.VARIABLE,
72264
+ kind: graphql10.Kind.VARIABLE,
71890
72265
  name: {
71891
- kind: graphql9.Kind.NAME,
72266
+ kind: graphql10.Kind.NAME,
71892
72267
  value: variableName ?? name2
71893
72268
  }
71894
72269
  },
@@ -71900,9 +72275,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
71900
72275
  }
71901
72276
  function argumentNode(name2, value) {
71902
72277
  return {
71903
- kind: graphql9.Kind.ARGUMENT,
72278
+ kind: graphql10.Kind.ARGUMENT,
71904
72279
  name: {
71905
- kind: graphql9.Kind.NAME,
72280
+ kind: graphql10.Kind.NAME,
71906
72281
  value: name2
71907
72282
  },
71908
72283
  value: objectNode(value)
@@ -71910,16 +72285,16 @@ function argumentNode(name2, value) {
71910
72285
  }
71911
72286
  function objectNode([type, defaultValue]) {
71912
72287
  const node = {
71913
- kind: graphql9.Kind.OBJECT,
72288
+ kind: graphql10.Kind.OBJECT,
71914
72289
  fields: [
71915
72290
  {
71916
- kind: graphql9.Kind.OBJECT_FIELD,
72291
+ kind: graphql10.Kind.OBJECT_FIELD,
71917
72292
  name: {
71918
- kind: graphql9.Kind.NAME,
72293
+ kind: graphql10.Kind.NAME,
71919
72294
  value: "type"
71920
72295
  },
71921
72296
  value: {
71922
- kind: graphql9.Kind.STRING,
72297
+ kind: graphql10.Kind.STRING,
71923
72298
  value: type
71924
72299
  }
71925
72300
  }
@@ -71927,8 +72302,8 @@ function objectNode([type, defaultValue]) {
71927
72302
  };
71928
72303
  if (defaultValue) {
71929
72304
  node.fields.push({
71930
- kind: graphql9.Kind.OBJECT_FIELD,
71931
- name: { kind: graphql9.Kind.NAME, value: "default" },
72305
+ kind: graphql10.Kind.OBJECT_FIELD,
72306
+ name: { kind: graphql10.Kind.NAME, value: "default" },
71932
72307
  value: {
71933
72308
  kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
71934
72309
  value: defaultValue.toString()
@@ -71939,34 +72314,34 @@ function objectNode([type, defaultValue]) {
71939
72314
  }
71940
72315
  var pageInfoSelection = [
71941
72316
  {
71942
- kind: graphql9.Kind.FIELD,
72317
+ kind: graphql10.Kind.FIELD,
71943
72318
  name: {
71944
- kind: graphql9.Kind.NAME,
72319
+ kind: graphql10.Kind.NAME,
71945
72320
  value: "edges"
71946
72321
  },
71947
72322
  selectionSet: {
71948
- kind: graphql9.Kind.SELECTION_SET,
72323
+ kind: graphql10.Kind.SELECTION_SET,
71949
72324
  selections: [
71950
72325
  {
71951
- kind: graphql9.Kind.FIELD,
72326
+ kind: graphql10.Kind.FIELD,
71952
72327
  name: {
71953
- kind: graphql9.Kind.NAME,
72328
+ kind: graphql10.Kind.NAME,
71954
72329
  value: "cursor"
71955
72330
  }
71956
72331
  },
71957
72332
  {
71958
- kind: graphql9.Kind.FIELD,
72333
+ kind: graphql10.Kind.FIELD,
71959
72334
  name: {
71960
- kind: graphql9.Kind.NAME,
72335
+ kind: graphql10.Kind.NAME,
71961
72336
  value: "node"
71962
72337
  },
71963
72338
  selectionSet: {
71964
- kind: graphql9.Kind.SELECTION_SET,
72339
+ kind: graphql10.Kind.SELECTION_SET,
71965
72340
  selections: [
71966
72341
  {
71967
- kind: graphql9.Kind.FIELD,
72342
+ kind: graphql10.Kind.FIELD,
71968
72343
  name: {
71969
- kind: graphql9.Kind.NAME,
72344
+ kind: graphql10.Kind.NAME,
71970
72345
  value: "__typename"
71971
72346
  }
71972
72347
  }
@@ -71977,39 +72352,39 @@ var pageInfoSelection = [
71977
72352
  }
71978
72353
  },
71979
72354
  {
71980
- kind: graphql9.Kind.FIELD,
72355
+ kind: graphql10.Kind.FIELD,
71981
72356
  name: {
71982
- kind: graphql9.Kind.NAME,
72357
+ kind: graphql10.Kind.NAME,
71983
72358
  value: "pageInfo"
71984
72359
  },
71985
72360
  selectionSet: {
71986
- kind: graphql9.Kind.SELECTION_SET,
72361
+ kind: graphql10.Kind.SELECTION_SET,
71987
72362
  selections: [
71988
72363
  {
71989
- kind: graphql9.Kind.FIELD,
72364
+ kind: graphql10.Kind.FIELD,
71990
72365
  name: {
71991
- kind: graphql9.Kind.NAME,
72366
+ kind: graphql10.Kind.NAME,
71992
72367
  value: "hasPreviousPage"
71993
72368
  }
71994
72369
  },
71995
72370
  {
71996
- kind: graphql9.Kind.FIELD,
72371
+ kind: graphql10.Kind.FIELD,
71997
72372
  name: {
71998
- kind: graphql9.Kind.NAME,
72373
+ kind: graphql10.Kind.NAME,
71999
72374
  value: "hasNextPage"
72000
72375
  }
72001
72376
  },
72002
72377
  {
72003
- kind: graphql9.Kind.FIELD,
72378
+ kind: graphql10.Kind.FIELD,
72004
72379
  name: {
72005
- kind: graphql9.Kind.NAME,
72380
+ kind: graphql10.Kind.NAME,
72006
72381
  value: "startCursor"
72007
72382
  }
72008
72383
  },
72009
72384
  {
72010
- kind: graphql9.Kind.FIELD,
72385
+ kind: graphql10.Kind.FIELD,
72011
72386
  name: {
72012
- kind: graphql9.Kind.NAME,
72387
+ kind: graphql10.Kind.NAME,
72013
72388
  value: "endCursor"
72014
72389
  }
72015
72390
  }
@@ -72023,15 +72398,15 @@ async function addListFragments(config2, documents) {
72023
72398
  const lists = {};
72024
72399
  const errors = [];
72025
72400
  for (const doc of documents) {
72026
- doc.document = graphql10.visit(doc.document, {
72401
+ doc.document = graphql11.visit(doc.document, {
72027
72402
  Directive(node, key, parent, path2, ancestors) {
72028
72403
  if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
72029
72404
  const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
72030
72405
  let error = {
72031
- ...new graphql10.GraphQLError(
72406
+ ...new graphql11.GraphQLError(
72032
72407
  "",
72033
72408
  node,
72034
- new graphql10.Source(""),
72409
+ new graphql11.Source(""),
72035
72410
  node.loc ? [node.loc.start, node.loc.end] : null,
72036
72411
  path2
72037
72412
  ),
@@ -72083,7 +72458,7 @@ async function addListFragments(config2, documents) {
72083
72458
  {
72084
72459
  kind: "Argument",
72085
72460
  name: {
72086
- kind: graphql10.Kind.NAME,
72461
+ kind: graphql11.Kind.NAME,
72087
72462
  value: "connection"
72088
72463
  },
72089
72464
  value: {
@@ -72133,7 +72508,7 @@ async function addListFragments(config2, documents) {
72133
72508
  const validDeletes = [
72134
72509
  ...new Set(
72135
72510
  Object.values(lists).map(({ type }) => {
72136
- if (!(type instanceof graphql10.GraphQLObjectType)) {
72511
+ if (!(type instanceof graphql11.GraphQLObjectType)) {
72137
72512
  return "";
72138
72513
  }
72139
72514
  if (config2.keyFieldsForType(type.name).length !== 1) {
@@ -72147,7 +72522,7 @@ async function addListFragments(config2, documents) {
72147
72522
  return;
72148
72523
  }
72149
72524
  const generatedDoc = {
72150
- kind: graphql10.Kind.DOCUMENT,
72525
+ kind: graphql11.Kind.DOCUMENT,
72151
72526
  definitions: Object.entries(lists).flatMap(
72152
72527
  ([name2, { selection: selection2, type }]) => {
72153
72528
  const schemaType = config2.schema.getType(type.name);
@@ -72155,7 +72530,7 @@ async function addListFragments(config2, documents) {
72155
72530
  throw new HoudiniError({ message: "Lists must have a selection" });
72156
72531
  }
72157
72532
  const fragmentSelection = {
72158
- kind: graphql10.Kind.SELECTION_SET,
72533
+ kind: graphql11.Kind.SELECTION_SET,
72159
72534
  selections: [...selection2.selections]
72160
72535
  };
72161
72536
  if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
@@ -72170,14 +72545,14 @@ async function addListFragments(config2, documents) {
72170
72545
  {
72171
72546
  name: {
72172
72547
  value: config2.listInsertFragment(name2),
72173
- kind: graphql10.Kind.NAME
72548
+ kind: graphql11.Kind.NAME
72174
72549
  },
72175
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
72550
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
72176
72551
  selectionSet: fragmentSelection,
72177
72552
  typeCondition: {
72178
- kind: graphql10.Kind.NAMED_TYPE,
72553
+ kind: graphql11.Kind.NAMED_TYPE,
72179
72554
  name: {
72180
- kind: graphql10.Kind.NAME,
72555
+ kind: graphql11.Kind.NAME,
72181
72556
  value: type.name
72182
72557
  }
72183
72558
  }
@@ -72185,32 +72560,32 @@ async function addListFragments(config2, documents) {
72185
72560
  {
72186
72561
  name: {
72187
72562
  value: config2.listToggleFragment(name2),
72188
- kind: graphql10.Kind.NAME
72563
+ kind: graphql11.Kind.NAME
72189
72564
  },
72190
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
72565
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
72191
72566
  selectionSet: fragmentSelection,
72192
72567
  typeCondition: {
72193
- kind: graphql10.Kind.NAMED_TYPE,
72568
+ kind: graphql11.Kind.NAMED_TYPE,
72194
72569
  name: {
72195
- kind: graphql10.Kind.NAME,
72570
+ kind: graphql11.Kind.NAME,
72196
72571
  value: type.name
72197
72572
  }
72198
72573
  }
72199
72574
  },
72200
72575
  {
72201
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
72576
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
72202
72577
  name: {
72203
72578
  value: config2.listRemoveFragment(name2),
72204
- kind: graphql10.Kind.NAME
72579
+ kind: graphql11.Kind.NAME
72205
72580
  },
72206
72581
  selectionSet: {
72207
- kind: graphql10.Kind.SELECTION_SET,
72582
+ kind: graphql11.Kind.SELECTION_SET,
72208
72583
  selections: [...objectIdentificationSelection(config2, type)]
72209
72584
  },
72210
72585
  typeCondition: {
72211
- kind: graphql10.Kind.NAMED_TYPE,
72586
+ kind: graphql11.Kind.NAMED_TYPE,
72212
72587
  name: {
72213
- kind: graphql10.Kind.NAME,
72588
+ kind: graphql11.Kind.NAME,
72214
72589
  value: type.name
72215
72590
  }
72216
72591
  }
@@ -72219,14 +72594,14 @@ async function addListFragments(config2, documents) {
72219
72594
  }
72220
72595
  ).concat(
72221
72596
  ...validDeletes.map((typeName) => ({
72222
- kind: graphql10.Kind.DIRECTIVE_DEFINITION,
72597
+ kind: graphql11.Kind.DIRECTIVE_DEFINITION,
72223
72598
  name: {
72224
- kind: graphql10.Kind.NAME,
72599
+ kind: graphql11.Kind.NAME,
72225
72600
  value: config2.listDeleteDirective(typeName)
72226
72601
  },
72227
72602
  locations: [
72228
72603
  {
72229
- kind: graphql10.Kind.NAME,
72604
+ kind: graphql11.Kind.NAME,
72230
72605
  value: "FIELD"
72231
72606
  }
72232
72607
  ],
@@ -72234,8 +72609,8 @@ async function addListFragments(config2, documents) {
72234
72609
  }))
72235
72610
  )
72236
72611
  };
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");
72612
+ config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql11.print).join("\n\n");
72613
+ config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql11.print).join("\n\n");
72239
72614
  documents.push({
72240
72615
  name: "generated::lists",
72241
72616
  kind: "HoudiniFragment" /* Fragment */,
@@ -72320,11 +72695,11 @@ var nodeNotDefinedMessage = (config2) => `Looks like you are trying to use the $
72320
72695
  For more information, visit this link: ${siteURL}/guides/pagination`;
72321
72696
 
72322
72697
  // src/codegen/generators/artifacts/fieldKey.ts
72323
- var graphql11 = __toESM(require_graphql2(), 1);
72698
+ var graphql12 = __toESM(require_graphql2(), 1);
72324
72699
  function fieldKey(config2, field) {
72325
72700
  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];
72701
+ const printed = graphql12.print(field);
72702
+ const secondParse = graphql12.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
72328
72703
  const paginated = !!field.directives?.find(
72329
72704
  (directive) => directive.name.value === config2.paginateDirective
72330
72705
  );
@@ -72419,8 +72794,8 @@ function selection({
72419
72794
  const typeConditionName = field.typeCondition.name.value;
72420
72795
  const typeCondition = config2.schema.getType(typeConditionName);
72421
72796
  const possibleTypes = [];
72422
- if (!graphql12.isAbstractType(typeCondition)) {
72423
- } else if (graphql12.isAbstractType(parentType)) {
72797
+ if (!graphql13.isAbstractType(typeCondition)) {
72798
+ } else if (graphql13.isAbstractType(parentType)) {
72424
72799
  const possibleParentTypes = config2.schema.getPossibleTypes(parentType).map((type) => type.name);
72425
72800
  for (const possible of config2.schema.getPossibleTypes(typeCondition)) {
72426
72801
  if (possibleParentTypes.includes(possible.name)) {
@@ -72468,7 +72843,7 @@ function selection({
72468
72843
  } else {
72469
72844
  let typeRef = type.getFields()[field.name.value].type;
72470
72845
  fieldType = getRootType(typeRef);
72471
- nullable = !graphql12.isNonNullType(typeRef);
72846
+ nullable = !graphql13.isNonNullType(typeRef);
72472
72847
  }
72473
72848
  const typeName = fieldType.toString();
72474
72849
  const pathSoFar = path2.concat(attributeName);
@@ -72533,7 +72908,7 @@ function selection({
72533
72908
  {}
72534
72909
  );
72535
72910
  }
72536
- if (graphql12.isInterfaceType(fieldType) || graphql12.isUnionType(fieldType)) {
72911
+ if (graphql13.isInterfaceType(fieldType) || graphql13.isUnionType(fieldType)) {
72537
72912
  fieldObj.abstract = true;
72538
72913
  }
72539
72914
  object.fields = {
@@ -72590,7 +72965,7 @@ function artifactGenerator(stats) {
72590
72965
  return async function(config2, docs) {
72591
72966
  const filterTypes = {};
72592
72967
  for (const doc of docs) {
72593
- graphql13.visit(doc.document, {
72968
+ graphql14.visit(doc.document, {
72594
72969
  Directive(node, _, __, ___, ancestors) {
72595
72970
  if (node.name.value !== config2.listDirective) {
72596
72971
  return;
@@ -72649,7 +73024,7 @@ function artifactGenerator(stats) {
72649
73024
  return;
72650
73025
  }
72651
73026
  const usedVariableNames = /* @__PURE__ */ new Set();
72652
- let documentWithoutInternalDirectives = graphql13.visit(document, {
73027
+ let documentWithoutInternalDirectives = graphql14.visit(document, {
72653
73028
  Directive(node) {
72654
73029
  if (config2.isInternalDirective(node)) {
72655
73030
  return null;
@@ -72662,7 +73037,7 @@ function artifactGenerator(stats) {
72662
73037
  }
72663
73038
  }
72664
73039
  });
72665
- let documentWithoutExtraVariables = graphql13.visit(
73040
+ let documentWithoutExtraVariables = graphql14.visit(
72666
73041
  documentWithoutInternalDirectives,
72667
73042
  {
72668
73043
  VariableDefinition(variableDefinitionNode) {
@@ -72673,13 +73048,13 @@ function artifactGenerator(stats) {
72673
73048
  }
72674
73049
  }
72675
73050
  );
72676
- let rawString = graphql13.print(documentWithoutExtraVariables);
73051
+ let rawString = graphql14.print(documentWithoutExtraVariables);
72677
73052
  let docKind = doc.kind;
72678
73053
  const operations = document.definitions.filter(
72679
- ({ kind }) => kind === graphql13.Kind.OPERATION_DEFINITION
73054
+ ({ kind }) => kind === graphql14.Kind.OPERATION_DEFINITION
72680
73055
  );
72681
73056
  const fragments = document.definitions.filter(
72682
- ({ kind }) => kind === graphql13.Kind.FRAGMENT_DEFINITION
73057
+ ({ kind }) => kind === graphql14.Kind.FRAGMENT_DEFINITION
72683
73058
  );
72684
73059
  let rootType = "";
72685
73060
  let selectionSet;
@@ -72712,7 +73087,13 @@ function artifactGenerator(stats) {
72712
73087
  rootType = matchingFragment.typeCondition.name.value;
72713
73088
  selectionSet = matchingFragment.selectionSet;
72714
73089
  }
72715
- const inputs = operations[0]?.variableDefinitions;
73090
+ let inputs = operations[0]?.variableDefinitions;
73091
+ let directive = fragments[0]?.directives?.find(
73092
+ (directive2) => directive2.name.value === config2.argumentsDirective
73093
+ );
73094
+ if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
73095
+ inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
73096
+ }
72716
73097
  const mergedSelection = flattenSelections({
72717
73098
  config: config2,
72718
73099
  filepath: doc.filename,
@@ -72773,7 +73154,7 @@ function artifactGenerator(stats) {
72773
73154
  }
72774
73155
  if (docKind === "HoudiniQuery") {
72775
73156
  const cacheDirective = operations[0].directives?.find(
72776
- (directive) => directive.name.value === config2.cacheDirective
73157
+ (directive2) => directive2.name.value === config2.cacheDirective
72777
73158
  );
72778
73159
  if (cacheDirective) {
72779
73160
  const args = cacheDirective.arguments?.reduce(
@@ -72989,19 +73370,19 @@ async function generatePluginRuntime(config2, plugin) {
72989
73370
  );
72990
73371
  }
72991
73372
 
72992
- // src/codegen/generators/typescript/index.ts
72993
- var recast12 = __toESM(require_main2(), 1);
73373
+ // src/codegen/generators/typescript/documentTypes.ts
73374
+ var recast11 = __toESM(require_main2(), 1);
72994
73375
 
72995
73376
  // src/codegen/generators/typescript/addReferencedInputTypes.ts
72996
- var graphql16 = __toESM(require_graphql2(), 1);
73377
+ var graphql17 = __toESM(require_graphql2(), 1);
72997
73378
  var recast9 = __toESM(require_main2(), 1);
72998
73379
 
72999
73380
  // src/codegen/generators/typescript/typeReference.ts
73000
- var graphql15 = __toESM(require_graphql2(), 1);
73381
+ var graphql16 = __toESM(require_graphql2(), 1);
73001
73382
  var recast8 = __toESM(require_main2(), 1);
73002
73383
 
73003
73384
  // src/codegen/generators/typescript/types.ts
73004
- var graphql14 = __toESM(require_graphql2(), 1);
73385
+ var graphql15 = __toESM(require_graphql2(), 1);
73005
73386
  var recast7 = __toESM(require_main2(), 1);
73006
73387
  var AST7 = recast7.types.builders;
73007
73388
  function readonlyProperty(prop, enable = true) {
@@ -73017,351 +73398,104 @@ function nullableField(inner, input = false) {
73017
73398
  }
73018
73399
  return AST7.tsUnionType(members);
73019
73400
  }
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
- )
73401
+ function scalarPropertyValue(config2, missingScalars, target) {
73402
+ switch (target.name) {
73403
+ case "String": {
73404
+ return AST7.tsStringKeyword();
73405
+ }
73406
+ case "Int": {
73407
+ return AST7.tsNumberKeyword();
73408
+ }
73409
+ case "Float": {
73410
+ return AST7.tsNumberKeyword();
73411
+ }
73412
+ case "Boolean": {
73413
+ return AST7.tsBooleanKeyword();
73414
+ }
73415
+ case "ID": {
73416
+ return AST7.tsStringKeyword();
73417
+ }
73418
+ default: {
73419
+ if (graphql15.isNonNullType(target) && "ofType" in target) {
73420
+ return scalarPropertyValue(
73421
+ config2,
73422
+ missingScalars,
73423
+ target.ofType
73344
73424
  );
73345
73425
  }
73346
- });
73426
+ if (config2.scalars?.[target.name]) {
73427
+ return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
73428
+ }
73429
+ missingScalars.add(target.name);
73430
+ return AST7.tsAnyKeyword();
73431
+ }
73347
73432
  }
73348
- return AST10.tsTypeLiteral(lists);
73349
73433
  }
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
- );
73434
+
73435
+ // src/codegen/generators/typescript/typeReference.ts
73436
+ var AST8 = recast8.types.builders;
73437
+ function tsTypeReference(config2, missingScalars, definition) {
73438
+ const { type, wrappers } = unwrapType(config2, definition.type);
73439
+ let result;
73440
+ if (graphql16.isScalarType(type)) {
73441
+ result = scalarPropertyValue(config2, missingScalars, type);
73442
+ } else {
73443
+ result = AST8.tsTypeReference(AST8.identifier(type.name));
73444
+ }
73445
+ for (const toWrap of wrappers) {
73446
+ if (toWrap === "NonNull" /* NonNull */) {
73447
+ continue;
73448
+ } else if (toWrap === "Nullable" /* Nullable */) {
73449
+ result = nullableField(result, true);
73450
+ } else if (toWrap === "List" /* List */) {
73451
+ result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
73452
+ }
73453
+ }
73454
+ return result;
73455
+ }
73456
+
73457
+ // src/codegen/generators/typescript/addReferencedInputTypes.ts
73458
+ var AST9 = recast9.types.builders;
73459
+ function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
73460
+ const { type } = unwrapType(config2, rootType);
73461
+ if (graphql17.isScalarType(type)) {
73462
+ return;
73463
+ }
73464
+ if (visitedTypes.has(type.name)) {
73465
+ return;
73466
+ }
73467
+ if (graphql17.isUnionType(type)) {
73468
+ throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
73469
+ }
73470
+ visitedTypes.add(type.name);
73471
+ if (graphql17.isEnumType(type)) {
73472
+ ensureImports({
73473
+ config: config2,
73474
+ body,
73475
+ import: [type.name],
73476
+ sourceModule: "$houdini/graphql/enums",
73477
+ importKind: "type"
73478
+ });
73479
+ return;
73480
+ }
73481
+ const members = [];
73482
+ for (const field of Object.values(type.getFields())) {
73483
+ addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
73484
+ members.push(
73485
+ AST9.tsPropertySignature(
73486
+ AST9.identifier(field.name),
73487
+ AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
73488
+ graphql17.isNullableType(field.type)
73489
+ )
73490
+ );
73491
+ }
73492
+ body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
73359
73493
  }
73360
73494
 
73361
73495
  // src/codegen/generators/typescript/inlineType.ts
73362
73496
  var graphql18 = __toESM(require_graphql2(), 1);
73363
- var recast11 = __toESM(require_main2(), 1);
73364
- var AST11 = recast11.types.builders;
73497
+ var recast10 = __toESM(require_main2(), 1);
73498
+ var AST10 = recast10.types.builders;
73365
73499
  var fragmentKey = "$fragments";
73366
73500
  function inlineType({
73367
73501
  config: config2,
@@ -73390,7 +73524,7 @@ function inlineType({
73390
73524
  });
73391
73525
  visitedTypes.add(type.name);
73392
73526
  }
73393
- result = AST11.tsTypeReference(AST11.identifier(type.name));
73527
+ result = AST10.tsTypeReference(AST10.identifier(type.name));
73394
73528
  } else if (selections) {
73395
73529
  const rootObj = type;
73396
73530
  const inlineFragments = {};
@@ -73441,7 +73575,7 @@ function inlineType({
73441
73575
  selectedFields.push(selection2);
73442
73576
  }
73443
73577
  }
73444
- result = AST11.tsTypeLiteral([
73578
+ result = AST10.tsTypeLiteral([
73445
73579
  ...(selectedFields || []).filter(
73446
73580
  (field) => field.kind === "Field"
73447
73581
  ).map((selection2) => {
@@ -73461,9 +73595,9 @@ function inlineType({
73461
73595
  allOptional
73462
73596
  });
73463
73597
  const prop = readonlyProperty(
73464
- AST11.tsPropertySignature(
73465
- AST11.identifier(attributeName),
73466
- AST11.tsTypeAnnotation(attributeType)
73598
+ AST10.tsPropertySignature(
73599
+ AST10.identifier(attributeName),
73600
+ AST10.tsTypeAnnotation(attributeType)
73467
73601
  ),
73468
73602
  allowReadonly
73469
73603
  );
@@ -73477,15 +73611,15 @@ function inlineType({
73477
73611
  if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
73478
73612
  result.members.push(
73479
73613
  readonlyProperty(
73480
- AST11.tsPropertySignature(
73481
- AST11.identifier(fragmentKey),
73482
- AST11.tsTypeAnnotation(
73483
- AST11.tsTypeLiteral(
73614
+ AST10.tsPropertySignature(
73615
+ AST10.identifier(fragmentKey),
73616
+ AST10.tsTypeAnnotation(
73617
+ AST10.tsTypeLiteral(
73484
73618
  (fragmentSpreads || []).map(
73485
- (fragmentSpread) => AST11.tsPropertySignature(
73486
- AST11.identifier(fragmentSpread.name.value),
73487
- AST11.tsTypeAnnotation(
73488
- AST11.tsLiteralType(AST11.booleanLiteral(true))
73619
+ (fragmentSpread) => AST10.tsPropertySignature(
73620
+ AST10.identifier(fragmentSpread.name.value),
73621
+ AST10.tsTypeAnnotation(
73622
+ AST10.tsLiteralType(AST10.booleanLiteral(true))
73489
73623
  )
73490
73624
  )
73491
73625
  )
@@ -73531,9 +73665,9 @@ function inlineType({
73531
73665
  }
73532
73666
  objectType.members.push(
73533
73667
  readonlyProperty(
73534
- AST11.tsPropertySignature(
73535
- AST11.identifier("__typename"),
73536
- AST11.tsTypeAnnotation(AST11.tsLiteralType(AST11.stringLiteral(typeName)))
73668
+ AST10.tsPropertySignature(
73669
+ AST10.identifier("__typename"),
73670
+ AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
73537
73671
  ),
73538
73672
  allowReadonly
73539
73673
  )
@@ -73544,8 +73678,8 @@ function inlineType({
73544
73678
  if (Object.keys(inlineFragmentSelections).length > 0) {
73545
73679
  let selectionTypes = Object.entries(inlineFragmentSelections).map(
73546
73680
  ([typeName, { type: type2, tsType }]) => {
73547
- return AST11.tsParenthesizedType(
73548
- AST11.tsIntersectionType(
73681
+ return AST10.tsParenthesizedType(
73682
+ AST10.tsIntersectionType(
73549
73683
  [tsType].flatMap((type3) => {
73550
73684
  if (type3.type === "TSUnionType") {
73551
73685
  return type3.types.filter(
@@ -73558,9 +73692,9 @@ function inlineType({
73558
73692
  );
73559
73693
  }
73560
73694
  );
73561
- result = AST11.tsIntersectionType([
73695
+ result = AST10.tsIntersectionType([
73562
73696
  result,
73563
- AST11.tsParenthesizedType(AST11.tsUnionType(selectionTypes))
73697
+ AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
73564
73698
  ]);
73565
73699
  }
73566
73700
  } else {
@@ -73572,7 +73706,7 @@ function inlineType({
73572
73706
  } else if (toWrap === "NonNull" /* NonNull */) {
73573
73707
  continue;
73574
73708
  } else if (toWrap === "List" /* List */) {
73575
- result = AST11.tsArrayType(AST11.tsParenthesizedType(result));
73709
+ result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
73576
73710
  }
73577
73711
  }
73578
73712
  return result;
@@ -73616,9 +73750,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
73616
73750
  return { field, type: selectionType };
73617
73751
  }
73618
73752
 
73619
- // src/codegen/generators/typescript/index.ts
73620
- var AST12 = recast12.types.builders;
73621
- async function typescriptGenerator(config2, docs) {
73753
+ // src/codegen/generators/typescript/documentTypes.ts
73754
+ var AST11 = recast11.types.builders;
73755
+ async function generateDocumentTypes(config2, docs) {
73622
73756
  const typePaths = [];
73623
73757
  const fragmentDefinitions = {};
73624
73758
  for (const document of docs) {
@@ -73635,7 +73769,7 @@ async function typescriptGenerator(config2, docs) {
73635
73769
  return;
73636
73770
  }
73637
73771
  const typeDefPath = config2.artifactTypePath(originalDocument);
73638
- const program3 = AST12.program([]);
73772
+ const program3 = AST11.program([]);
73639
73773
  const visitedTypes = /* @__PURE__ */ new Set();
73640
73774
  let definition = originalDocument.definitions.find(
73641
73775
  (def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
@@ -73668,21 +73802,21 @@ async function typescriptGenerator(config2, docs) {
73668
73802
  missingScalars
73669
73803
  );
73670
73804
  }
73671
- await fs_exports.writeFile(typeDefPath, recast12.print(program3).code);
73805
+ await fs_exports.writeFile(typeDefPath, recast11.print(program3).code);
73672
73806
  typePaths.push(typeDefPath);
73673
73807
  })
73674
73808
  );
73675
- const typeIndex = AST12.program(
73809
+ const typeIndex = AST11.program(
73676
73810
  typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
73677
- return AST12.exportAllDeclaration(
73678
- AST12.literal(
73811
+ return AST11.exportAllDeclaration(
73812
+ AST11.literal(
73679
73813
  "./" + path_exports.relative(path_exports.resolve(config2.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
73680
73814
  ),
73681
73815
  null
73682
73816
  );
73683
73817
  }).concat([
73684
- AST12.exportAllDeclaration(AST12.literal("./runtime"), null),
73685
- AST12.exportAllDeclaration(AST12.literal("./graphql"), null)
73818
+ AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
73819
+ AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
73686
73820
  ])
73687
73821
  );
73688
73822
  const export_default_as = ({ module: module2, as }) => `
@@ -73691,7 +73825,7 @@ export { default as ${as} } from "${module2}"
73691
73825
  const export_star_from = ({ module: module2 }) => `
73692
73826
  export * from "${module2}"
73693
73827
  `;
73694
- let indexContent = recast12.print(typeIndex).code;
73828
+ let indexContent = recast11.print(typeIndex).code;
73695
73829
  for (const plugin of config2.plugins) {
73696
73830
  if (!plugin.index_file) {
73697
73831
  continue;
@@ -73712,7 +73846,6 @@ export * from "${module2}"
73712
73846
  }
73713
73847
  }
73714
73848
  await fs_exports.writeFile(config2.typeIndexPath, indexContent);
73715
- await imperativeCacheTypef(config2, docs);
73716
73849
  if (missingScalars.size > 0) {
73717
73850
  console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
73718
73851
  ", "
@@ -73754,23 +73887,23 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73754
73887
  const optimisticTypeName = `${definition.name.value}$optimistic`;
73755
73888
  const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
73756
73889
  body.push(
73757
- AST12.exportNamedDeclaration(
73758
- AST12.tsTypeAliasDeclaration(
73759
- AST12.identifier(definition.name.value),
73760
- AST12.tsTypeLiteral([
73890
+ AST11.exportNamedDeclaration(
73891
+ AST11.tsTypeAliasDeclaration(
73892
+ AST11.identifier(definition.name.value),
73893
+ AST11.tsTypeLiteral([
73761
73894
  readonlyProperty(
73762
- AST12.tsPropertySignature(
73763
- AST12.stringLiteral("input"),
73764
- AST12.tsTypeAnnotation(AST12.tsTypeReference(AST12.identifier(inputTypeName)))
73895
+ AST11.tsPropertySignature(
73896
+ AST11.stringLiteral("input"),
73897
+ AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
73765
73898
  )
73766
73899
  ),
73767
73900
  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()
73901
+ AST11.tsPropertySignature(
73902
+ AST11.stringLiteral("result"),
73903
+ AST11.tsTypeAnnotation(
73904
+ definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
73905
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
73906
+ AST11.tsUndefinedKeyword()
73774
73907
  ])
73775
73908
  )
73776
73909
  )
@@ -73778,9 +73911,9 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73778
73911
  ])
73779
73912
  )
73780
73913
  ),
73781
- AST12.exportNamedDeclaration(
73782
- AST12.tsTypeAliasDeclaration(
73783
- AST12.identifier(shapeTypeName),
73914
+ AST11.exportNamedDeclaration(
73915
+ AST11.tsTypeAliasDeclaration(
73916
+ AST11.identifier(shapeTypeName),
73784
73917
  inlineType({
73785
73918
  config: config2,
73786
73919
  filepath,
@@ -73808,15 +73941,15 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73808
73941
  );
73809
73942
  }
73810
73943
  body.push(
73811
- AST12.exportNamedDeclaration(
73812
- AST12.tsTypeAliasDeclaration(
73813
- AST12.identifier(inputTypeName),
73814
- AST12.tsTypeLiteral(
73944
+ AST11.exportNamedDeclaration(
73945
+ AST11.tsTypeAliasDeclaration(
73946
+ AST11.identifier(inputTypeName),
73947
+ AST11.tsTypeLiteral(
73815
73948
  (definition.variableDefinitions || []).map(
73816
73949
  (definition2) => {
73817
- return AST12.tsPropertySignature(
73818
- AST12.identifier(definition2.variable.name.value),
73819
- AST12.tsTypeAnnotation(
73950
+ return AST11.tsPropertySignature(
73951
+ AST11.identifier(definition2.variable.name.value),
73952
+ AST11.tsTypeAnnotation(
73820
73953
  tsTypeReference(config2, missingScalars, definition2)
73821
73954
  ),
73822
73955
  definition2.type.kind !== "NonNullType"
@@ -73829,16 +73962,16 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
73829
73962
  );
73830
73963
  } else {
73831
73964
  body.push(
73832
- AST12.exportNamedDeclaration(
73833
- AST12.tsTypeAliasDeclaration(AST12.identifier(inputTypeName), AST12.tsNullKeyword())
73965
+ AST11.exportNamedDeclaration(
73966
+ AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
73834
73967
  )
73835
73968
  );
73836
73969
  }
73837
73970
  if (definition.operation === "mutation") {
73838
73971
  body.push(
73839
- AST12.exportNamedDeclaration(
73840
- AST12.tsTypeAliasDeclaration(
73841
- AST12.identifier(optimisticTypeName),
73972
+ AST11.exportNamedDeclaration(
73973
+ AST11.tsTypeAliasDeclaration(
73974
+ AST11.identifier(optimisticTypeName),
73842
73975
  inlineType({
73843
73976
  config: config2,
73844
73977
  filepath,
@@ -73864,65 +73997,463 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
73864
73997
  }
73865
73998
  const propTypeName = definition.name.value;
73866
73999
  const shapeTypeName = `${definition.name.value}$data`;
74000
+ const inputTypeName = `${definition.name.value}$input`;
73867
74001
  const type = config2.schema.getType(definition.typeCondition.name.value);
73868
74002
  if (!type) {
73869
74003
  throw new Error("Should not get here");
73870
74004
  }
74005
+ let extraExports = [];
74006
+ let directive = definition.directives?.find(
74007
+ (directive2) => directive2.name.value === config2.argumentsDirective
74008
+ );
74009
+ if (directive) {
74010
+ extraExports.push(
74011
+ AST11.exportNamedDeclaration(
74012
+ AST11.tsTypeAliasDeclaration(
74013
+ AST11.identifier(inputTypeName),
74014
+ AST11.tsTypeLiteral(
74015
+ (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
74016
+ (definition2) => {
74017
+ return AST11.tsPropertySignature(
74018
+ AST11.identifier(definition2.variable.name.value),
74019
+ AST11.tsTypeAnnotation(
74020
+ tsTypeReference(config2, missingScalars, definition2)
74021
+ ),
74022
+ definition2.type.kind !== "NonNullType"
74023
+ );
74024
+ }
74025
+ )
74026
+ )
74027
+ )
74028
+ )
74029
+ );
74030
+ }
73871
74031
  body.push(
73872
- AST12.exportNamedDeclaration(
73873
- AST12.tsTypeAliasDeclaration(
73874
- AST12.identifier(propTypeName),
73875
- AST12.tsTypeLiteral([
74032
+ ...extraExports,
74033
+ AST11.exportNamedDeclaration(
74034
+ AST11.tsTypeAliasDeclaration(
74035
+ AST11.identifier(propTypeName),
74036
+ AST11.tsTypeLiteral([
73876
74037
  readonlyProperty(
73877
- AST12.tsPropertySignature(
73878
- AST12.stringLiteral("shape"),
73879
- AST12.tsTypeAnnotation(
73880
- AST12.tsTypeReference(AST12.identifier(shapeTypeName))
74038
+ AST11.tsPropertySignature(
74039
+ AST11.stringLiteral("shape"),
74040
+ AST11.tsTypeAnnotation(
74041
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName))
73881
74042
  ),
73882
74043
  true
73883
74044
  )
73884
74045
  ),
73885
74046
  readonlyProperty(
73886
- AST12.tsPropertySignature(
73887
- AST12.stringLiteral(fragmentKey),
74047
+ AST11.tsPropertySignature(
74048
+ AST11.stringLiteral(fragmentKey),
74049
+ AST11.tsTypeAnnotation(
74050
+ AST11.tsTypeLiteral([
74051
+ AST11.tsPropertySignature(
74052
+ AST11.stringLiteral(propTypeName),
74053
+ AST11.tsTypeAnnotation(
74054
+ AST11.tsLiteralType(AST11.booleanLiteral(true))
74055
+ )
74056
+ )
74057
+ ])
74058
+ )
74059
+ )
74060
+ )
74061
+ ])
74062
+ )
74063
+ ),
74064
+ AST11.exportNamedDeclaration(
74065
+ AST11.tsTypeAliasDeclaration(
74066
+ AST11.identifier(shapeTypeName),
74067
+ inlineType({
74068
+ config: config2,
74069
+ filepath,
74070
+ rootType: type,
74071
+ selections,
74072
+ root: true,
74073
+ allowReadonly: true,
74074
+ body,
74075
+ visitedTypes,
74076
+ missingScalars,
74077
+ includeFragments: true
74078
+ })
74079
+ )
74080
+ )
74081
+ );
74082
+ }
74083
+ }
74084
+
74085
+ // src/codegen/generators/typescript/imperativeTypeDef.ts
74086
+ var graphql19 = __toESM(require_graphql2(), 1);
74087
+ var recast12 = __toESM(require_main2(), 1);
74088
+ var AST12 = recast12.types.builders;
74089
+ async function imperativeCacheTypef(config2, docs) {
74090
+ const returnType = (doc) => config2.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
74091
+ config: config2,
74092
+ doc,
74093
+ ensure_import({ identifier, module: module2 }) {
74094
+ ensureImports({
74095
+ config: config2,
74096
+ body,
74097
+ sourceModule: module2,
74098
+ import: [identifier]
74099
+ });
74100
+ }
74101
+ }) ?? "any";
74102
+ const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
74103
+ const body = [];
74104
+ const declaration = AST12.tsTypeAliasDeclaration(
74105
+ AST12.identifier(CacheTypeDefName),
74106
+ AST12.tsTypeLiteral([
74107
+ AST12.tsPropertySignature(
74108
+ AST12.identifier("types"),
74109
+ AST12.tsTypeAnnotation(typeDefinitions(config2, body, docs, returnType))
74110
+ ),
74111
+ AST12.tsPropertySignature(
74112
+ AST12.identifier("lists"),
74113
+ AST12.tsTypeAnnotation(listDefinitions(config2, docs))
74114
+ ),
74115
+ AST12.tsPropertySignature(
74116
+ AST12.identifier("queries"),
74117
+ AST12.tsTypeAnnotation(queryDefinitions(config2, body, docs, returnType))
74118
+ )
74119
+ ])
74120
+ );
74121
+ declaration.declare = true;
74122
+ const importRecord = AST12.importDeclaration(
74123
+ [AST12.importSpecifier(AST12.identifier("Record"))],
74124
+ AST12.stringLiteral("./public/record")
74125
+ );
74126
+ importRecord.importKind = "type";
74127
+ await fs_exports.writeFile(
74128
+ target,
74129
+ recast12.prettyPrint(
74130
+ AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
74131
+ ).code
74132
+ );
74133
+ }
74134
+ function typeDefinitions(config2, body, docs, returnType) {
74135
+ const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
74136
+ const visitedTypes = /* @__PURE__ */ new Set();
74137
+ const types16 = Object.values(config2.schema.getTypeMap()).filter(
74138
+ (type) => !graphql19.isAbstractType(type) && !graphql19.isScalarType(type) && !graphql19.isEnumType(type) && !graphql19.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
74139
+ );
74140
+ const fragmentMap = fragmentListMap(
74141
+ config2,
74142
+ types16.map((type) => type.name),
74143
+ body,
74144
+ docs,
74145
+ returnType
74146
+ );
74147
+ return AST12.tsTypeLiteral(
74148
+ types16.map((type) => {
74149
+ let typeName = type.name;
74150
+ if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
74151
+ typeName = "__ROOT__";
74152
+ }
74153
+ let idFields = AST12.tsNeverKeyword();
74154
+ const keys = keyFieldsForType(config2.configFile, type.name);
74155
+ if (graphql19.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
74156
+ idFields = AST12.tsTypeLiteral(
74157
+ keys.map((key) => {
74158
+ const fieldType = type.getFields()[key];
74159
+ const unwrapped = unwrapType(config2, fieldType.type);
74160
+ return AST12.tsPropertySignature(
74161
+ AST12.identifier(key),
74162
+ AST12.tsTypeAnnotation(
74163
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
74164
+ )
74165
+ );
74166
+ })
74167
+ );
74168
+ } else if (typeName === "__ROOT__") {
74169
+ idFields = AST12.tsTypeLiteral([]);
74170
+ }
74171
+ let fields = AST12.tsTypeLiteral([]);
74172
+ if (graphql19.isObjectType(type)) {
74173
+ fields = AST12.tsTypeLiteral(
74174
+ Object.entries(type.getFields()).map(
74175
+ ([key, fieldType]) => {
74176
+ const unwrapped = unwrapType(config2, fieldType.type);
74177
+ let typeOptions = AST12.tsUnionType([]);
74178
+ if (graphql19.isScalarType(unwrapped.type)) {
74179
+ typeOptions.types.push(
74180
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
74181
+ );
74182
+ } else if (graphql19.isEnumType(unwrapped.type)) {
74183
+ typeOptions.types.push(
74184
+ AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
74185
+ );
74186
+ } else if (!graphql19.isAbstractType(unwrapped.type)) {
74187
+ typeOptions.types.push(record(unwrapped.type.name));
74188
+ } else {
74189
+ typeOptions.types.push(
74190
+ ...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
74191
+ );
74192
+ }
74193
+ for (const wrapper of unwrapped.wrappers) {
74194
+ if (wrapper === "Nullable" /* Nullable */) {
74195
+ typeOptions = AST12.tsParenthesizedType(
74196
+ AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
74197
+ );
74198
+ } else if (wrapper === "List" /* List */) {
74199
+ typeOptions = AST12.tsArrayType(
74200
+ AST12.tsParenthesizedType(typeOptions)
74201
+ );
74202
+ }
74203
+ }
74204
+ if (typeOptions.type === "TSParenthesizedType") {
74205
+ typeOptions = typeOptions.typeAnnotation;
74206
+ }
74207
+ let args = AST12.tsNeverKeyword();
74208
+ if (fieldType.args?.length > 0) {
74209
+ args = AST12.tsTypeLiteral(
74210
+ fieldType.args.map((arg) => {
74211
+ addReferencedInputTypes(
74212
+ config2,
74213
+ "",
74214
+ body,
74215
+ visitedTypes,
74216
+ /* @__PURE__ */ new Set(),
74217
+ arg.type
74218
+ );
74219
+ const prop = AST12.tsPropertySignature(
74220
+ AST12.identifier(arg.name),
74221
+ AST12.tsTypeAnnotation(
74222
+ tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
74223
+ )
74224
+ );
74225
+ const unwrapped2 = unwrapType(config2, arg.type);
74226
+ prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
74227
+ return prop;
74228
+ })
74229
+ );
74230
+ }
74231
+ return AST12.tsPropertySignature(
74232
+ AST12.identifier(key),
73888
74233
  AST12.tsTypeAnnotation(
73889
74234
  AST12.tsTypeLiteral([
73890
74235
  AST12.tsPropertySignature(
73891
- AST12.stringLiteral(propTypeName),
73892
- AST12.tsTypeAnnotation(
73893
- AST12.tsLiteralType(AST12.booleanLiteral(true))
73894
- )
74236
+ AST12.identifier("type"),
74237
+ AST12.tsTypeAnnotation(typeOptions)
74238
+ ),
74239
+ AST12.tsPropertySignature(
74240
+ AST12.identifier("args"),
74241
+ AST12.tsTypeAnnotation(args)
73895
74242
  )
73896
74243
  ])
73897
74244
  )
73898
- )
74245
+ );
74246
+ }
74247
+ )
74248
+ );
74249
+ }
74250
+ return AST12.tsPropertySignature(
74251
+ AST12.identifier(typeName),
74252
+ AST12.tsTypeAnnotation(
74253
+ AST12.tsTypeLiteral([
74254
+ AST12.tsPropertySignature(
74255
+ AST12.identifier("idFields"),
74256
+ AST12.tsTypeAnnotation(idFields)
74257
+ ),
74258
+ AST12.tsPropertySignature(
74259
+ AST12.identifier("fields"),
74260
+ AST12.tsTypeAnnotation(fields)
74261
+ ),
74262
+ AST12.tsPropertySignature(
74263
+ AST12.identifier("fragments"),
74264
+ AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
73899
74265
  )
73900
74266
  ])
73901
74267
  )
74268
+ );
74269
+ })
74270
+ );
74271
+ }
74272
+ function listDefinitions(config2, docs) {
74273
+ const lists = [];
74274
+ const visitedLists = /* @__PURE__ */ new Set();
74275
+ for (const doc of docs) {
74276
+ graphql19.visit(doc.document, {
74277
+ Directive(node, key, parent, path2, ancestors) {
74278
+ if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
74279
+ return;
74280
+ }
74281
+ const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
74282
+ const nameValue = nameArg?.value?.value || "";
74283
+ if (!nameValue || visitedLists.has(nameValue)) {
74284
+ return;
74285
+ }
74286
+ visitedLists.add(nameValue);
74287
+ const parentType = parentTypeFromAncestors(
74288
+ config2.schema,
74289
+ doc.filename,
74290
+ ancestors.slice(0, -1)
74291
+ );
74292
+ const targetField = ancestors[ancestors.length - 1];
74293
+ const targetFieldDefinition = parentType.getFields()[targetField.name.value];
74294
+ const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
74295
+ const possibleTypes = [];
74296
+ if (graphql19.isAbstractType(listType)) {
74297
+ possibleTypes.push(
74298
+ ...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
74299
+ );
74300
+ } else {
74301
+ possibleTypes.push(listType.name);
74302
+ }
74303
+ lists.push(
74304
+ AST12.tsPropertySignature(
74305
+ AST12.identifier(nameValue),
74306
+ AST12.tsTypeAnnotation(
74307
+ AST12.tsTypeLiteral([
74308
+ AST12.tsPropertySignature(
74309
+ AST12.identifier("types"),
74310
+ AST12.tsTypeAnnotation(
74311
+ AST12.tsUnionType(
74312
+ possibleTypes.map(
74313
+ (possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
74314
+ )
74315
+ )
74316
+ )
74317
+ ),
74318
+ AST12.tsPropertySignature(
74319
+ AST12.identifier("filters"),
74320
+ AST12.tsTypeAnnotation(
74321
+ targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
74322
+ targetFieldDefinition.args.map((arg) => {
74323
+ const argDef = AST12.tsPropertySignature(
74324
+ AST12.identifier(arg.name),
74325
+ AST12.tsTypeAnnotation(
74326
+ tsTypeReference(
74327
+ config2,
74328
+ /* @__PURE__ */ new Set(),
74329
+ arg
74330
+ )
74331
+ )
74332
+ );
74333
+ argDef.optional = true;
74334
+ return argDef;
74335
+ })
74336
+ )
74337
+ )
74338
+ )
74339
+ ])
74340
+ )
74341
+ )
74342
+ );
74343
+ }
74344
+ });
74345
+ }
74346
+ return AST12.tsTypeLiteral(lists);
74347
+ }
74348
+ function queryDefinitions(config2, body, docs, returnType) {
74349
+ return AST12.tsTupleType(
74350
+ docs.reduce((prev, doc) => {
74351
+ if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
74352
+ return prev;
74353
+ }
74354
+ const definition = doc.document.definitions.find(
74355
+ (def) => def.kind === "OperationDefinition" && def.operation === "query"
74356
+ );
74357
+ if (!definition) {
74358
+ return prev;
74359
+ }
74360
+ const runtimeType = returnType(doc);
74361
+ const [shapeType, inputType] = ensureImports({
74362
+ config: config2,
74363
+ body,
74364
+ sourceModule: path_exports.relative(
74365
+ config2.runtimeDirectory,
74366
+ config2.artifactImportPath(doc.name)
74367
+ ),
74368
+ import: [`${doc.name}$result`, `${doc.name}$input`]
74369
+ });
74370
+ return prev.concat(
74371
+ AST12.tsTupleType([
74372
+ AST12.tsTypeReference(AST12.identifier(runtimeType)),
74373
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
74374
+ AST12.tsTypeReference(AST12.identifier(inputType))
74375
+ ])
74376
+ );
74377
+ }, [])
74378
+ );
74379
+ }
74380
+ function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
74381
+ return docs.reduce((prev, doc) => {
74382
+ if (doc.kind !== "HoudiniFragment" /* Fragment */) {
74383
+ return prev;
74384
+ }
74385
+ const definition = doc.document.definitions.find(
74386
+ (def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
74387
+ );
74388
+ if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
74389
+ return prev;
74390
+ }
74391
+ const typeName = definition.typeCondition.name.value;
74392
+ const previousValue = prev[typeName]?.elementTypes ?? [];
74393
+ const tagResult = return_type(doc);
74394
+ const [shapeType] = ensureImports({
74395
+ config: config2,
74396
+ body,
74397
+ sourceModule: path_exports.relative(
74398
+ config2.runtimeDirectory,
74399
+ config2.artifactImportPath(doc.name)
73902
74400
  ),
73903
- AST12.exportNamedDeclaration(
73904
- AST12.tsTypeAliasDeclaration(
73905
- AST12.identifier(shapeTypeName),
73906
- inlineType({
74401
+ import: [`${definition.name.value}$data`]
74402
+ });
74403
+ let inputType = AST12.tsNeverKeyword();
74404
+ let directive = definition.directives?.find(
74405
+ (directive2) => directive2.name.value === config2.argumentsDirective
74406
+ );
74407
+ if (directive) {
74408
+ inputType = AST12.tsTypeReference(
74409
+ AST12.identifier(
74410
+ ensureImports({
73907
74411
  config: config2,
73908
- filepath,
73909
- rootType: type,
73910
- selections,
73911
- root: true,
73912
- allowReadonly: true,
73913
74412
  body,
73914
- visitedTypes,
73915
- missingScalars,
73916
- includeFragments: true
73917
- })
74413
+ sourceModule: path_exports.relative(
74414
+ config2.runtimeDirectory,
74415
+ config2.artifactImportPath(doc.name)
74416
+ ),
74417
+ import: [`${definition.name.value}$input`]
74418
+ })[0]
74419
+ )
74420
+ );
74421
+ }
74422
+ return {
74423
+ ...prev,
74424
+ [typeName]: AST12.tsTupleType(
74425
+ previousValue.concat(
74426
+ AST12.tsTupleType([
74427
+ AST12.tsTypeReference(AST12.identifier(tagResult)),
74428
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
74429
+ inputType
74430
+ ])
73918
74431
  )
73919
74432
  )
73920
- );
73921
- }
74433
+ };
74434
+ }, {});
74435
+ }
74436
+ var CacheTypeDefName = "CacheTypeDef";
74437
+ function record(name2) {
74438
+ return AST12.tsTypeReference(
74439
+ AST12.identifier("Record"),
74440
+ AST12.tsTypeParameterInstantiation([
74441
+ AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
74442
+ AST12.tsLiteralType(AST12.stringLiteral(name2))
74443
+ ])
74444
+ );
74445
+ }
74446
+
74447
+ // src/codegen/generators/typescript/index.ts
74448
+ async function typescriptGenerator(config2, docs) {
74449
+ await Promise.all([
74450
+ generateDocumentTypes(config2, docs),
74451
+ imperativeCacheTypef(config2, docs)
74452
+ ]);
73922
74453
  }
73923
74454
 
73924
74455
  // src/codegen/generators/persistedQueries/index.ts
73925
- var graphql19 = __toESM(require_graphql2(), 1);
74456
+ var graphql20 = __toESM(require_graphql2(), 1);
73926
74457
  async function persistOutputGenerator(config2, docs) {
73927
74458
  if (typeof config2.persistedQueryPath !== "string" || config2.persistedQueryPath.length === 0)
73928
74459
  return;
@@ -73934,8 +74465,8 @@ async function persistOutputGenerator(config2, docs) {
73934
74465
  if (!generateArtifact) {
73935
74466
  return acc;
73936
74467
  }
73937
- let rawString = graphql19.print(
73938
- graphql19.visit(document, {
74468
+ let rawString = graphql20.print(
74469
+ graphql20.visit(document, {
73939
74470
  Directive(node) {
73940
74471
  if (config2.isInternalDirective(node)) {
73941
74472
  return null;
@@ -73944,7 +74475,7 @@ async function persistOutputGenerator(config2, docs) {
73944
74475
  })
73945
74476
  );
73946
74477
  const operations = document.definitions.filter(
73947
- ({ kind }) => kind === graphql19.Kind.OPERATION_DEFINITION
74478
+ ({ kind }) => kind === graphql20.Kind.OPERATION_DEFINITION
73948
74479
  );
73949
74480
  if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
73950
74481
  acc[hashDocument(rawString)] = rawString;
@@ -73957,11 +74488,11 @@ async function persistOutputGenerator(config2, docs) {
73957
74488
  }
73958
74489
 
73959
74490
  // src/codegen/generators/definitions/enums.ts
73960
- var graphql20 = __toESM(require_graphql2(), 1);
74491
+ var graphql21 = __toESM(require_graphql2(), 1);
73961
74492
  var recast13 = __toESM(require_main2(), 1);
73962
74493
  var AST13 = recast13.types.builders;
73963
74494
  async function definitionsGenerator(config2) {
73964
- const enums = graphql20.parse(graphql20.printSchema(config2.schema)).definitions.filter(
74495
+ const enums = graphql21.parse(graphql21.printSchema(config2.schema)).definitions.filter(
73965
74496
  (definition) => definition.kind === "EnumTypeDefinition"
73966
74497
  ).filter((def) => !config2.isInternalEnum(def));
73967
74498
  const runtimeDefinitions = recast13.print(
@@ -74035,107 +74566,24 @@ async function writeIndexFile2(config2, docs) {
74035
74566
  export_default_as,
74036
74567
  export_star_from,
74037
74568
  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;
74569
+ typedef: false,
74570
+ documents: docs
74571
+ });
74124
74572
  }
74125
- const targetFragment = fragments[nextFragment];
74126
- if (!targetFragment) {
74127
- throw new HoudiniError({
74128
- filepath,
74129
- message: "compose: could not find definition for fragment " + nextFragment
74573
+ if (plugin.include_runtime) {
74574
+ body += export_star_from({
74575
+ module: relative2(config2.pluginRuntimeDirectory(plugin.name))
74130
74576
  });
74131
74577
  }
74132
- remaining.push(...targetFragment.requiredFragments);
74578
+ if (!plugin.index_file) {
74579
+ continue;
74580
+ }
74133
74581
  }
74134
- return [...frags];
74582
+ await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
74135
74583
  }
74136
74584
 
74137
74585
  // src/codegen/transforms/schema.ts
74138
- var graphql21 = __toESM(require_graphql2(), 1);
74586
+ var graphql22 = __toESM(require_graphql2(), 1);
74139
74587
  async function graphqlExtensions(config2, documents) {
74140
74588
  const internalSchema = `
74141
74589
  enum CachePolicy {
@@ -74169,407 +74617,147 @@ directive @${config2.listAppendDirective} on FRAGMENT_SPREAD
74169
74617
 
74170
74618
  """
74171
74619
  @${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
- };
74620
+ """
74621
+ directive @${config2.listAllListsDirective} on FRAGMENT_SPREAD
74622
+
74623
+ """
74624
+ @${config2.listParentDirective} is used to provide a parentID without specifying position or in situations
74625
+ where it doesn't make sense (eg when deleting a node.)
74626
+ """
74627
+ directive @${config2.listParentDirective}(value: ID!) on FRAGMENT_SPREAD
74628
+
74629
+ """
74630
+ @${config2.whenDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
74631
+ """
74632
+ directive @${config2.whenDirective} on FRAGMENT_SPREAD
74633
+
74634
+ """
74635
+ @${config2.whenNotDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
74636
+ """
74637
+ directive @${config2.whenNotDirective} on FRAGMENT_SPREAD
74638
+
74639
+ """
74640
+ @${config2.argumentsDirective} is used to define the arguments of a fragment
74641
+ """
74642
+ directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
74643
+
74644
+ """
74645
+ @${config2.cacheDirective} is used to specify cache rules for a query
74646
+ """
74647
+ directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
74648
+
74649
+ """
74650
+ @${config2.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
74651
+ """
74652
+ directive @${config2.loadDirective} on QUERY
74653
+
74654
+ """
74655
+ @${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
74656
+ """
74657
+ directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
74658
+
74659
+ """
74660
+ @${config2.maskDisableDirective} to disable masking on fragment (overwriting the global conf)
74661
+ """
74662
+ directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
74663
+ `;
74664
+ let currentSchema = graphql22.printSchema(config2.schema);
74665
+ if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
74666
+ currentSchema += internalSchema;
74667
+ }
74668
+ config2.newSchema += internalSchema;
74669
+ config2.schema = graphql22.buildSchema(currentSchema);
74670
+ }
74671
+
74672
+ // src/codegen/transforms/typename.ts
74673
+ var graphql23 = __toESM(require_graphql2(), 1);
74674
+ async function addTypename(config2, documents) {
74675
+ for (const doc of documents) {
74676
+ doc.document = graphql23.visit(doc.document, {
74677
+ Field(node, key, parent, path2, ancestors) {
74678
+ if (!node.selectionSet) {
74679
+ return;
74423
74680
  }
74424
- if (node.name.value !== newFragmentName) {
74681
+ const type = parentTypeFromAncestors(
74682
+ config2.schema,
74683
+ doc.filename,
74684
+ ancestors.slice(0, -1)
74685
+ );
74686
+ const field = type.getFields()[node.name.value];
74687
+ const fieldType = unwrapType(config2, field.type).type;
74688
+ if (graphql23.isInterfaceType(fieldType) || graphql23.isUnionType(fieldType)) {
74425
74689
  return {
74426
74690
  ...node,
74427
- name: {
74428
- kind: "Name",
74429
- value: newFragmentName
74691
+ selectionSet: {
74692
+ ...node.selectionSet,
74693
+ selections: [
74694
+ ...node.selectionSet.selections,
74695
+ {
74696
+ kind: graphql23.Kind.FIELD,
74697
+ name: {
74698
+ kind: graphql23.Kind.NAME,
74699
+ value: "__typename"
74700
+ }
74701
+ }
74702
+ ]
74430
74703
  }
74431
74704
  };
74432
74705
  }
74433
74706
  }
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 [];
74707
+ });
74476
74708
  }
74477
- return withDirectives.flatMap((directive) => directive.arguments || []);
74478
74709
  }
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
74710
+
74711
+ // src/codegen/transforms/addID.ts
74712
+ var graphql24 = __toESM(require_graphql2(), 1);
74713
+ async function addID(config2, documents) {
74714
+ for (const doc of documents) {
74715
+ doc.document = graphql24.visit(doc.document, {
74716
+ Field(node, key, parent, path2, ancestors) {
74717
+ if (!node.selectionSet) {
74718
+ return;
74513
74719
  }
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
74720
+ const type = parentTypeFromAncestors(
74721
+ config2.schema,
74722
+ doc.filename,
74723
+ ancestors.slice(0, -1)
74724
+ );
74725
+ const field = type.getFields()[node.name.value];
74726
+ const fieldType = unwrapType(config2, field.type).type;
74727
+ if (node.selectionSet?.selections.length > 0) {
74728
+ if (!graphql24.isObjectType(fieldType) && !graphql24.isInterfaceType(fieldType)) {
74729
+ return;
74730
+ }
74731
+ const keyFields = config2.keyFieldsForType(fieldType.name);
74732
+ if (keyFields.find((key2) => !fieldType.getFields()[key2])) {
74733
+ return;
74734
+ }
74735
+ const selections = [...node.selectionSet.selections];
74736
+ for (const keyField of keyFields) {
74737
+ if (node.selectionSet.selections.find(
74738
+ (selection2) => selection2.kind === "Field" && !selection2.alias && selection2.name.value === keyField
74739
+ )) {
74740
+ continue;
74741
+ }
74742
+ selections.push({
74743
+ kind: graphql24.Kind.FIELD,
74744
+ name: {
74745
+ kind: graphql24.Kind.NAME,
74746
+ value: keyField
74747
+ }
74748
+ });
74749
+ }
74750
+ return {
74751
+ ...node,
74752
+ selectionSet: {
74753
+ ...node.selectionSet,
74754
+ selections
74755
+ }
74756
+ };
74568
74757
  }
74569
74758
  }
74570
- }),
74571
- {}
74572
- ) || {};
74759
+ });
74760
+ }
74573
74761
  }
74574
74762
 
74575
74763
  // src/codegen/validators/typeCheck.ts
@@ -75922,7 +76110,9 @@ var writeConfigFile = async ({
75922
76110
  }) => {
75923
76111
  const config2 = {};
75924
76112
  if (url !== null) {
75925
- config2.apiUrl = url;
76113
+ config2.watchSchema = {
76114
+ url
76115
+ };
75926
76116
  }
75927
76117
  if (schemaPath !== "./schema.graphql") {
75928
76118
  config2.schemaPath = schemaPath;
@@ -76088,8 +76278,8 @@ async function updatePackageJSON(targetPath) {
76088
76278
  }
76089
76279
  packageJSON.devDependencies = {
76090
76280
  ...packageJSON.devDependencies,
76091
- houdini: "^1.0.0-next.2",
76092
- "houdini-svelte": "^1.0.0-next.2",
76281
+ houdini: "^1.0.0-next.3",
76282
+ "houdini-svelte": "^1.0.0-next.3",
76093
76283
  graphql: "^15.8.0"
76094
76284
  };
76095
76285
  await fs_exports.writeFile(packagePath, JSON.stringify(packageJSON, null, 4));