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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/build/cmd-cjs/index.js +1417 -1231
  2. package/build/cmd-esm/index.js +1417 -1231
  3. package/build/codegen/generators/artifacts/selection.d.ts +3 -3
  4. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  5. package/build/codegen/generators/typescript/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
  6. package/build/codegen/transforms/fragmentVariables.d.ts +1 -0
  7. package/build/codegen-cjs/index.js +1262 -1078
  8. package/build/codegen-esm/index.js +1262 -1078
  9. package/build/lib/config.d.ts +1 -1
  10. package/build/lib/walk.d.ts +4 -1
  11. package/build/lib-cjs/index.js +10 -10
  12. package/build/lib-esm/index.js +10 -10
  13. package/build/runtime/cache/cache.d.ts +3 -3
  14. package/build/runtime/cache/lists.d.ts +1 -0
  15. package/build/runtime/client/documentStore.d.ts +1 -1
  16. package/build/runtime/client/plugins/fetchParams.d.ts +1 -1
  17. package/build/runtime/generated.d.ts +1 -0
  18. package/build/runtime/index.d.ts +1 -1
  19. package/build/runtime/lib/config.d.ts +21 -22
  20. package/build/runtime/lib/scalars.d.ts +2 -2
  21. package/build/runtime/lib/types.d.ts +2 -3
  22. package/build/runtime/public/cache.d.ts +19 -6
  23. package/build/runtime/public/record.d.ts +17 -17
  24. package/build/runtime/public/tests/test.d.ts +43 -0
  25. package/build/runtime/public/types.d.ts +8 -0
  26. package/build/runtime-cjs/cache/cache.d.ts +3 -3
  27. package/build/runtime-cjs/cache/cache.js +30 -15
  28. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  29. package/build/runtime-cjs/cache/lists.js +6 -3
  30. package/build/runtime-cjs/client/documentStore.d.ts +1 -1
  31. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
  32. package/build/runtime-cjs/client/plugins/fetchParams.js +6 -1
  33. package/build/runtime-cjs/client/plugins/query.js +0 -1
  34. package/build/runtime-cjs/generated.d.ts +1 -0
  35. package/build/runtime-cjs/index.d.ts +1 -1
  36. package/build/runtime-cjs/lib/config.d.ts +21 -22
  37. package/build/runtime-cjs/lib/scalars.d.ts +2 -2
  38. package/build/runtime-cjs/lib/types.d.ts +2 -3
  39. package/build/runtime-cjs/public/cache.d.ts +19 -6
  40. package/build/runtime-cjs/public/cache.js +29 -32
  41. package/build/runtime-cjs/public/list.js +6 -28
  42. package/build/runtime-cjs/public/record.d.ts +17 -17
  43. package/build/runtime-cjs/public/record.js +22 -188
  44. package/build/runtime-cjs/public/tests/test.d.ts +43 -0
  45. package/build/runtime-cjs/public/tests/test.js +27 -2
  46. package/build/runtime-cjs/public/types.d.ts +8 -0
  47. package/build/runtime-esm/cache/cache.d.ts +3 -3
  48. package/build/runtime-esm/cache/cache.js +30 -15
  49. package/build/runtime-esm/cache/lists.d.ts +1 -0
  50. package/build/runtime-esm/cache/lists.js +6 -3
  51. package/build/runtime-esm/client/documentStore.d.ts +1 -1
  52. package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
  53. package/build/runtime-esm/client/plugins/fetchParams.js +6 -1
  54. package/build/runtime-esm/client/plugins/query.js +0 -1
  55. package/build/runtime-esm/generated.d.ts +1 -0
  56. package/build/runtime-esm/index.d.ts +1 -1
  57. package/build/runtime-esm/lib/config.d.ts +21 -22
  58. package/build/runtime-esm/lib/scalars.d.ts +2 -2
  59. package/build/runtime-esm/lib/types.d.ts +2 -3
  60. package/build/runtime-esm/public/cache.d.ts +19 -6
  61. package/build/runtime-esm/public/cache.js +28 -30
  62. package/build/runtime-esm/public/list.js +6 -28
  63. package/build/runtime-esm/public/record.d.ts +17 -17
  64. package/build/runtime-esm/public/record.js +21 -184
  65. package/build/runtime-esm/public/tests/test.d.ts +43 -0
  66. package/build/runtime-esm/public/tests/test.js +26 -1
  67. package/build/runtime-esm/public/types.d.ts +8 -0
  68. package/build/test-cjs/index.js +1270 -1087
  69. package/build/test-esm/index.js +1270 -1087
  70. package/build/vite-cjs/index.js +1271 -1087
  71. package/build/vite-esm/index.js +1271 -1087
  72. package/package.json +1 -1
@@ -66722,8 +66722,7 @@ var Config = class {
66722
66722
  types: types17 = {},
66723
66723
  logLevel,
66724
66724
  defaultFragmentMasking = "enable",
66725
- schemaPollInterval = 2e3,
66726
- schemaPollHeaders = {},
66725
+ watchSchema,
66727
66726
  projectDir
66728
66727
  } = this.configFile;
66729
66728
  if (typeof schema === "string") {
@@ -66756,8 +66755,8 @@ var Config = class {
66756
66755
  this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
66757
66756
  this.defaultFragmentMasking = defaultFragmentMasking;
66758
66757
  this.routesDir = join2(this.projectRoot, "src", "routes");
66759
- this.schemaPollInterval = schemaPollInterval;
66760
- this.schemaPollHeaders = schemaPollHeaders;
66758
+ this.schemaPollInterval = watchSchema?.interval ?? 2e3;
66759
+ this.schemaPollHeaders = watchSchema?.headers ?? {};
66761
66760
  this.rootDir = join2(this.projectRoot, "$houdini");
66762
66761
  if (defaultKeys) {
66763
66762
  this.defaultKeys = defaultKeys;
@@ -66770,11 +66769,12 @@ var Config = class {
66770
66769
  }
66771
66770
  }
66772
66771
  async apiURL() {
66773
- if (!this.configFile.apiUrl) {
66772
+ const apiURL = this.configFile.watchSchema?.url;
66773
+ if (!apiURL) {
66774
66774
  return "";
66775
66775
  }
66776
66776
  const env = await this.getEnv();
66777
- return this.processEnvValues(env, this.configFile.apiUrl);
66777
+ return this.processEnvValues(env, apiURL);
66778
66778
  }
66779
66779
  get include() {
66780
66780
  if (this.configFile.include) {
@@ -66978,8 +66978,8 @@ var Config = class {
66978
66978
  pluginDirectory(name2) {
66979
66979
  return join2(this.pluginRootDirectory, name2);
66980
66980
  }
66981
- get manualLoadDirective() {
66982
- return "manual_load";
66981
+ get loadDirective() {
66982
+ return "load";
66983
66983
  }
66984
66984
  get maskEnableDirective() {
66985
66985
  return "mask_enable";
@@ -67096,7 +67096,7 @@ var Config = class {
67096
67096
  this.withDirective,
67097
67097
  this.paginateDirective,
67098
67098
  this.cacheDirective,
67099
- this.manualLoadDirective,
67099
+ this.loadDirective,
67100
67100
  this.maskEnableDirective,
67101
67101
  this.maskDisableDirective
67102
67102
  ].includes(name2.value) || this.isDeleteDirective(name2.value);
@@ -67681,7 +67681,7 @@ async function find_graphql(config4, parsedScript, walker) {
67681
67681
  return;
67682
67682
  }
67683
67683
  const parsedTag = graphql4.parse(documentString);
67684
- if (walker.where && !walker.where(parsedTag)) {
67684
+ if (walker.where && !walker.where(parsedTag, { node, parent })) {
67685
67685
  return;
67686
67686
  }
67687
67687
  const definition = config4.extractDefinition(parsedTag);
@@ -67722,7 +67722,7 @@ async function find_graphql(config4, parsedScript, walker) {
67722
67722
  }
67723
67723
 
67724
67724
  // src/codegen/generators/artifacts/index.ts
67725
- var graphql13 = __toESM(require_graphql2(), 1);
67725
+ var graphql14 = __toESM(require_graphql2(), 1);
67726
67726
  var recast5 = __toESM(require_main2(), 1);
67727
67727
 
67728
67728
  // src/codegen/utils/commonjs.ts
@@ -67980,159 +67980,534 @@ function murmurHash(str) {
67980
67980
  return s2;
67981
67981
  }
67982
67982
 
67983
- // src/codegen/generators/artifacts/indexFile.ts
67984
- async function writeIndexFile(config4, docs) {
67985
- const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
67986
- let body = config4.module === "esm" ? docsToGenerate.reduce(
67987
- (content, doc) => content + `
67988
- export { default as ${doc.name}} from './${doc.name}'`,
67989
- ""
67990
- ) : docsToGenerate.reduce(
67991
- (content, doc) => content + `
67992
- ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
67993
- cjsIndexFilePreamble
67994
- );
67995
- await fs_exports.writeFile(path_exports.join(config4.artifactDirectory, "index.js"), body);
67996
- }
67997
-
67998
- // src/codegen/generators/artifacts/inputs.ts
67983
+ // src/codegen/transforms/fragmentVariables.ts
67999
67984
  var graphql5 = __toESM(require_graphql2(), 1);
68000
- var recast3 = __toESM(require_main2(), 1);
68001
- var AST3 = recast3.types.builders;
68002
- function inputObject(config4, inputs) {
68003
- const visitedTypes = /* @__PURE__ */ new Set();
68004
- const inputObj = {
68005
- fields: inputs.reduce((fields, input) => {
68006
- const { type } = unwrapType(config4, input.type);
68007
- return {
68008
- ...fields,
68009
- [input.variable.name.value]: type.name
68010
- };
68011
- }, {}),
68012
- types: {}
68013
- };
68014
- for (const input of inputs) {
68015
- walkInputs(config4, visitedTypes, inputObj, input.type);
68016
- }
68017
- return inputObj;
68018
- }
68019
- function walkInputs(config4, visitedTypes, inputObj, rootType) {
68020
- const { type } = unwrapType(config4, rootType);
68021
- if (visitedTypes.has(type.name)) {
68022
- return;
68023
- }
68024
- if (graphql5.isEnumType(type) || graphql5.isScalarType(type)) {
68025
- return;
68026
- }
68027
- if (graphql5.isUnionType(type)) {
68028
- return;
68029
- }
68030
- visitedTypes.add(type.name);
68031
- inputObj.types[type.name] = Object.values(type.getFields()).reduce(
68032
- (typeFields, field) => {
68033
- const { type: fieldType } = unwrapType(config4, field.type);
68034
- walkInputs(config4, visitedTypes, inputObj, fieldType);
68035
- return {
68036
- ...typeFields,
68037
- [field.name]: fieldType.toString()
68038
- };
68039
- },
68040
- {}
68041
- );
68042
- }
68043
67985
 
68044
- // src/codegen/generators/artifacts/operations.ts
68045
- var graphql7 = __toESM(require_graphql2(), 1);
68046
-
68047
- // src/codegen/generators/artifacts/utils.ts
68048
- var graphql6 = __toESM(require_graphql2(), 1);
68049
- var recast4 = __toESM(require_main2(), 1);
68050
- var AST4 = recast4.types.builders;
68051
- function serializeValue(value) {
68052
- if (Array.isArray(value)) {
68053
- return AST4.arrayExpression(value.map(serializeValue));
67986
+ // src/codegen/transforms/composeQueries.ts
67987
+ var import_graphql30 = __toESM(require_graphql2(), 1);
67988
+ async function includeFragmentDefinitions(config4, documents) {
67989
+ const fragments = collectFragments(config4, documents);
67990
+ for (const [index, { name: name2, document, filename }] of documents.entries()) {
67991
+ const operation = document.definitions.find(
67992
+ ({ kind }) => kind === import_graphql30.Kind.OPERATION_DEFINITION
67993
+ );
67994
+ if (!operation) {
67995
+ continue;
67996
+ }
67997
+ const allFragments = flattenFragments(
67998
+ filename,
67999
+ { requiredFragments: findRequiredFragments(operation.selectionSet) },
68000
+ fragments
68001
+ );
68002
+ documents[index].document = {
68003
+ ...document,
68004
+ definitions: [
68005
+ operation,
68006
+ ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
68007
+ ]
68008
+ };
68054
68009
  }
68055
- if (typeof value === "object" && value !== null) {
68056
- return AST4.objectExpression(
68057
- Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
68058
- ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
68059
- )
68010
+ }
68011
+ function collectFragments(config4, docs) {
68012
+ return docs.reduce((acc, doc) => {
68013
+ const definitions = doc.document.definitions.reduce(
68014
+ (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
68015
+ ...prev,
68016
+ [definition.name.value]: {
68017
+ definition,
68018
+ requiredFragments: findRequiredFragments(definition.selectionSet),
68019
+ document: doc
68020
+ }
68021
+ },
68022
+ {}
68060
68023
  );
68024
+ return {
68025
+ ...acc,
68026
+ ...definitions
68027
+ };
68028
+ }, {});
68029
+ }
68030
+ function findRequiredFragments(selectionSet) {
68031
+ if (selectionSet.selections.length === 0) {
68032
+ return [];
68061
68033
  }
68062
- if (typeof value === "string") {
68063
- if (value.indexOf("\n") !== -1) {
68064
- return AST4.templateLiteral(
68065
- [AST4.templateElement({ raw: value, cooked: value }, true)],
68066
- []
68067
- );
68034
+ const referencedFragments = [];
68035
+ for (const selection2 of selectionSet.selections) {
68036
+ if (selection2.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
68037
+ referencedFragments.push(selection2.name.value);
68038
+ } else if (selection2.selectionSet) {
68039
+ referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
68068
68040
  }
68069
- return AST4.stringLiteral(value);
68070
68041
  }
68071
- return AST4.literal(value);
68042
+ return referencedFragments;
68072
68043
  }
68073
- function deepMerge(filepath, ...targets) {
68074
- if (typeof targets[0] !== "object") {
68075
- const matches = targets.filter((val) => val !== targets[0]).length === 0;
68076
- if (!matches) {
68077
- throw new HoudiniError({ filepath, message: "could not merge: " + targets });
68044
+ function flattenFragments(filepath, operation, fragments) {
68045
+ const frags = /* @__PURE__ */ new Set();
68046
+ const remaining = [...operation.requiredFragments];
68047
+ while (remaining.length > 0) {
68048
+ const nextFragment = remaining.shift();
68049
+ if (!nextFragment) {
68050
+ continue;
68078
68051
  }
68079
- return targets[0];
68080
- }
68081
- if (Array.isArray(targets[0])) {
68082
- return targets[0].concat(...targets.slice(1));
68083
- }
68084
- const fields = {};
68085
- for (const target of targets) {
68086
- for (const [key, value] of Object.entries(target)) {
68087
- if (!fields[key]) {
68088
- fields[key] = [];
68089
- }
68090
- fields[key].push(value);
68052
+ if (!frags.has(nextFragment)) {
68053
+ frags.add(nextFragment);
68054
+ } else {
68055
+ continue;
68056
+ }
68057
+ const targetFragment = fragments[nextFragment];
68058
+ if (!targetFragment) {
68059
+ throw new HoudiniError({
68060
+ filepath,
68061
+ message: "compose: could not find definition for fragment " + nextFragment
68062
+ });
68091
68063
  }
68064
+ remaining.push(...targetFragment.requiredFragments);
68092
68065
  }
68093
- return Object.fromEntries(
68094
- Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
68095
- );
68066
+ return [...frags];
68096
68067
  }
68097
- function convertValue(config4, val) {
68098
- let value;
68099
- let kind;
68100
- if (val.kind === graphql6.Kind.INT) {
68101
- value = parseInt(val.value, 10);
68102
- kind = "Int";
68103
- } else if (val.kind === graphql6.Kind.FLOAT) {
68104
- value = parseFloat(val.value);
68105
- kind = "Float";
68106
- } else if (val.kind === graphql6.Kind.BOOLEAN) {
68107
- value = val.value;
68108
- kind = "Boolean";
68109
- } else if (val.kind === graphql6.Kind.VARIABLE) {
68110
- value = val.name.value;
68111
- kind = "Variable";
68112
- } else if (val.kind === graphql6.Kind.STRING) {
68113
- value = val.value;
68114
- kind = "String";
68068
+
68069
+ // src/codegen/transforms/fragmentVariables.ts
68070
+ var GraphqlKinds2 = graphql5.Kind;
68071
+ async function fragmentVariables(config4, documents) {
68072
+ const fragments = collectFragments(config4, documents);
68073
+ const generatedFragments = {};
68074
+ const visitedFragments = /* @__PURE__ */ new Set();
68075
+ for (const doc2 of documents) {
68076
+ const operation = doc2.document.definitions.find(
68077
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
68078
+ );
68079
+ if (!operation) {
68080
+ continue;
68081
+ }
68082
+ doc2.document = inlineFragmentArgs({
68083
+ config: config4,
68084
+ filepath: doc2.filename,
68085
+ fragmentDefinitions: fragments,
68086
+ document: doc2.document,
68087
+ generatedFragments,
68088
+ visitedFragments,
68089
+ scope: null
68090
+ });
68115
68091
  }
68116
- return { kind, value };
68092
+ const doc = {
68093
+ kind: graphql5.Kind.DOCUMENT,
68094
+ definitions: Object.values(generatedFragments)
68095
+ };
68096
+ documents.push({
68097
+ name: "generated::fragmentVariables",
68098
+ kind: "HoudiniFragment" /* Fragment */,
68099
+ document: doc,
68100
+ originalDocument: doc,
68101
+ generateStore: false,
68102
+ generateArtifact: false,
68103
+ filename: "generated::fragmentVariables",
68104
+ originalString: ""
68105
+ });
68117
68106
  }
68118
-
68119
- // src/codegen/generators/artifacts/operations.ts
68120
- function operationsByPath(config4, filepath, definition, filterTypes) {
68121
- if (!definition) {
68122
- return {};
68107
+ function inlineFragmentArgs({
68108
+ config: config4,
68109
+ filepath,
68110
+ fragmentDefinitions,
68111
+ document,
68112
+ generatedFragments,
68113
+ visitedFragments,
68114
+ scope,
68115
+ newName
68116
+ }) {
68117
+ if (!scope) {
68118
+ scope = operationScope(
68119
+ document.definitions.find(
68120
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
68121
+ )
68122
+ );
68123
68123
  }
68124
- const pathOperations = {};
68125
- graphql7.visit(definition, {
68126
- FragmentSpread(node, _, __, ___, ancestors) {
68127
- if (!config4.isListFragment(node.name.value)) {
68128
- return;
68129
- }
68130
- const path2 = ancestorKey(ancestors);
68131
- if (!pathOperations[path2]) {
68132
- pathOperations[path2] = [];
68133
- }
68134
- pathOperations[path2].push(
68135
- operationObject({
68124
+ const definitionArgs = fragmentArguments(
68125
+ config4,
68126
+ filepath,
68127
+ document
68128
+ ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
68129
+ const result = graphql5.visit(document, {
68130
+ FragmentSpread(node) {
68131
+ const { definition } = fragmentDefinitions[node.name.value];
68132
+ let { args, hash } = collectWithArguments(config4, filepath, node, scope);
68133
+ const newFragmentName = `${node.name.value}${hash}`;
68134
+ if (!visitedFragments.has(newFragmentName)) {
68135
+ visitedFragments.add(newFragmentName);
68136
+ const defaultArguments = collectDefaultArgumentValues(config4, filepath, definition);
68137
+ if (args) {
68138
+ for (const [field, value] of Object.entries(defaultArguments || {})) {
68139
+ if (!args[field]) {
68140
+ args[field] = value;
68141
+ }
68142
+ }
68143
+ generatedFragments[newFragmentName] = inlineFragmentArgs({
68144
+ config: config4,
68145
+ filepath,
68146
+ fragmentDefinitions,
68147
+ document: fragmentDefinitions[node.name.value].definition,
68148
+ generatedFragments,
68149
+ visitedFragments,
68150
+ scope: args,
68151
+ newName: newFragmentName
68152
+ });
68153
+ } else {
68154
+ const doc = fragmentDefinitions[node.name.value].document;
68155
+ const definitionIndex = doc.document.definitions.findIndex(
68156
+ (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
68157
+ );
68158
+ const localDefinitions = [...doc.document.definitions];
68159
+ localDefinitions.splice(definitionIndex, 1);
68160
+ localDefinitions.push(
68161
+ inlineFragmentArgs({
68162
+ config: config4,
68163
+ filepath,
68164
+ fragmentDefinitions,
68165
+ document: fragmentDefinitions[node.name.value].definition,
68166
+ generatedFragments,
68167
+ visitedFragments,
68168
+ scope: defaultArguments,
68169
+ newName: ""
68170
+ })
68171
+ );
68172
+ doc.document = {
68173
+ ...doc.document,
68174
+ definitions: localDefinitions
68175
+ };
68176
+ }
68177
+ if (node.name.value !== newFragmentName) {
68178
+ return {
68179
+ ...node,
68180
+ name: {
68181
+ kind: "Name",
68182
+ value: newFragmentName
68183
+ }
68184
+ };
68185
+ }
68186
+ }
68187
+ },
68188
+ Argument(node) {
68189
+ const value = node.value;
68190
+ if (value.kind !== "Variable") {
68191
+ return;
68192
+ }
68193
+ if (!scope) {
68194
+ throw new HoudiniError({
68195
+ filepath,
68196
+ message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
68197
+ });
68198
+ }
68199
+ const newValue = scope[value.name.value];
68200
+ if (newValue) {
68201
+ return {
68202
+ ...node,
68203
+ value: newValue
68204
+ };
68205
+ }
68206
+ if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
68207
+ throw new HoudiniError({
68208
+ filepath,
68209
+ message: "Missing value for required arg: " + value.name.value
68210
+ });
68211
+ }
68212
+ return null;
68213
+ }
68214
+ });
68215
+ if (newName) {
68216
+ result.name = {
68217
+ kind: graphql5.Kind.NAME,
68218
+ value: newName
68219
+ };
68220
+ }
68221
+ return result;
68222
+ }
68223
+ function withArguments(config4, node) {
68224
+ const withDirectives = node.directives?.filter(
68225
+ (directive) => directive.name.value === config4.withDirective
68226
+ );
68227
+ if (!withDirectives || withDirectives.length === 0) {
68228
+ return [];
68229
+ }
68230
+ return withDirectives.flatMap((directive) => directive.arguments || []);
68231
+ }
68232
+ function fragmentArguments(config4, filepath, definition) {
68233
+ const directives = definition.directives?.filter(
68234
+ (directive) => directive.name.value === config4.argumentsDirective
68235
+ );
68236
+ if (!directives || directives.length === 0) {
68237
+ return [];
68238
+ }
68239
+ return directives.flatMap(
68240
+ (directive) => directive.arguments?.flatMap((arg) => {
68241
+ if (arg.value.kind !== "ObjectValue") {
68242
+ throw new HoudiniError({
68243
+ filepath,
68244
+ message: "values of @argument must be objects"
68245
+ });
68246
+ }
68247
+ const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
68248
+ if (!typeArg || typeArg.kind !== "StringValue") {
68249
+ return [];
68250
+ }
68251
+ let type = typeArg.value;
68252
+ let name2 = arg.name.value;
68253
+ let required = false;
68254
+ let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
68255
+ if (type[type.length - 1] === "!") {
68256
+ type = type.slice(0, -1);
68257
+ required = true;
68258
+ defaultValue = null;
68259
+ }
68260
+ return [
68261
+ {
68262
+ name: name2,
68263
+ type,
68264
+ required,
68265
+ defaultValue
68266
+ }
68267
+ ];
68268
+ }) || []
68269
+ );
68270
+ }
68271
+ function collectDefaultArgumentValues(config4, filepath, definition) {
68272
+ let result = {};
68273
+ for (const { name: name2, required, defaultValue } of fragmentArguments(
68274
+ config4,
68275
+ filepath,
68276
+ definition
68277
+ )) {
68278
+ if (required || !defaultValue) {
68279
+ continue;
68280
+ }
68281
+ result[name2] = defaultValue;
68282
+ }
68283
+ return result;
68284
+ }
68285
+ function collectWithArguments(config4, filepath, node, scope = {}) {
68286
+ const withArgs = withArguments(config4, node);
68287
+ if (withArgs.length === 0) {
68288
+ return { args: null, hash: "" };
68289
+ }
68290
+ let args = {};
68291
+ for (const arg of withArgs) {
68292
+ let value = arg.value;
68293
+ if (value.kind === GraphqlKinds2.VARIABLE) {
68294
+ if (!scope || !scope[value.name.value]) {
68295
+ throw new HoudiniError({
68296
+ filepath,
68297
+ message: "Encountered undefined variable: " + value.name.value
68298
+ });
68299
+ }
68300
+ value = scope[value.name.value];
68301
+ }
68302
+ args[arg.name.value] = {
68303
+ ...value,
68304
+ loc: void 0
68305
+ };
68306
+ }
68307
+ return {
68308
+ args,
68309
+ hash: "_" + murmurHash(JSON.stringify(args))
68310
+ };
68311
+ }
68312
+ function operationScope(operation) {
68313
+ return operation.variableDefinitions?.reduce(
68314
+ (scope, definition) => ({
68315
+ ...scope,
68316
+ [definition.variable.name.value]: {
68317
+ kind: "Variable",
68318
+ name: {
68319
+ kind: "Name",
68320
+ value: definition.variable.name.value
68321
+ }
68322
+ }
68323
+ }),
68324
+ {}
68325
+ ) || {};
68326
+ }
68327
+ function fragmentArgumentsDefinitions(config4, filepath, definition) {
68328
+ const args = fragmentArguments(config4, filepath, definition);
68329
+ if (args.length === 0) {
68330
+ return [];
68331
+ }
68332
+ return args.map((arg) => {
68333
+ const innerType = {
68334
+ kind: "NamedType",
68335
+ name: {
68336
+ kind: "Name",
68337
+ value: arg.type
68338
+ }
68339
+ };
68340
+ return {
68341
+ kind: "VariableDefinition",
68342
+ type: arg.required ? innerType : {
68343
+ kind: "NonNullType",
68344
+ type: innerType
68345
+ },
68346
+ variable: {
68347
+ kind: "Variable",
68348
+ name: {
68349
+ kind: "Name",
68350
+ value: arg.name
68351
+ }
68352
+ },
68353
+ defaultValue: arg.defaultValue ?? void 0
68354
+ };
68355
+ });
68356
+ }
68357
+
68358
+ // src/codegen/generators/artifacts/indexFile.ts
68359
+ async function writeIndexFile(config4, docs) {
68360
+ const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
68361
+ let body = config4.module === "esm" ? docsToGenerate.reduce(
68362
+ (content, doc) => content + `
68363
+ export { default as ${doc.name}} from './${doc.name}'`,
68364
+ ""
68365
+ ) : docsToGenerate.reduce(
68366
+ (content, doc) => content + `
68367
+ ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
68368
+ cjsIndexFilePreamble
68369
+ );
68370
+ await fs_exports.writeFile(path_exports.join(config4.artifactDirectory, "index.js"), body);
68371
+ }
68372
+
68373
+ // src/codegen/generators/artifacts/inputs.ts
68374
+ var graphql6 = __toESM(require_graphql2(), 1);
68375
+ var recast3 = __toESM(require_main2(), 1);
68376
+ var AST3 = recast3.types.builders;
68377
+ function inputObject(config4, inputs) {
68378
+ const visitedTypes = /* @__PURE__ */ new Set();
68379
+ const inputObj = {
68380
+ fields: inputs.reduce((fields, input) => {
68381
+ const { type } = unwrapType(config4, input.type);
68382
+ return {
68383
+ ...fields,
68384
+ [input.variable.name.value]: type.name
68385
+ };
68386
+ }, {}),
68387
+ types: {}
68388
+ };
68389
+ for (const input of inputs) {
68390
+ walkInputs(config4, visitedTypes, inputObj, input.type);
68391
+ }
68392
+ return inputObj;
68393
+ }
68394
+ function walkInputs(config4, visitedTypes, inputObj, rootType) {
68395
+ const { type } = unwrapType(config4, rootType);
68396
+ if (visitedTypes.has(type.name)) {
68397
+ return;
68398
+ }
68399
+ if (graphql6.isEnumType(type) || graphql6.isScalarType(type)) {
68400
+ return;
68401
+ }
68402
+ if (graphql6.isUnionType(type)) {
68403
+ return;
68404
+ }
68405
+ visitedTypes.add(type.name);
68406
+ inputObj.types[type.name] = Object.values(type.getFields()).reduce(
68407
+ (typeFields, field) => {
68408
+ const { type: fieldType } = unwrapType(config4, field.type);
68409
+ walkInputs(config4, visitedTypes, inputObj, fieldType);
68410
+ return {
68411
+ ...typeFields,
68412
+ [field.name]: fieldType.toString()
68413
+ };
68414
+ },
68415
+ {}
68416
+ );
68417
+ }
68418
+
68419
+ // src/codegen/generators/artifacts/operations.ts
68420
+ var graphql8 = __toESM(require_graphql2(), 1);
68421
+
68422
+ // src/codegen/generators/artifacts/utils.ts
68423
+ var graphql7 = __toESM(require_graphql2(), 1);
68424
+ var recast4 = __toESM(require_main2(), 1);
68425
+ var AST4 = recast4.types.builders;
68426
+ function serializeValue(value) {
68427
+ if (Array.isArray(value)) {
68428
+ return AST4.arrayExpression(value.map(serializeValue));
68429
+ }
68430
+ if (typeof value === "object" && value !== null) {
68431
+ return AST4.objectExpression(
68432
+ Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
68433
+ ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
68434
+ )
68435
+ );
68436
+ }
68437
+ if (typeof value === "string") {
68438
+ if (value.indexOf("\n") !== -1) {
68439
+ return AST4.templateLiteral(
68440
+ [AST4.templateElement({ raw: value, cooked: value }, true)],
68441
+ []
68442
+ );
68443
+ }
68444
+ return AST4.stringLiteral(value);
68445
+ }
68446
+ return AST4.literal(value);
68447
+ }
68448
+ function deepMerge(filepath, ...targets) {
68449
+ if (typeof targets[0] !== "object") {
68450
+ const matches = targets.filter((val) => val !== targets[0]).length === 0;
68451
+ if (!matches) {
68452
+ throw new HoudiniError({ filepath, message: "could not merge: " + targets });
68453
+ }
68454
+ return targets[0];
68455
+ }
68456
+ if (Array.isArray(targets[0])) {
68457
+ return targets[0].concat(...targets.slice(1));
68458
+ }
68459
+ const fields = {};
68460
+ for (const target of targets) {
68461
+ for (const [key, value] of Object.entries(target)) {
68462
+ if (!fields[key]) {
68463
+ fields[key] = [];
68464
+ }
68465
+ fields[key].push(value);
68466
+ }
68467
+ }
68468
+ return Object.fromEntries(
68469
+ Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
68470
+ );
68471
+ }
68472
+ function convertValue(config4, val) {
68473
+ let value;
68474
+ let kind;
68475
+ if (val.kind === graphql7.Kind.INT) {
68476
+ value = parseInt(val.value, 10);
68477
+ kind = "Int";
68478
+ } else if (val.kind === graphql7.Kind.FLOAT) {
68479
+ value = parseFloat(val.value);
68480
+ kind = "Float";
68481
+ } else if (val.kind === graphql7.Kind.BOOLEAN) {
68482
+ value = val.value;
68483
+ kind = "Boolean";
68484
+ } else if (val.kind === graphql7.Kind.VARIABLE) {
68485
+ value = val.name.value;
68486
+ kind = "Variable";
68487
+ } else if (val.kind === graphql7.Kind.STRING) {
68488
+ value = val.value;
68489
+ kind = "String";
68490
+ }
68491
+ return { kind, value };
68492
+ }
68493
+
68494
+ // src/codegen/generators/artifacts/operations.ts
68495
+ function operationsByPath(config4, filepath, definition, filterTypes) {
68496
+ if (!definition) {
68497
+ return {};
68498
+ }
68499
+ const pathOperations = {};
68500
+ graphql8.visit(definition, {
68501
+ FragmentSpread(node, _, __, ___, ancestors) {
68502
+ if (!config4.isListFragment(node.name.value)) {
68503
+ return;
68504
+ }
68505
+ const path2 = ancestorKey(ancestors);
68506
+ if (!pathOperations[path2]) {
68507
+ pathOperations[path2] = [];
68508
+ }
68509
+ pathOperations[path2].push(
68510
+ operationObject({
68136
68511
  config: config4,
68137
68512
  filepath,
68138
68513
  listName: config4.listNameFromFragment(node.name.value),
@@ -68281,7 +68656,7 @@ function ancestorKey(ancestors) {
68281
68656
  }
68282
68657
 
68283
68658
  // src/codegen/generators/artifacts/selection.ts
68284
- var graphql12 = __toESM(require_graphql2(), 1);
68659
+ var graphql13 = __toESM(require_graphql2(), 1);
68285
68660
 
68286
68661
  // ../../node_modules/.pnpm/@kitql+helper@0.5.0/node_modules/@kitql/helper/index.mjs
68287
68662
  var config2 = {
@@ -68327,16 +68702,16 @@ async function sleep2(ms) {
68327
68702
  }
68328
68703
 
68329
68704
  // src/codegen/transforms/list.ts
68330
- var graphql10 = __toESM(require_graphql2(), 1);
68705
+ var graphql11 = __toESM(require_graphql2(), 1);
68331
68706
 
68332
68707
  // src/codegen/utils/objectIdentificationSelection.ts
68333
- var graphql8 = __toESM(require_graphql2(), 1);
68708
+ var graphql9 = __toESM(require_graphql2(), 1);
68334
68709
  var objectIdentificationSelection = (config4, type) => {
68335
68710
  return config4.keyFieldsForType(type.name).map((key) => {
68336
68711
  return {
68337
- kind: graphql8.Kind.FIELD,
68712
+ kind: graphql9.Kind.FIELD,
68338
68713
  name: {
68339
- kind: graphql8.Kind.NAME,
68714
+ kind: graphql9.Kind.NAME,
68340
68715
  value: key
68341
68716
  }
68342
68717
  };
@@ -68344,7 +68719,7 @@ var objectIdentificationSelection = (config4, type) => {
68344
68719
  };
68345
68720
 
68346
68721
  // src/codegen/transforms/paginate.ts
68347
- var graphql9 = __toESM(require_graphql2(), 1);
68722
+ var graphql10 = __toESM(require_graphql2(), 1);
68348
68723
  async function paginate(config4, documents) {
68349
68724
  const newDocs = [];
68350
68725
  for (const doc of documents) {
@@ -68377,7 +68752,7 @@ async function paginate(config4, documents) {
68377
68752
  };
68378
68753
  let cursorType = "String";
68379
68754
  let paginationPath = [];
68380
- doc.document = graphql9.visit(doc.document, {
68755
+ doc.document = graphql10.visit(doc.document, {
68381
68756
  Field(node, _, __, ___, ancestors) {
68382
68757
  const paginateDirective = node.directives?.find(
68383
68758
  (directive) => directive.name.value === config4.paginateDirective
@@ -68388,23 +68763,22 @@ async function paginate(config4, documents) {
68388
68763
  paginated = true;
68389
68764
  const fieldTypeFields = parentTypeFromAncestors(config4.schema, doc.filename, ancestors).getFields()[node.name.value];
68390
68765
  const args = new Set(fieldTypeFields.args.map((arg) => arg.name));
68391
- const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
68392
- const specifiedForwards = passedArgs.has("first");
68393
- const specifiedBackwards = passedArgs.has("last");
68394
68766
  cursorType = fieldTypeFields.args?.find((arg) => ["before", "after"].includes(arg.name))?.type?.name || "String";
68395
68767
  flags.after.type = cursorType;
68396
68768
  flags.before.type = cursorType;
68397
- const forwardPagination = !specifiedBackwards && args.has("first") && args.has("after");
68398
- const backwardsPagination = !specifiedForwards && args.has("last") && args.has("before");
68399
- const offsetPagination = !forwardPagination && !backwardsPagination && args.has("offset") && args.has("limit");
68400
- flags.first.enabled = forwardPagination;
68401
- flags.after.enabled = forwardPagination;
68402
- flags.last.enabled = backwardsPagination;
68403
- flags.before.enabled = backwardsPagination;
68769
+ const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
68770
+ const forwards = args.has("first") && args.has("after");
68771
+ const backwards = args.has("last") && args.has("after");
68772
+ const cursorPagination = passedArgs.has("last") || passedArgs.has("first");
68773
+ const offsetPagination = !cursorPagination && args.has("offset") && args.has("limit");
68774
+ flags.first.enabled = forwards;
68775
+ flags.after.enabled = forwards;
68776
+ flags.last.enabled = backwards;
68777
+ flags.before.enabled = backwards;
68404
68778
  flags.offset.enabled = offsetPagination;
68405
68779
  flags.limit.enabled = offsetPagination;
68406
68780
  paginationPath = ancestors.filter(
68407
- (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql9.Kind.FIELD
68781
+ (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql10.Kind.FIELD
68408
68782
  ).concat(node).map((field) => field.alias?.value || field.name.value);
68409
68783
  return {
68410
68784
  ...node,
@@ -68420,12 +68794,8 @@ async function paginate(config4, documents) {
68420
68794
  let fragmentName = "";
68421
68795
  let refetchQueryName = "";
68422
68796
  let nodeQuery = false;
68423
- let refetchUpdate = "append" /* append */;
68424
- if (flags.last.enabled) {
68425
- refetchUpdate = "prepend" /* prepend */;
68426
- }
68427
68797
  let fragment = "";
68428
- doc.document = graphql9.visit(doc.document, {
68798
+ doc.document = graphql10.visit(doc.document, {
68429
68799
  OperationDefinition(node) {
68430
68800
  if (node.operation !== "query") {
68431
68801
  throw new HoudiniError({
@@ -68479,9 +68849,9 @@ async function paginate(config4, documents) {
68479
68849
  directives: [
68480
68850
  ...node.directives || [],
68481
68851
  {
68482
- kind: graphql9.Kind.DIRECTIVE,
68852
+ kind: graphql10.Kind.DIRECTIVE,
68483
68853
  name: {
68484
- kind: graphql9.Kind.NAME,
68854
+ kind: graphql10.Kind.NAME,
68485
68855
  value: config4.argumentsDirective
68486
68856
  }
68487
68857
  }
@@ -68518,42 +68888,40 @@ async function paginate(config4, documents) {
68518
68888
  targetType = fragment;
68519
68889
  }
68520
68890
  }
68891
+ const pageSize = flags.first.defaultValue ?? flags.last.defaultValue ?? flags.limit.defaultValue;
68892
+ const start = flags.after.defaultValue ?? flags.before.defaultValue ?? flags.offset.defaultValue;
68893
+ let direction = "forward";
68894
+ if (flags.before.enabled && flags.after.enabled) {
68895
+ direction = "both";
68896
+ } else if (flags.before.enabled) {
68897
+ direction = "backward";
68898
+ }
68521
68899
  doc.refetch = {
68522
- update: refetchUpdate,
68523
68900
  path: paginationPath,
68524
68901
  method: flags.first.enabled || flags.last.enabled ? "cursor" : "offset",
68525
- pageSize: 0,
68902
+ pageSize,
68526
68903
  embedded: nodeQuery,
68527
68904
  targetType,
68528
68905
  paginated: true,
68529
- direction: flags.last.enabled ? "backwards" : "forward"
68530
- };
68531
- if (flags.first.enabled) {
68532
- doc.refetch.pageSize = flags.first.defaultValue;
68533
- doc.refetch.start = flags.after.defaultValue;
68534
- } else if (flags.last.enabled) {
68535
- doc.refetch.pageSize = flags.last.defaultValue;
68536
- doc.refetch.start = flags.before.defaultValue;
68537
- } else if (flags.limit.enabled) {
68538
- doc.refetch.pageSize = flags.limit.defaultValue;
68539
- doc.refetch.start = flags.offset.defaultValue;
68540
- }
68906
+ direction,
68907
+ start
68908
+ };
68541
68909
  if (!fragment) {
68542
68910
  continue;
68543
68911
  }
68544
68912
  const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
68545
68913
  const fragmentSpreadSelection = [
68546
68914
  {
68547
- kind: graphql9.Kind.FRAGMENT_SPREAD,
68915
+ kind: graphql10.Kind.FRAGMENT_SPREAD,
68548
68916
  name: {
68549
- kind: graphql9.Kind.NAME,
68917
+ kind: graphql10.Kind.NAME,
68550
68918
  value: fragmentName
68551
68919
  },
68552
68920
  directives: [
68553
68921
  {
68554
- kind: graphql9.Kind.DIRECTIVE,
68922
+ kind: graphql10.Kind.DIRECTIVE,
68555
68923
  name: {
68556
- kind: graphql9.Kind.NAME,
68924
+ kind: graphql10.Kind.NAME,
68557
68925
  value: config4.withDirective
68558
68926
  },
68559
68927
  ["arguments"]: paginationArgs.map(
@@ -68581,29 +68949,29 @@ async function paginate(config4, documents) {
68581
68949
  });
68582
68950
  const typeConfig = config4.typeConfig?.[fragment];
68583
68951
  const queryDoc = {
68584
- kind: graphql9.Kind.DOCUMENT,
68952
+ kind: graphql10.Kind.DOCUMENT,
68585
68953
  definitions: [
68586
68954
  {
68587
- kind: graphql9.Kind.OPERATION_DEFINITION,
68955
+ kind: graphql10.Kind.OPERATION_DEFINITION,
68588
68956
  name: {
68589
- kind: graphql9.Kind.NAME,
68957
+ kind: graphql10.Kind.NAME,
68590
68958
  value: refetchQueryName
68591
68959
  },
68592
68960
  operation: "query",
68593
68961
  variableDefinitions: paginationArgs.map(
68594
68962
  (arg) => ({
68595
- kind: graphql9.Kind.VARIABLE_DEFINITION,
68963
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
68596
68964
  type: {
68597
- kind: graphql9.Kind.NAMED_TYPE,
68965
+ kind: graphql10.Kind.NAMED_TYPE,
68598
68966
  name: {
68599
- kind: graphql9.Kind.NAME,
68967
+ kind: graphql10.Kind.NAME,
68600
68968
  value: arg.type
68601
68969
  }
68602
68970
  },
68603
68971
  variable: {
68604
- kind: graphql9.Kind.VARIABLE,
68972
+ kind: graphql10.Kind.VARIABLE,
68605
68973
  name: {
68606
- kind: graphql9.Kind.NAME,
68974
+ kind: graphql10.Kind.NAME,
68607
68975
  value: arg.name
68608
68976
  }
68609
68977
  },
@@ -68615,12 +68983,12 @@ async function paginate(config4, documents) {
68615
68983
  ).concat(
68616
68984
  !nodeQuery ? [] : keys.map(
68617
68985
  (key) => ({
68618
- kind: graphql9.Kind.VARIABLE_DEFINITION,
68986
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
68619
68987
  type: key.type,
68620
68988
  variable: {
68621
- kind: graphql9.Kind.VARIABLE,
68989
+ kind: graphql10.Kind.VARIABLE,
68622
68990
  name: {
68623
- kind: graphql9.Kind.NAME,
68991
+ kind: graphql10.Kind.NAME,
68624
68992
  value: key.name
68625
68993
  }
68626
68994
  }
@@ -68628,42 +68996,42 @@ async function paginate(config4, documents) {
68628
68996
  )
68629
68997
  ),
68630
68998
  selectionSet: {
68631
- kind: graphql9.Kind.SELECTION_SET,
68999
+ kind: graphql10.Kind.SELECTION_SET,
68632
69000
  selections: !nodeQuery ? fragmentSpreadSelection : [
68633
69001
  {
68634
- kind: graphql9.Kind.FIELD,
69002
+ kind: graphql10.Kind.FIELD,
68635
69003
  name: {
68636
- kind: graphql9.Kind.NAME,
69004
+ kind: graphql10.Kind.NAME,
68637
69005
  value: typeConfig?.resolve?.queryField || "node"
68638
69006
  },
68639
69007
  ["arguments"]: keys.map((key) => ({
68640
- kind: graphql9.Kind.ARGUMENT,
69008
+ kind: graphql10.Kind.ARGUMENT,
68641
69009
  name: {
68642
- kind: graphql9.Kind.NAME,
69010
+ kind: graphql10.Kind.NAME,
68643
69011
  value: key.name
68644
69012
  },
68645
69013
  value: {
68646
- kind: graphql9.Kind.VARIABLE,
69014
+ kind: graphql10.Kind.VARIABLE,
68647
69015
  name: {
68648
- kind: graphql9.Kind.NAME,
69016
+ kind: graphql10.Kind.NAME,
68649
69017
  value: key.name
68650
69018
  }
68651
69019
  }
68652
69020
  })),
68653
69021
  selectionSet: {
68654
- kind: graphql9.Kind.SELECTION_SET,
69022
+ kind: graphql10.Kind.SELECTION_SET,
68655
69023
  selections: [
68656
69024
  {
68657
- kind: graphql9.Kind.FIELD,
69025
+ kind: graphql10.Kind.FIELD,
68658
69026
  name: {
68659
- kind: graphql9.Kind.NAME,
69027
+ kind: graphql10.Kind.NAME,
68660
69028
  value: "__typename"
68661
69029
  }
68662
69030
  },
68663
69031
  ...(typeConfig?.keys || ["id"]).map((key) => ({
68664
- kind: graphql9.Kind.FIELD,
69032
+ kind: graphql10.Kind.FIELD,
68665
69033
  name: {
68666
- kind: graphql9.Kind.NAME,
69034
+ kind: graphql10.Kind.NAME,
68667
69035
  value: key
68668
69036
  }
68669
69037
  })),
@@ -68713,27 +69081,21 @@ function replaceArgumentsWithVariables(args, flags) {
68713
69081
  if (flags[name2].defaultValue || !spec.enabled || seenArgs[name2]) {
68714
69082
  continue;
68715
69083
  }
68716
- if (["first", "after"].includes(name2) && flags["before"].enabled) {
68717
- continue;
68718
- }
68719
- if (["last", "before"].includes(name2) && flags["first"].enabled) {
68720
- continue;
68721
- }
68722
69084
  newArgs.push(variableAsArgument(name2));
68723
69085
  }
68724
69086
  return newArgs;
68725
69087
  }
68726
69088
  function variableAsArgument(name2, variable) {
68727
69089
  return {
68728
- kind: graphql9.Kind.ARGUMENT,
69090
+ kind: graphql10.Kind.ARGUMENT,
68729
69091
  name: {
68730
- kind: graphql9.Kind.NAME,
69092
+ kind: graphql10.Kind.NAME,
68731
69093
  value: name2
68732
69094
  },
68733
69095
  value: {
68734
- kind: graphql9.Kind.VARIABLE,
69096
+ kind: graphql10.Kind.VARIABLE,
68735
69097
  name: {
68736
- kind: graphql9.Kind.NAME,
69098
+ kind: graphql10.Kind.NAME,
68737
69099
  value: variable ?? name2
68738
69100
  }
68739
69101
  }
@@ -68741,18 +69103,18 @@ function variableAsArgument(name2, variable) {
68741
69103
  }
68742
69104
  function staticVariableDefinition(name2, type, defaultValue, variableName) {
68743
69105
  return {
68744
- kind: graphql9.Kind.VARIABLE_DEFINITION,
69106
+ kind: graphql10.Kind.VARIABLE_DEFINITION,
68745
69107
  type: {
68746
- kind: graphql9.Kind.NAMED_TYPE,
69108
+ kind: graphql10.Kind.NAMED_TYPE,
68747
69109
  name: {
68748
- kind: graphql9.Kind.NAME,
69110
+ kind: graphql10.Kind.NAME,
68749
69111
  value: type
68750
69112
  }
68751
69113
  },
68752
69114
  variable: {
68753
- kind: graphql9.Kind.VARIABLE,
69115
+ kind: graphql10.Kind.VARIABLE,
68754
69116
  name: {
68755
- kind: graphql9.Kind.NAME,
69117
+ kind: graphql10.Kind.NAME,
68756
69118
  value: variableName ?? name2
68757
69119
  }
68758
69120
  },
@@ -68764,9 +69126,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
68764
69126
  }
68765
69127
  function argumentNode(name2, value) {
68766
69128
  return {
68767
- kind: graphql9.Kind.ARGUMENT,
69129
+ kind: graphql10.Kind.ARGUMENT,
68768
69130
  name: {
68769
- kind: graphql9.Kind.NAME,
69131
+ kind: graphql10.Kind.NAME,
68770
69132
  value: name2
68771
69133
  },
68772
69134
  value: objectNode(value)
@@ -68774,16 +69136,16 @@ function argumentNode(name2, value) {
68774
69136
  }
68775
69137
  function objectNode([type, defaultValue]) {
68776
69138
  const node = {
68777
- kind: graphql9.Kind.OBJECT,
69139
+ kind: graphql10.Kind.OBJECT,
68778
69140
  fields: [
68779
69141
  {
68780
- kind: graphql9.Kind.OBJECT_FIELD,
69142
+ kind: graphql10.Kind.OBJECT_FIELD,
68781
69143
  name: {
68782
- kind: graphql9.Kind.NAME,
69144
+ kind: graphql10.Kind.NAME,
68783
69145
  value: "type"
68784
69146
  },
68785
69147
  value: {
68786
- kind: graphql9.Kind.STRING,
69148
+ kind: graphql10.Kind.STRING,
68787
69149
  value: type
68788
69150
  }
68789
69151
  }
@@ -68791,8 +69153,8 @@ function objectNode([type, defaultValue]) {
68791
69153
  };
68792
69154
  if (defaultValue) {
68793
69155
  node.fields.push({
68794
- kind: graphql9.Kind.OBJECT_FIELD,
68795
- name: { kind: graphql9.Kind.NAME, value: "default" },
69156
+ kind: graphql10.Kind.OBJECT_FIELD,
69157
+ name: { kind: graphql10.Kind.NAME, value: "default" },
68796
69158
  value: {
68797
69159
  kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
68798
69160
  value: defaultValue.toString()
@@ -68803,34 +69165,34 @@ function objectNode([type, defaultValue]) {
68803
69165
  }
68804
69166
  var pageInfoSelection = [
68805
69167
  {
68806
- kind: graphql9.Kind.FIELD,
69168
+ kind: graphql10.Kind.FIELD,
68807
69169
  name: {
68808
- kind: graphql9.Kind.NAME,
69170
+ kind: graphql10.Kind.NAME,
68809
69171
  value: "edges"
68810
69172
  },
68811
69173
  selectionSet: {
68812
- kind: graphql9.Kind.SELECTION_SET,
69174
+ kind: graphql10.Kind.SELECTION_SET,
68813
69175
  selections: [
68814
69176
  {
68815
- kind: graphql9.Kind.FIELD,
69177
+ kind: graphql10.Kind.FIELD,
68816
69178
  name: {
68817
- kind: graphql9.Kind.NAME,
69179
+ kind: graphql10.Kind.NAME,
68818
69180
  value: "cursor"
68819
69181
  }
68820
69182
  },
68821
69183
  {
68822
- kind: graphql9.Kind.FIELD,
69184
+ kind: graphql10.Kind.FIELD,
68823
69185
  name: {
68824
- kind: graphql9.Kind.NAME,
69186
+ kind: graphql10.Kind.NAME,
68825
69187
  value: "node"
68826
69188
  },
68827
69189
  selectionSet: {
68828
- kind: graphql9.Kind.SELECTION_SET,
69190
+ kind: graphql10.Kind.SELECTION_SET,
68829
69191
  selections: [
68830
69192
  {
68831
- kind: graphql9.Kind.FIELD,
69193
+ kind: graphql10.Kind.FIELD,
68832
69194
  name: {
68833
- kind: graphql9.Kind.NAME,
69195
+ kind: graphql10.Kind.NAME,
68834
69196
  value: "__typename"
68835
69197
  }
68836
69198
  }
@@ -68841,39 +69203,39 @@ var pageInfoSelection = [
68841
69203
  }
68842
69204
  },
68843
69205
  {
68844
- kind: graphql9.Kind.FIELD,
69206
+ kind: graphql10.Kind.FIELD,
68845
69207
  name: {
68846
- kind: graphql9.Kind.NAME,
69208
+ kind: graphql10.Kind.NAME,
68847
69209
  value: "pageInfo"
68848
69210
  },
68849
69211
  selectionSet: {
68850
- kind: graphql9.Kind.SELECTION_SET,
69212
+ kind: graphql10.Kind.SELECTION_SET,
68851
69213
  selections: [
68852
69214
  {
68853
- kind: graphql9.Kind.FIELD,
69215
+ kind: graphql10.Kind.FIELD,
68854
69216
  name: {
68855
- kind: graphql9.Kind.NAME,
69217
+ kind: graphql10.Kind.NAME,
68856
69218
  value: "hasPreviousPage"
68857
69219
  }
68858
69220
  },
68859
69221
  {
68860
- kind: graphql9.Kind.FIELD,
69222
+ kind: graphql10.Kind.FIELD,
68861
69223
  name: {
68862
- kind: graphql9.Kind.NAME,
69224
+ kind: graphql10.Kind.NAME,
68863
69225
  value: "hasNextPage"
68864
69226
  }
68865
69227
  },
68866
69228
  {
68867
- kind: graphql9.Kind.FIELD,
69229
+ kind: graphql10.Kind.FIELD,
68868
69230
  name: {
68869
- kind: graphql9.Kind.NAME,
69231
+ kind: graphql10.Kind.NAME,
68870
69232
  value: "startCursor"
68871
69233
  }
68872
69234
  },
68873
69235
  {
68874
- kind: graphql9.Kind.FIELD,
69236
+ kind: graphql10.Kind.FIELD,
68875
69237
  name: {
68876
- kind: graphql9.Kind.NAME,
69238
+ kind: graphql10.Kind.NAME,
68877
69239
  value: "endCursor"
68878
69240
  }
68879
69241
  }
@@ -68887,15 +69249,15 @@ async function addListFragments(config4, documents) {
68887
69249
  const lists = {};
68888
69250
  const errors = [];
68889
69251
  for (const doc of documents) {
68890
- doc.document = graphql10.visit(doc.document, {
69252
+ doc.document = graphql11.visit(doc.document, {
68891
69253
  Directive(node, key, parent, path2, ancestors) {
68892
69254
  if ([config4.listDirective, config4.paginateDirective].includes(node.name.value)) {
68893
69255
  const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
68894
69256
  let error = {
68895
- ...new graphql10.GraphQLError(
69257
+ ...new graphql11.GraphQLError(
68896
69258
  "",
68897
69259
  node,
68898
- new graphql10.Source(""),
69260
+ new graphql11.Source(""),
68899
69261
  node.loc ? [node.loc.start, node.loc.end] : null,
68900
69262
  path2
68901
69263
  ),
@@ -68947,7 +69309,7 @@ async function addListFragments(config4, documents) {
68947
69309
  {
68948
69310
  kind: "Argument",
68949
69311
  name: {
68950
- kind: graphql10.Kind.NAME,
69312
+ kind: graphql11.Kind.NAME,
68951
69313
  value: "connection"
68952
69314
  },
68953
69315
  value: {
@@ -68997,7 +69359,7 @@ async function addListFragments(config4, documents) {
68997
69359
  const validDeletes = [
68998
69360
  ...new Set(
68999
69361
  Object.values(lists).map(({ type }) => {
69000
- if (!(type instanceof graphql10.GraphQLObjectType)) {
69362
+ if (!(type instanceof graphql11.GraphQLObjectType)) {
69001
69363
  return "";
69002
69364
  }
69003
69365
  if (config4.keyFieldsForType(type.name).length !== 1) {
@@ -69011,7 +69373,7 @@ async function addListFragments(config4, documents) {
69011
69373
  return;
69012
69374
  }
69013
69375
  const generatedDoc = {
69014
- kind: graphql10.Kind.DOCUMENT,
69376
+ kind: graphql11.Kind.DOCUMENT,
69015
69377
  definitions: Object.entries(lists).flatMap(
69016
69378
  ([name2, { selection: selection2, type }]) => {
69017
69379
  const schemaType = config4.schema.getType(type.name);
@@ -69019,7 +69381,7 @@ async function addListFragments(config4, documents) {
69019
69381
  throw new HoudiniError({ message: "Lists must have a selection" });
69020
69382
  }
69021
69383
  const fragmentSelection = {
69022
- kind: graphql10.Kind.SELECTION_SET,
69384
+ kind: graphql11.Kind.SELECTION_SET,
69023
69385
  selections: [...selection2.selections]
69024
69386
  };
69025
69387
  if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
@@ -69034,14 +69396,14 @@ async function addListFragments(config4, documents) {
69034
69396
  {
69035
69397
  name: {
69036
69398
  value: config4.listInsertFragment(name2),
69037
- kind: graphql10.Kind.NAME
69399
+ kind: graphql11.Kind.NAME
69038
69400
  },
69039
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
69401
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
69040
69402
  selectionSet: fragmentSelection,
69041
69403
  typeCondition: {
69042
- kind: graphql10.Kind.NAMED_TYPE,
69404
+ kind: graphql11.Kind.NAMED_TYPE,
69043
69405
  name: {
69044
- kind: graphql10.Kind.NAME,
69406
+ kind: graphql11.Kind.NAME,
69045
69407
  value: type.name
69046
69408
  }
69047
69409
  }
@@ -69049,32 +69411,32 @@ async function addListFragments(config4, documents) {
69049
69411
  {
69050
69412
  name: {
69051
69413
  value: config4.listToggleFragment(name2),
69052
- kind: graphql10.Kind.NAME
69414
+ kind: graphql11.Kind.NAME
69053
69415
  },
69054
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
69416
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
69055
69417
  selectionSet: fragmentSelection,
69056
69418
  typeCondition: {
69057
- kind: graphql10.Kind.NAMED_TYPE,
69419
+ kind: graphql11.Kind.NAMED_TYPE,
69058
69420
  name: {
69059
- kind: graphql10.Kind.NAME,
69421
+ kind: graphql11.Kind.NAME,
69060
69422
  value: type.name
69061
69423
  }
69062
69424
  }
69063
69425
  },
69064
69426
  {
69065
- kind: graphql10.Kind.FRAGMENT_DEFINITION,
69427
+ kind: graphql11.Kind.FRAGMENT_DEFINITION,
69066
69428
  name: {
69067
69429
  value: config4.listRemoveFragment(name2),
69068
- kind: graphql10.Kind.NAME
69430
+ kind: graphql11.Kind.NAME
69069
69431
  },
69070
69432
  selectionSet: {
69071
- kind: graphql10.Kind.SELECTION_SET,
69433
+ kind: graphql11.Kind.SELECTION_SET,
69072
69434
  selections: [...objectIdentificationSelection(config4, type)]
69073
69435
  },
69074
69436
  typeCondition: {
69075
- kind: graphql10.Kind.NAMED_TYPE,
69437
+ kind: graphql11.Kind.NAMED_TYPE,
69076
69438
  name: {
69077
- kind: graphql10.Kind.NAME,
69439
+ kind: graphql11.Kind.NAME,
69078
69440
  value: type.name
69079
69441
  }
69080
69442
  }
@@ -69083,14 +69445,14 @@ async function addListFragments(config4, documents) {
69083
69445
  }
69084
69446
  ).concat(
69085
69447
  ...validDeletes.map((typeName) => ({
69086
- kind: graphql10.Kind.DIRECTIVE_DEFINITION,
69448
+ kind: graphql11.Kind.DIRECTIVE_DEFINITION,
69087
69449
  name: {
69088
- kind: graphql10.Kind.NAME,
69450
+ kind: graphql11.Kind.NAME,
69089
69451
  value: config4.listDeleteDirective(typeName)
69090
69452
  },
69091
69453
  locations: [
69092
69454
  {
69093
- kind: graphql10.Kind.NAME,
69455
+ kind: graphql11.Kind.NAME,
69094
69456
  value: "FIELD"
69095
69457
  }
69096
69458
  ],
@@ -69098,8 +69460,8 @@ async function addListFragments(config4, documents) {
69098
69460
  }))
69099
69461
  )
69100
69462
  };
69101
- config4.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql10.print).join("\n\n");
69102
- config4.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql10.print).join("\n\n");
69463
+ config4.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql11.print).join("\n\n");
69464
+ config4.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql11.print).join("\n\n");
69103
69465
  documents.push({
69104
69466
  name: "generated::lists",
69105
69467
  kind: "HoudiniFragment" /* Fragment */,
@@ -69184,11 +69546,11 @@ var nodeNotDefinedMessage = (config4) => `Looks like you are trying to use the $
69184
69546
  For more information, visit this link: ${siteURL}/guides/pagination`;
69185
69547
 
69186
69548
  // src/codegen/generators/artifacts/fieldKey.ts
69187
- var graphql11 = __toESM(require_graphql2(), 1);
69549
+ var graphql12 = __toESM(require_graphql2(), 1);
69188
69550
  function fieldKey(config4, field) {
69189
69551
  const attributeName = field.alias?.value || field.name.value;
69190
- const printed = graphql11.print(field);
69191
- const secondParse = graphql11.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
69552
+ const printed = graphql12.print(field);
69553
+ const secondParse = graphql12.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
69192
69554
  const paginated = !!field.directives?.find(
69193
69555
  (directive) => directive.name.value === config4.paginateDirective
69194
69556
  );
@@ -69226,7 +69588,7 @@ function selection({
69226
69588
  path: path2 = [],
69227
69589
  includeFragments,
69228
69590
  document,
69229
- markEdges
69591
+ inConnection
69230
69592
  }) {
69231
69593
  let object = {};
69232
69594
  const typeMap = {};
@@ -69283,8 +69645,8 @@ function selection({
69283
69645
  const typeConditionName = field.typeCondition.name.value;
69284
69646
  const typeCondition = config4.schema.getType(typeConditionName);
69285
69647
  const possibleTypes = [];
69286
- if (!graphql12.isAbstractType(typeCondition)) {
69287
- } else if (graphql12.isAbstractType(parentType)) {
69648
+ if (!graphql13.isAbstractType(typeCondition)) {
69649
+ } else if (graphql13.isAbstractType(parentType)) {
69288
69650
  const possibleParentTypes = config4.schema.getPossibleTypes(parentType).map((type) => type.name);
69289
69651
  for (const possible of config4.schema.getPossibleTypes(typeCondition)) {
69290
69652
  if (possibleParentTypes.includes(possible.name)) {
@@ -69332,7 +69694,7 @@ function selection({
69332
69694
  } else {
69333
69695
  let typeRef = type.getFields()[field.name.value].type;
69334
69696
  fieldType = getRootType(typeRef);
69335
- nullable = !graphql12.isNonNullType(typeRef);
69697
+ nullable = !graphql13.isNonNullType(typeRef);
69336
69698
  }
69337
69699
  const typeName = fieldType.toString();
69338
69700
  const pathSoFar = path2.concat(attributeName);
@@ -69368,14 +69730,23 @@ function selection({
69368
69730
  (directive) => directive.name.value === config4.paginateDirective
69369
69731
  );
69370
69732
  if (paginated && document.refetch && document.refetch.method === "offset") {
69371
- fieldObj.update = document.refetch.update;
69733
+ fieldObj.updates = ["append" /* append */];
69372
69734
  }
69373
- if (attributeName === "edges" && markEdges && document.refetch) {
69374
- fieldObj.update = document.refetch.update;
69375
- markEdges = "";
69735
+ let continueConnection = inConnection;
69736
+ if ([
69737
+ "edges",
69738
+ "endCursor",
69739
+ "startCursor",
69740
+ "hasNextPage",
69741
+ "hasPreviousPage"
69742
+ ].includes(attributeName) && inConnection && document.refetch) {
69743
+ fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
69744
+ }
69745
+ if (attributeName === "node" && inConnection) {
69746
+ continueConnection = false;
69376
69747
  }
69377
69748
  if (field.selectionSet) {
69378
- const edgesMark = paginated && document.refetch?.method === "cursor" ? document.refetch.update : markEdges;
69749
+ const connectionState = paginated && document.refetch?.method === "cursor" || continueConnection;
69379
69750
  fieldObj.selection = selection({
69380
69751
  config: config4,
69381
69752
  filepath,
@@ -69385,7 +69756,7 @@ function selection({
69385
69756
  path: pathSoFar,
69386
69757
  includeFragments,
69387
69758
  document,
69388
- markEdges: edgesMark
69759
+ inConnection: connectionState
69389
69760
  });
69390
69761
  }
69391
69762
  if (field.arguments?.length && fieldObj.list) {
@@ -69397,7 +69768,7 @@ function selection({
69397
69768
  {}
69398
69769
  );
69399
69770
  }
69400
- if (graphql12.isInterfaceType(fieldType) || graphql12.isUnionType(fieldType)) {
69771
+ if (graphql13.isInterfaceType(fieldType) || graphql13.isUnionType(fieldType)) {
69401
69772
  fieldObj.abstract = true;
69402
69773
  }
69403
69774
  object.fields = {
@@ -69454,7 +69825,7 @@ function artifactGenerator(stats) {
69454
69825
  return async function(config4, docs) {
69455
69826
  const filterTypes = {};
69456
69827
  for (const doc of docs) {
69457
- graphql13.visit(doc.document, {
69828
+ graphql14.visit(doc.document, {
69458
69829
  Directive(node, _, __, ___, ancestors) {
69459
69830
  if (node.name.value !== config4.listDirective) {
69460
69831
  return;
@@ -69513,7 +69884,7 @@ function artifactGenerator(stats) {
69513
69884
  return;
69514
69885
  }
69515
69886
  const usedVariableNames = /* @__PURE__ */ new Set();
69516
- let documentWithoutInternalDirectives = graphql13.visit(document, {
69887
+ let documentWithoutInternalDirectives = graphql14.visit(document, {
69517
69888
  Directive(node) {
69518
69889
  if (config4.isInternalDirective(node)) {
69519
69890
  return null;
@@ -69526,7 +69897,7 @@ function artifactGenerator(stats) {
69526
69897
  }
69527
69898
  }
69528
69899
  });
69529
- let documentWithoutExtraVariables = graphql13.visit(
69900
+ let documentWithoutExtraVariables = graphql14.visit(
69530
69901
  documentWithoutInternalDirectives,
69531
69902
  {
69532
69903
  VariableDefinition(variableDefinitionNode) {
@@ -69537,13 +69908,13 @@ function artifactGenerator(stats) {
69537
69908
  }
69538
69909
  }
69539
69910
  );
69540
- let rawString = graphql13.print(documentWithoutExtraVariables);
69911
+ let rawString = graphql14.print(documentWithoutExtraVariables);
69541
69912
  let docKind = doc.kind;
69542
69913
  const operations = document.definitions.filter(
69543
- ({ kind }) => kind === graphql13.Kind.OPERATION_DEFINITION
69914
+ ({ kind }) => kind === graphql14.Kind.OPERATION_DEFINITION
69544
69915
  );
69545
69916
  const fragments = document.definitions.filter(
69546
- ({ kind }) => kind === graphql13.Kind.FRAGMENT_DEFINITION
69917
+ ({ kind }) => kind === graphql14.Kind.FRAGMENT_DEFINITION
69547
69918
  );
69548
69919
  let rootType = "";
69549
69920
  let selectionSet;
@@ -69576,7 +69947,13 @@ function artifactGenerator(stats) {
69576
69947
  rootType = matchingFragment.typeCondition.name.value;
69577
69948
  selectionSet = matchingFragment.selectionSet;
69578
69949
  }
69579
- const inputs = operations[0]?.variableDefinitions;
69950
+ let inputs = operations[0]?.variableDefinitions;
69951
+ let directive = fragments[0]?.directives?.find(
69952
+ (directive2) => directive2.name.value === config4.argumentsDirective
69953
+ );
69954
+ if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
69955
+ inputs = fragmentArgumentsDefinitions(config4, doc.filename, fragments[0]);
69956
+ }
69580
69957
  const mergedSelection = flattenSelections({
69581
69958
  config: config4,
69582
69959
  filepath: doc.filename,
@@ -69637,7 +70014,7 @@ function artifactGenerator(stats) {
69637
70014
  }
69638
70015
  if (docKind === "HoudiniQuery") {
69639
70016
  const cacheDirective = operations[0].directives?.find(
69640
- (directive) => directive.name.value === config4.cacheDirective
70017
+ (directive2) => directive2.name.value === config4.cacheDirective
69641
70018
  );
69642
70019
  if (cacheDirective) {
69643
70020
  const args = cacheDirective.arguments?.reduce(
@@ -69853,19 +70230,19 @@ async function generatePluginRuntime(config4, plugin) {
69853
70230
  );
69854
70231
  }
69855
70232
 
69856
- // src/codegen/generators/typescript/index.ts
69857
- var recast12 = __toESM(require_main2(), 1);
70233
+ // src/codegen/generators/typescript/documentTypes.ts
70234
+ var recast11 = __toESM(require_main2(), 1);
69858
70235
 
69859
70236
  // src/codegen/generators/typescript/addReferencedInputTypes.ts
69860
- var graphql16 = __toESM(require_graphql2(), 1);
70237
+ var graphql17 = __toESM(require_graphql2(), 1);
69861
70238
  var recast9 = __toESM(require_main2(), 1);
69862
70239
 
69863
70240
  // src/codegen/generators/typescript/typeReference.ts
69864
- var graphql15 = __toESM(require_graphql2(), 1);
70241
+ var graphql16 = __toESM(require_graphql2(), 1);
69865
70242
  var recast8 = __toESM(require_main2(), 1);
69866
70243
 
69867
70244
  // src/codegen/generators/typescript/types.ts
69868
- var graphql14 = __toESM(require_graphql2(), 1);
70245
+ var graphql15 = __toESM(require_graphql2(), 1);
69869
70246
  var recast7 = __toESM(require_main2(), 1);
69870
70247
  var AST7 = recast7.types.builders;
69871
70248
  function readonlyProperty(prop, enable = true) {
@@ -69896,336 +70273,89 @@ function scalarPropertyValue(config4, missingScalars, target) {
69896
70273
  return AST7.tsBooleanKeyword();
69897
70274
  }
69898
70275
  case "ID": {
69899
- return AST7.tsStringKeyword();
69900
- }
69901
- default: {
69902
- if (graphql14.isNonNullType(target) && "ofType" in target) {
69903
- return scalarPropertyValue(
69904
- config4,
69905
- missingScalars,
69906
- target.ofType
69907
- );
69908
- }
69909
- if (config4.scalars?.[target.name]) {
69910
- return AST7.tsTypeReference(AST7.identifier(config4.scalars?.[target.name].type));
69911
- }
69912
- missingScalars.add(target.name);
69913
- return AST7.tsAnyKeyword();
69914
- }
69915
- }
69916
- }
69917
-
69918
- // src/codegen/generators/typescript/typeReference.ts
69919
- var AST8 = recast8.types.builders;
69920
- function tsTypeReference(config4, missingScalars, definition) {
69921
- const { type, wrappers } = unwrapType(config4, definition.type);
69922
- let result;
69923
- if (graphql15.isScalarType(type)) {
69924
- result = scalarPropertyValue(config4, missingScalars, type);
69925
- } else {
69926
- result = AST8.tsTypeReference(AST8.identifier(type.name));
69927
- }
69928
- for (const toWrap of wrappers) {
69929
- if (toWrap === "NonNull" /* NonNull */) {
69930
- continue;
69931
- } else if (toWrap === "Nullable" /* Nullable */) {
69932
- result = nullableField(result, true);
69933
- } else if (toWrap === "List" /* List */) {
69934
- result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
69935
- }
69936
- }
69937
- return result;
69938
- }
69939
-
69940
- // src/codegen/generators/typescript/addReferencedInputTypes.ts
69941
- var AST9 = recast9.types.builders;
69942
- function addReferencedInputTypes(config4, filepath, body, visitedTypes, missingScalars, rootType) {
69943
- const { type } = unwrapType(config4, rootType);
69944
- if (graphql16.isScalarType(type)) {
69945
- return;
69946
- }
69947
- if (visitedTypes.has(type.name)) {
69948
- return;
69949
- }
69950
- if (graphql16.isUnionType(type)) {
69951
- throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
69952
- }
69953
- visitedTypes.add(type.name);
69954
- if (graphql16.isEnumType(type)) {
69955
- ensureImports({
69956
- config: config4,
69957
- body,
69958
- import: [type.name],
69959
- sourceModule: "$houdini/graphql/enums",
69960
- importKind: "type"
69961
- });
69962
- return;
69963
- }
69964
- const members = [];
69965
- for (const field of Object.values(type.getFields())) {
69966
- addReferencedInputTypes(config4, filepath, body, visitedTypes, missingScalars, field.type);
69967
- members.push(
69968
- AST9.tsPropertySignature(
69969
- AST9.identifier(field.name),
69970
- AST9.tsTypeAnnotation(tsTypeReference(config4, missingScalars, field)),
69971
- graphql16.isNullableType(field.type)
69972
- )
69973
- );
69974
- }
69975
- body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
69976
- }
69977
-
69978
- // src/codegen/generators/typescript/imperativeCache.ts
69979
- var graphql17 = __toESM(require_graphql2(), 1);
69980
- var recast10 = __toESM(require_main2(), 1);
69981
- var AST10 = recast10.types.builders;
69982
- async function imperativeCacheTypef(config4, docs) {
69983
- const target = path_exports.join(config4.runtimeDirectory, "generated.d.ts");
69984
- const body = [];
69985
- const declaration = AST10.tsTypeAliasDeclaration(
69986
- AST10.identifier(CacheTypeDefName),
69987
- AST10.tsTypeLiteral([
69988
- AST10.tsPropertySignature(
69989
- AST10.identifier("types"),
69990
- AST10.tsTypeAnnotation(typeDefinitions(config4, body))
69991
- ),
69992
- AST10.tsPropertySignature(
69993
- AST10.identifier("lists"),
69994
- AST10.tsTypeAnnotation(listDefinitions(config4, docs))
69995
- )
69996
- ])
69997
- );
69998
- declaration.declare = true;
69999
- const importRecord = AST10.importDeclaration(
70000
- [AST10.importSpecifier(AST10.identifier("Record"))],
70001
- AST10.stringLiteral("./public/record")
70002
- );
70003
- importRecord.importKind = "type";
70004
- await fs_exports.writeFile(
70005
- target,
70006
- recast10.prettyPrint(
70007
- AST10.program([importRecord, ...body, AST10.exportNamedDeclaration(declaration)])
70008
- ).code
70009
- );
70010
- }
70011
- function typeDefinitions(config4, body) {
70012
- const operationTypes = [config4.schema.getMutationType(), config4.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
70013
- const visitedTypes = /* @__PURE__ */ new Set();
70014
- const types17 = Object.values(config4.schema.getTypeMap()).filter(
70015
- (type) => !graphql17.isAbstractType(type) && !graphql17.isScalarType(type) && !graphql17.isEnumType(type) && !graphql17.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
70016
- );
70017
- return AST10.tsTypeLiteral(
70018
- types17.map((type) => {
70019
- let typeName = type.name;
70020
- if (config4.schema.getQueryType() && config4.schema.getQueryType()?.name === type.name) {
70021
- typeName = "__ROOT__";
70022
- }
70023
- let idFields = AST10.tsNeverKeyword();
70024
- const keys = keyFieldsForType(config4.configFile, type.name);
70025
- if (graphql17.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
70026
- idFields = AST10.tsTypeLiteral(
70027
- keys.map((key) => {
70028
- const fieldType = type.getFields()[key];
70029
- const unwrapped = unwrapType(config4, fieldType.type);
70030
- return AST10.tsPropertySignature(
70031
- AST10.identifier(key),
70032
- AST10.tsTypeAnnotation(
70033
- scalarPropertyValue(config4, /* @__PURE__ */ new Set(), unwrapped.type)
70034
- )
70035
- );
70036
- })
70037
- );
70038
- } else if (typeName === "__ROOT__") {
70039
- idFields = AST10.tsTypeLiteral([]);
70040
- }
70041
- let fields = AST10.tsTypeLiteral([]);
70042
- if (graphql17.isObjectType(type)) {
70043
- fields = AST10.tsTypeLiteral(
70044
- Object.entries(type.getFields()).map(
70045
- ([key, fieldType]) => {
70046
- const unwrapped = unwrapType(config4, fieldType.type);
70047
- let typeOptions = AST10.tsUnionType([]);
70048
- if (graphql17.isScalarType(unwrapped.type)) {
70049
- typeOptions.types.push(
70050
- scalarPropertyValue(config4, /* @__PURE__ */ new Set(), unwrapped.type)
70051
- );
70052
- } else if (graphql17.isEnumType(unwrapped.type)) {
70053
- typeOptions.types.push(
70054
- AST10.tsTypeReference(AST10.identifier(unwrapped.type.name))
70055
- );
70056
- } else if (!graphql17.isAbstractType(unwrapped.type)) {
70057
- typeOptions.types.push(record(unwrapped.type.name));
70058
- } else {
70059
- typeOptions.types.push(
70060
- ...config4.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
70061
- );
70062
- }
70063
- for (const wrapper of unwrapped.wrappers) {
70064
- if (wrapper === "Nullable" /* Nullable */) {
70065
- typeOptions = AST10.tsParenthesizedType(
70066
- AST10.tsUnionType([typeOptions, AST10.tsNullKeyword()])
70067
- );
70068
- } else if (wrapper === "List" /* List */) {
70069
- typeOptions = AST10.tsArrayType(
70070
- AST10.tsParenthesizedType(typeOptions)
70071
- );
70072
- }
70073
- }
70074
- if (typeOptions.type === "TSParenthesizedType") {
70075
- typeOptions = typeOptions.typeAnnotation;
70076
- }
70077
- let args = AST10.tsNeverKeyword();
70078
- if (fieldType.args?.length > 0) {
70079
- args = AST10.tsTypeLiteral(
70080
- fieldType.args.map((arg) => {
70081
- addReferencedInputTypes(
70082
- config4,
70083
- "",
70084
- body,
70085
- visitedTypes,
70086
- /* @__PURE__ */ new Set(),
70087
- arg.type
70088
- );
70089
- const prop = AST10.tsPropertySignature(
70090
- AST10.identifier(arg.name),
70091
- AST10.tsTypeAnnotation(
70092
- tsTypeReference(config4, /* @__PURE__ */ new Set(), arg)
70093
- )
70094
- );
70095
- const unwrapped2 = unwrapType(config4, arg.type);
70096
- prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
70097
- return prop;
70098
- })
70099
- );
70100
- }
70101
- return AST10.tsPropertySignature(
70102
- AST10.identifier(key),
70103
- AST10.tsTypeAnnotation(
70104
- AST10.tsTypeLiteral([
70105
- AST10.tsPropertySignature(
70106
- AST10.identifier("type"),
70107
- AST10.tsTypeAnnotation(typeOptions)
70108
- ),
70109
- AST10.tsPropertySignature(
70110
- AST10.identifier("args"),
70111
- AST10.tsTypeAnnotation(args)
70112
- )
70113
- ])
70114
- )
70115
- );
70116
- }
70117
- )
70276
+ return AST7.tsStringKeyword();
70277
+ }
70278
+ default: {
70279
+ if (graphql15.isNonNullType(target) && "ofType" in target) {
70280
+ return scalarPropertyValue(
70281
+ config4,
70282
+ missingScalars,
70283
+ target.ofType
70118
70284
  );
70119
70285
  }
70120
- return AST10.tsPropertySignature(
70121
- AST10.identifier(typeName),
70122
- AST10.tsTypeAnnotation(
70123
- AST10.tsTypeLiteral([
70124
- AST10.tsPropertySignature(
70125
- AST10.identifier("idFields"),
70126
- AST10.tsTypeAnnotation(idFields)
70127
- ),
70128
- AST10.tsPropertySignature(
70129
- AST10.identifier("fields"),
70130
- AST10.tsTypeAnnotation(fields)
70131
- )
70132
- ])
70133
- )
70134
- );
70135
- })
70136
- );
70137
- }
70138
- function listDefinitions(config4, docs) {
70139
- const lists = [];
70140
- const visitedLists = /* @__PURE__ */ new Set();
70141
- for (const doc of docs) {
70142
- graphql17.visit(doc.document, {
70143
- Directive(node, key, parent, path2, ancestors) {
70144
- if (![config4.listDirective, config4.paginateDirective].includes(node.name.value)) {
70145
- return;
70146
- }
70147
- const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
70148
- const nameValue = nameArg?.value?.value || "";
70149
- if (!nameValue || visitedLists.has(nameValue)) {
70150
- return;
70151
- }
70152
- visitedLists.add(nameValue);
70153
- const parentType = parentTypeFromAncestors(
70154
- config4.schema,
70155
- doc.filename,
70156
- ancestors.slice(0, -1)
70157
- );
70158
- const targetField = ancestors[ancestors.length - 1];
70159
- const targetFieldDefinition = parentType.getFields()[targetField.name.value];
70160
- const { type: listType } = unwrapType(config4, targetFieldDefinition.type);
70161
- const possibleTypes = [];
70162
- if (graphql17.isAbstractType(listType)) {
70163
- possibleTypes.push(
70164
- ...config4.schema.getPossibleTypes(listType).map((possible) => possible.name)
70165
- );
70166
- } else {
70167
- possibleTypes.push(listType.name);
70168
- }
70169
- lists.push(
70170
- AST10.tsPropertySignature(
70171
- AST10.identifier(nameValue),
70172
- AST10.tsTypeAnnotation(
70173
- AST10.tsTypeLiteral([
70174
- AST10.tsPropertySignature(
70175
- AST10.identifier("types"),
70176
- AST10.tsTypeAnnotation(
70177
- AST10.tsUnionType(
70178
- possibleTypes.map(
70179
- (possible) => AST10.tsLiteralType(AST10.stringLiteral(possible))
70180
- )
70181
- )
70182
- )
70183
- ),
70184
- AST10.tsPropertySignature(
70185
- AST10.identifier("filters"),
70186
- AST10.tsTypeAnnotation(
70187
- targetFieldDefinition.args.length === 0 ? AST10.tsNeverKeyword() : AST10.tsTypeLiteral(
70188
- targetFieldDefinition.args.map((arg) => {
70189
- const argDef = AST10.tsPropertySignature(
70190
- AST10.identifier(arg.name),
70191
- AST10.tsTypeAnnotation(
70192
- tsTypeReference(
70193
- config4,
70194
- /* @__PURE__ */ new Set(),
70195
- arg
70196
- )
70197
- )
70198
- );
70199
- argDef.optional = true;
70200
- return argDef;
70201
- })
70202
- )
70203
- )
70204
- )
70205
- ])
70206
- )
70207
- )
70208
- );
70286
+ if (config4.scalars?.[target.name]) {
70287
+ return AST7.tsTypeReference(AST7.identifier(config4.scalars?.[target.name].type));
70209
70288
  }
70210
- });
70289
+ missingScalars.add(target.name);
70290
+ return AST7.tsAnyKeyword();
70291
+ }
70211
70292
  }
70212
- return AST10.tsTypeLiteral(lists);
70213
70293
  }
70214
- var CacheTypeDefName = "CacheTypeDef";
70215
- function record(name2) {
70216
- return AST10.tsTypeReference(
70217
- AST10.identifier("Record"),
70218
- AST10.tsTypeParameterInstantiation([
70219
- AST10.tsTypeReference(AST10.identifier(CacheTypeDefName)),
70220
- AST10.tsLiteralType(AST10.stringLiteral(name2))
70221
- ])
70222
- );
70294
+
70295
+ // src/codegen/generators/typescript/typeReference.ts
70296
+ var AST8 = recast8.types.builders;
70297
+ function tsTypeReference(config4, missingScalars, definition) {
70298
+ const { type, wrappers } = unwrapType(config4, definition.type);
70299
+ let result;
70300
+ if (graphql16.isScalarType(type)) {
70301
+ result = scalarPropertyValue(config4, missingScalars, type);
70302
+ } else {
70303
+ result = AST8.tsTypeReference(AST8.identifier(type.name));
70304
+ }
70305
+ for (const toWrap of wrappers) {
70306
+ if (toWrap === "NonNull" /* NonNull */) {
70307
+ continue;
70308
+ } else if (toWrap === "Nullable" /* Nullable */) {
70309
+ result = nullableField(result, true);
70310
+ } else if (toWrap === "List" /* List */) {
70311
+ result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
70312
+ }
70313
+ }
70314
+ return result;
70315
+ }
70316
+
70317
+ // src/codegen/generators/typescript/addReferencedInputTypes.ts
70318
+ var AST9 = recast9.types.builders;
70319
+ function addReferencedInputTypes(config4, filepath, body, visitedTypes, missingScalars, rootType) {
70320
+ const { type } = unwrapType(config4, rootType);
70321
+ if (graphql17.isScalarType(type)) {
70322
+ return;
70323
+ }
70324
+ if (visitedTypes.has(type.name)) {
70325
+ return;
70326
+ }
70327
+ if (graphql17.isUnionType(type)) {
70328
+ throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
70329
+ }
70330
+ visitedTypes.add(type.name);
70331
+ if (graphql17.isEnumType(type)) {
70332
+ ensureImports({
70333
+ config: config4,
70334
+ body,
70335
+ import: [type.name],
70336
+ sourceModule: "$houdini/graphql/enums",
70337
+ importKind: "type"
70338
+ });
70339
+ return;
70340
+ }
70341
+ const members = [];
70342
+ for (const field of Object.values(type.getFields())) {
70343
+ addReferencedInputTypes(config4, filepath, body, visitedTypes, missingScalars, field.type);
70344
+ members.push(
70345
+ AST9.tsPropertySignature(
70346
+ AST9.identifier(field.name),
70347
+ AST9.tsTypeAnnotation(tsTypeReference(config4, missingScalars, field)),
70348
+ graphql17.isNullableType(field.type)
70349
+ )
70350
+ );
70351
+ }
70352
+ body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
70223
70353
  }
70224
70354
 
70225
70355
  // src/codegen/generators/typescript/inlineType.ts
70226
70356
  var graphql18 = __toESM(require_graphql2(), 1);
70227
- var recast11 = __toESM(require_main2(), 1);
70228
- var AST11 = recast11.types.builders;
70357
+ var recast10 = __toESM(require_main2(), 1);
70358
+ var AST10 = recast10.types.builders;
70229
70359
  var fragmentKey = "$fragments";
70230
70360
  function inlineType({
70231
70361
  config: config4,
@@ -70254,7 +70384,7 @@ function inlineType({
70254
70384
  });
70255
70385
  visitedTypes.add(type.name);
70256
70386
  }
70257
- result = AST11.tsTypeReference(AST11.identifier(type.name));
70387
+ result = AST10.tsTypeReference(AST10.identifier(type.name));
70258
70388
  } else if (selections) {
70259
70389
  const rootObj = type;
70260
70390
  const inlineFragments = {};
@@ -70305,7 +70435,7 @@ function inlineType({
70305
70435
  selectedFields.push(selection2);
70306
70436
  }
70307
70437
  }
70308
- result = AST11.tsTypeLiteral([
70438
+ result = AST10.tsTypeLiteral([
70309
70439
  ...(selectedFields || []).filter(
70310
70440
  (field) => field.kind === "Field"
70311
70441
  ).map((selection2) => {
@@ -70325,9 +70455,9 @@ function inlineType({
70325
70455
  allOptional
70326
70456
  });
70327
70457
  const prop = readonlyProperty(
70328
- AST11.tsPropertySignature(
70329
- AST11.identifier(attributeName),
70330
- AST11.tsTypeAnnotation(attributeType)
70458
+ AST10.tsPropertySignature(
70459
+ AST10.identifier(attributeName),
70460
+ AST10.tsTypeAnnotation(attributeType)
70331
70461
  ),
70332
70462
  allowReadonly
70333
70463
  );
@@ -70341,15 +70471,15 @@ function inlineType({
70341
70471
  if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
70342
70472
  result.members.push(
70343
70473
  readonlyProperty(
70344
- AST11.tsPropertySignature(
70345
- AST11.identifier(fragmentKey),
70346
- AST11.tsTypeAnnotation(
70347
- AST11.tsTypeLiteral(
70474
+ AST10.tsPropertySignature(
70475
+ AST10.identifier(fragmentKey),
70476
+ AST10.tsTypeAnnotation(
70477
+ AST10.tsTypeLiteral(
70348
70478
  (fragmentSpreads || []).map(
70349
- (fragmentSpread) => AST11.tsPropertySignature(
70350
- AST11.identifier(fragmentSpread.name.value),
70351
- AST11.tsTypeAnnotation(
70352
- AST11.tsLiteralType(AST11.booleanLiteral(true))
70479
+ (fragmentSpread) => AST10.tsPropertySignature(
70480
+ AST10.identifier(fragmentSpread.name.value),
70481
+ AST10.tsTypeAnnotation(
70482
+ AST10.tsLiteralType(AST10.booleanLiteral(true))
70353
70483
  )
70354
70484
  )
70355
70485
  )
@@ -70395,9 +70525,9 @@ function inlineType({
70395
70525
  }
70396
70526
  objectType.members.push(
70397
70527
  readonlyProperty(
70398
- AST11.tsPropertySignature(
70399
- AST11.identifier("__typename"),
70400
- AST11.tsTypeAnnotation(AST11.tsLiteralType(AST11.stringLiteral(typeName)))
70528
+ AST10.tsPropertySignature(
70529
+ AST10.identifier("__typename"),
70530
+ AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
70401
70531
  ),
70402
70532
  allowReadonly
70403
70533
  )
@@ -70408,8 +70538,8 @@ function inlineType({
70408
70538
  if (Object.keys(inlineFragmentSelections).length > 0) {
70409
70539
  let selectionTypes = Object.entries(inlineFragmentSelections).map(
70410
70540
  ([typeName, { type: type2, tsType }]) => {
70411
- return AST11.tsParenthesizedType(
70412
- AST11.tsIntersectionType(
70541
+ return AST10.tsParenthesizedType(
70542
+ AST10.tsIntersectionType(
70413
70543
  [tsType].flatMap((type3) => {
70414
70544
  if (type3.type === "TSUnionType") {
70415
70545
  return type3.types.filter(
@@ -70422,9 +70552,9 @@ function inlineType({
70422
70552
  );
70423
70553
  }
70424
70554
  );
70425
- result = AST11.tsIntersectionType([
70555
+ result = AST10.tsIntersectionType([
70426
70556
  result,
70427
- AST11.tsParenthesizedType(AST11.tsUnionType(selectionTypes))
70557
+ AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
70428
70558
  ]);
70429
70559
  }
70430
70560
  } else {
@@ -70436,7 +70566,7 @@ function inlineType({
70436
70566
  } else if (toWrap === "NonNull" /* NonNull */) {
70437
70567
  continue;
70438
70568
  } else if (toWrap === "List" /* List */) {
70439
- result = AST11.tsArrayType(AST11.tsParenthesizedType(result));
70569
+ result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
70440
70570
  }
70441
70571
  }
70442
70572
  return result;
@@ -70480,9 +70610,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
70480
70610
  return { field, type: selectionType };
70481
70611
  }
70482
70612
 
70483
- // src/codegen/generators/typescript/index.ts
70484
- var AST12 = recast12.types.builders;
70485
- async function typescriptGenerator(config4, docs) {
70613
+ // src/codegen/generators/typescript/documentTypes.ts
70614
+ var AST11 = recast11.types.builders;
70615
+ async function generateDocumentTypes(config4, docs) {
70486
70616
  const typePaths = [];
70487
70617
  const fragmentDefinitions = {};
70488
70618
  for (const document of docs) {
@@ -70499,7 +70629,7 @@ async function typescriptGenerator(config4, docs) {
70499
70629
  return;
70500
70630
  }
70501
70631
  const typeDefPath = config4.artifactTypePath(originalDocument);
70502
- const program = AST12.program([]);
70632
+ const program = AST11.program([]);
70503
70633
  const visitedTypes = /* @__PURE__ */ new Set();
70504
70634
  let definition = originalDocument.definitions.find(
70505
70635
  (def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
@@ -70532,21 +70662,21 @@ async function typescriptGenerator(config4, docs) {
70532
70662
  missingScalars
70533
70663
  );
70534
70664
  }
70535
- await fs_exports.writeFile(typeDefPath, recast12.print(program).code);
70665
+ await fs_exports.writeFile(typeDefPath, recast11.print(program).code);
70536
70666
  typePaths.push(typeDefPath);
70537
70667
  })
70538
70668
  );
70539
- const typeIndex = AST12.program(
70669
+ const typeIndex = AST11.program(
70540
70670
  typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
70541
- return AST12.exportAllDeclaration(
70542
- AST12.literal(
70671
+ return AST11.exportAllDeclaration(
70672
+ AST11.literal(
70543
70673
  "./" + path_exports.relative(path_exports.resolve(config4.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
70544
70674
  ),
70545
70675
  null
70546
70676
  );
70547
70677
  }).concat([
70548
- AST12.exportAllDeclaration(AST12.literal("./runtime"), null),
70549
- AST12.exportAllDeclaration(AST12.literal("./graphql"), null)
70678
+ AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
70679
+ AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
70550
70680
  ])
70551
70681
  );
70552
70682
  const export_default_as = ({ module: module2, as }) => `
@@ -70555,7 +70685,7 @@ export { default as ${as} } from "${module2}"
70555
70685
  const export_star_from = ({ module: module2 }) => `
70556
70686
  export * from "${module2}"
70557
70687
  `;
70558
- let indexContent = recast12.print(typeIndex).code;
70688
+ let indexContent = recast11.print(typeIndex).code;
70559
70689
  for (const plugin of config4.plugins) {
70560
70690
  if (!plugin.index_file) {
70561
70691
  continue;
@@ -70576,7 +70706,6 @@ export * from "${module2}"
70576
70706
  }
70577
70707
  }
70578
70708
  await fs_exports.writeFile(config4.typeIndexPath, indexContent);
70579
- await imperativeCacheTypef(config4, docs);
70580
70709
  if (missingScalars.size > 0) {
70581
70710
  console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
70582
70711
  ", "
@@ -70618,23 +70747,23 @@ async function generateOperationTypeDefs(config4, filepath, body, definition, se
70618
70747
  const optimisticTypeName = `${definition.name.value}$optimistic`;
70619
70748
  const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
70620
70749
  body.push(
70621
- AST12.exportNamedDeclaration(
70622
- AST12.tsTypeAliasDeclaration(
70623
- AST12.identifier(definition.name.value),
70624
- AST12.tsTypeLiteral([
70750
+ AST11.exportNamedDeclaration(
70751
+ AST11.tsTypeAliasDeclaration(
70752
+ AST11.identifier(definition.name.value),
70753
+ AST11.tsTypeLiteral([
70625
70754
  readonlyProperty(
70626
- AST12.tsPropertySignature(
70627
- AST12.stringLiteral("input"),
70628
- AST12.tsTypeAnnotation(AST12.tsTypeReference(AST12.identifier(inputTypeName)))
70755
+ AST11.tsPropertySignature(
70756
+ AST11.stringLiteral("input"),
70757
+ AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
70629
70758
  )
70630
70759
  ),
70631
70760
  readonlyProperty(
70632
- AST12.tsPropertySignature(
70633
- AST12.stringLiteral("result"),
70634
- AST12.tsTypeAnnotation(
70635
- definition.operation === "mutation" ? AST12.tsTypeReference(AST12.identifier(shapeTypeName)) : AST12.tsUnionType([
70636
- AST12.tsTypeReference(AST12.identifier(shapeTypeName)),
70637
- AST12.tsUndefinedKeyword()
70761
+ AST11.tsPropertySignature(
70762
+ AST11.stringLiteral("result"),
70763
+ AST11.tsTypeAnnotation(
70764
+ definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
70765
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
70766
+ AST11.tsUndefinedKeyword()
70638
70767
  ])
70639
70768
  )
70640
70769
  )
@@ -70642,9 +70771,9 @@ async function generateOperationTypeDefs(config4, filepath, body, definition, se
70642
70771
  ])
70643
70772
  )
70644
70773
  ),
70645
- AST12.exportNamedDeclaration(
70646
- AST12.tsTypeAliasDeclaration(
70647
- AST12.identifier(shapeTypeName),
70774
+ AST11.exportNamedDeclaration(
70775
+ AST11.tsTypeAliasDeclaration(
70776
+ AST11.identifier(shapeTypeName),
70648
70777
  inlineType({
70649
70778
  config: config4,
70650
70779
  filepath,
@@ -70672,15 +70801,15 @@ async function generateOperationTypeDefs(config4, filepath, body, definition, se
70672
70801
  );
70673
70802
  }
70674
70803
  body.push(
70675
- AST12.exportNamedDeclaration(
70676
- AST12.tsTypeAliasDeclaration(
70677
- AST12.identifier(inputTypeName),
70678
- AST12.tsTypeLiteral(
70804
+ AST11.exportNamedDeclaration(
70805
+ AST11.tsTypeAliasDeclaration(
70806
+ AST11.identifier(inputTypeName),
70807
+ AST11.tsTypeLiteral(
70679
70808
  (definition.variableDefinitions || []).map(
70680
70809
  (definition2) => {
70681
- return AST12.tsPropertySignature(
70682
- AST12.identifier(definition2.variable.name.value),
70683
- AST12.tsTypeAnnotation(
70810
+ return AST11.tsPropertySignature(
70811
+ AST11.identifier(definition2.variable.name.value),
70812
+ AST11.tsTypeAnnotation(
70684
70813
  tsTypeReference(config4, missingScalars, definition2)
70685
70814
  ),
70686
70815
  definition2.type.kind !== "NonNullType"
@@ -70693,16 +70822,16 @@ async function generateOperationTypeDefs(config4, filepath, body, definition, se
70693
70822
  );
70694
70823
  } else {
70695
70824
  body.push(
70696
- AST12.exportNamedDeclaration(
70697
- AST12.tsTypeAliasDeclaration(AST12.identifier(inputTypeName), AST12.tsNullKeyword())
70825
+ AST11.exportNamedDeclaration(
70826
+ AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
70698
70827
  )
70699
70828
  );
70700
70829
  }
70701
70830
  if (definition.operation === "mutation") {
70702
70831
  body.push(
70703
- AST12.exportNamedDeclaration(
70704
- AST12.tsTypeAliasDeclaration(
70705
- AST12.identifier(optimisticTypeName),
70832
+ AST11.exportNamedDeclaration(
70833
+ AST11.tsTypeAliasDeclaration(
70834
+ AST11.identifier(optimisticTypeName),
70706
70835
  inlineType({
70707
70836
  config: config4,
70708
70837
  filepath,
@@ -70728,65 +70857,463 @@ async function generateFragmentTypeDefs(config4, filepath, body, selections, def
70728
70857
  }
70729
70858
  const propTypeName = definition.name.value;
70730
70859
  const shapeTypeName = `${definition.name.value}$data`;
70860
+ const inputTypeName = `${definition.name.value}$input`;
70731
70861
  const type = config4.schema.getType(definition.typeCondition.name.value);
70732
70862
  if (!type) {
70733
70863
  throw new Error("Should not get here");
70734
70864
  }
70865
+ let extraExports = [];
70866
+ let directive = definition.directives?.find(
70867
+ (directive2) => directive2.name.value === config4.argumentsDirective
70868
+ );
70869
+ if (directive) {
70870
+ extraExports.push(
70871
+ AST11.exportNamedDeclaration(
70872
+ AST11.tsTypeAliasDeclaration(
70873
+ AST11.identifier(inputTypeName),
70874
+ AST11.tsTypeLiteral(
70875
+ (fragmentArgumentsDefinitions(config4, filepath, definition) || []).map(
70876
+ (definition2) => {
70877
+ return AST11.tsPropertySignature(
70878
+ AST11.identifier(definition2.variable.name.value),
70879
+ AST11.tsTypeAnnotation(
70880
+ tsTypeReference(config4, missingScalars, definition2)
70881
+ ),
70882
+ definition2.type.kind !== "NonNullType"
70883
+ );
70884
+ }
70885
+ )
70886
+ )
70887
+ )
70888
+ )
70889
+ );
70890
+ }
70735
70891
  body.push(
70736
- AST12.exportNamedDeclaration(
70737
- AST12.tsTypeAliasDeclaration(
70738
- AST12.identifier(propTypeName),
70739
- AST12.tsTypeLiteral([
70892
+ ...extraExports,
70893
+ AST11.exportNamedDeclaration(
70894
+ AST11.tsTypeAliasDeclaration(
70895
+ AST11.identifier(propTypeName),
70896
+ AST11.tsTypeLiteral([
70740
70897
  readonlyProperty(
70741
- AST12.tsPropertySignature(
70742
- AST12.stringLiteral("shape"),
70743
- AST12.tsTypeAnnotation(
70744
- AST12.tsTypeReference(AST12.identifier(shapeTypeName))
70898
+ AST11.tsPropertySignature(
70899
+ AST11.stringLiteral("shape"),
70900
+ AST11.tsTypeAnnotation(
70901
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName))
70745
70902
  ),
70746
70903
  true
70747
70904
  )
70748
70905
  ),
70749
70906
  readonlyProperty(
70750
- AST12.tsPropertySignature(
70751
- AST12.stringLiteral(fragmentKey),
70907
+ AST11.tsPropertySignature(
70908
+ AST11.stringLiteral(fragmentKey),
70909
+ AST11.tsTypeAnnotation(
70910
+ AST11.tsTypeLiteral([
70911
+ AST11.tsPropertySignature(
70912
+ AST11.stringLiteral(propTypeName),
70913
+ AST11.tsTypeAnnotation(
70914
+ AST11.tsLiteralType(AST11.booleanLiteral(true))
70915
+ )
70916
+ )
70917
+ ])
70918
+ )
70919
+ )
70920
+ )
70921
+ ])
70922
+ )
70923
+ ),
70924
+ AST11.exportNamedDeclaration(
70925
+ AST11.tsTypeAliasDeclaration(
70926
+ AST11.identifier(shapeTypeName),
70927
+ inlineType({
70928
+ config: config4,
70929
+ filepath,
70930
+ rootType: type,
70931
+ selections,
70932
+ root: true,
70933
+ allowReadonly: true,
70934
+ body,
70935
+ visitedTypes,
70936
+ missingScalars,
70937
+ includeFragments: true
70938
+ })
70939
+ )
70940
+ )
70941
+ );
70942
+ }
70943
+ }
70944
+
70945
+ // src/codegen/generators/typescript/imperativeTypeDef.ts
70946
+ var graphql19 = __toESM(require_graphql2(), 1);
70947
+ var recast12 = __toESM(require_main2(), 1);
70948
+ var AST12 = recast12.types.builders;
70949
+ async function imperativeCacheTypef(config4, docs) {
70950
+ const returnType = (doc) => config4.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
70951
+ config: config4,
70952
+ doc,
70953
+ ensure_import({ identifier, module: module2 }) {
70954
+ ensureImports({
70955
+ config: config4,
70956
+ body,
70957
+ sourceModule: module2,
70958
+ import: [identifier]
70959
+ });
70960
+ }
70961
+ }) ?? "any";
70962
+ const target = path_exports.join(config4.runtimeDirectory, "generated.d.ts");
70963
+ const body = [];
70964
+ const declaration = AST12.tsTypeAliasDeclaration(
70965
+ AST12.identifier(CacheTypeDefName),
70966
+ AST12.tsTypeLiteral([
70967
+ AST12.tsPropertySignature(
70968
+ AST12.identifier("types"),
70969
+ AST12.tsTypeAnnotation(typeDefinitions(config4, body, docs, returnType))
70970
+ ),
70971
+ AST12.tsPropertySignature(
70972
+ AST12.identifier("lists"),
70973
+ AST12.tsTypeAnnotation(listDefinitions(config4, docs))
70974
+ ),
70975
+ AST12.tsPropertySignature(
70976
+ AST12.identifier("queries"),
70977
+ AST12.tsTypeAnnotation(queryDefinitions(config4, body, docs, returnType))
70978
+ )
70979
+ ])
70980
+ );
70981
+ declaration.declare = true;
70982
+ const importRecord = AST12.importDeclaration(
70983
+ [AST12.importSpecifier(AST12.identifier("Record"))],
70984
+ AST12.stringLiteral("./public/record")
70985
+ );
70986
+ importRecord.importKind = "type";
70987
+ await fs_exports.writeFile(
70988
+ target,
70989
+ recast12.prettyPrint(
70990
+ AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
70991
+ ).code
70992
+ );
70993
+ }
70994
+ function typeDefinitions(config4, body, docs, returnType) {
70995
+ const operationTypes = [config4.schema.getMutationType(), config4.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
70996
+ const visitedTypes = /* @__PURE__ */ new Set();
70997
+ const types17 = Object.values(config4.schema.getTypeMap()).filter(
70998
+ (type) => !graphql19.isAbstractType(type) && !graphql19.isScalarType(type) && !graphql19.isEnumType(type) && !graphql19.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
70999
+ );
71000
+ const fragmentMap = fragmentListMap(
71001
+ config4,
71002
+ types17.map((type) => type.name),
71003
+ body,
71004
+ docs,
71005
+ returnType
71006
+ );
71007
+ return AST12.tsTypeLiteral(
71008
+ types17.map((type) => {
71009
+ let typeName = type.name;
71010
+ if (config4.schema.getQueryType() && config4.schema.getQueryType()?.name === type.name) {
71011
+ typeName = "__ROOT__";
71012
+ }
71013
+ let idFields = AST12.tsNeverKeyword();
71014
+ const keys = keyFieldsForType(config4.configFile, type.name);
71015
+ if (graphql19.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
71016
+ idFields = AST12.tsTypeLiteral(
71017
+ keys.map((key) => {
71018
+ const fieldType = type.getFields()[key];
71019
+ const unwrapped = unwrapType(config4, fieldType.type);
71020
+ return AST12.tsPropertySignature(
71021
+ AST12.identifier(key),
71022
+ AST12.tsTypeAnnotation(
71023
+ scalarPropertyValue(config4, /* @__PURE__ */ new Set(), unwrapped.type)
71024
+ )
71025
+ );
71026
+ })
71027
+ );
71028
+ } else if (typeName === "__ROOT__") {
71029
+ idFields = AST12.tsTypeLiteral([]);
71030
+ }
71031
+ let fields = AST12.tsTypeLiteral([]);
71032
+ if (graphql19.isObjectType(type)) {
71033
+ fields = AST12.tsTypeLiteral(
71034
+ Object.entries(type.getFields()).map(
71035
+ ([key, fieldType]) => {
71036
+ const unwrapped = unwrapType(config4, fieldType.type);
71037
+ let typeOptions = AST12.tsUnionType([]);
71038
+ if (graphql19.isScalarType(unwrapped.type)) {
71039
+ typeOptions.types.push(
71040
+ scalarPropertyValue(config4, /* @__PURE__ */ new Set(), unwrapped.type)
71041
+ );
71042
+ } else if (graphql19.isEnumType(unwrapped.type)) {
71043
+ typeOptions.types.push(
71044
+ AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
71045
+ );
71046
+ } else if (!graphql19.isAbstractType(unwrapped.type)) {
71047
+ typeOptions.types.push(record(unwrapped.type.name));
71048
+ } else {
71049
+ typeOptions.types.push(
71050
+ ...config4.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
71051
+ );
71052
+ }
71053
+ for (const wrapper of unwrapped.wrappers) {
71054
+ if (wrapper === "Nullable" /* Nullable */) {
71055
+ typeOptions = AST12.tsParenthesizedType(
71056
+ AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
71057
+ );
71058
+ } else if (wrapper === "List" /* List */) {
71059
+ typeOptions = AST12.tsArrayType(
71060
+ AST12.tsParenthesizedType(typeOptions)
71061
+ );
71062
+ }
71063
+ }
71064
+ if (typeOptions.type === "TSParenthesizedType") {
71065
+ typeOptions = typeOptions.typeAnnotation;
71066
+ }
71067
+ let args = AST12.tsNeverKeyword();
71068
+ if (fieldType.args?.length > 0) {
71069
+ args = AST12.tsTypeLiteral(
71070
+ fieldType.args.map((arg) => {
71071
+ addReferencedInputTypes(
71072
+ config4,
71073
+ "",
71074
+ body,
71075
+ visitedTypes,
71076
+ /* @__PURE__ */ new Set(),
71077
+ arg.type
71078
+ );
71079
+ const prop = AST12.tsPropertySignature(
71080
+ AST12.identifier(arg.name),
71081
+ AST12.tsTypeAnnotation(
71082
+ tsTypeReference(config4, /* @__PURE__ */ new Set(), arg)
71083
+ )
71084
+ );
71085
+ const unwrapped2 = unwrapType(config4, arg.type);
71086
+ prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
71087
+ return prop;
71088
+ })
71089
+ );
71090
+ }
71091
+ return AST12.tsPropertySignature(
71092
+ AST12.identifier(key),
70752
71093
  AST12.tsTypeAnnotation(
70753
71094
  AST12.tsTypeLiteral([
70754
71095
  AST12.tsPropertySignature(
70755
- AST12.stringLiteral(propTypeName),
70756
- AST12.tsTypeAnnotation(
70757
- AST12.tsLiteralType(AST12.booleanLiteral(true))
70758
- )
71096
+ AST12.identifier("type"),
71097
+ AST12.tsTypeAnnotation(typeOptions)
71098
+ ),
71099
+ AST12.tsPropertySignature(
71100
+ AST12.identifier("args"),
71101
+ AST12.tsTypeAnnotation(args)
70759
71102
  )
70760
71103
  ])
70761
71104
  )
70762
- )
71105
+ );
71106
+ }
71107
+ )
71108
+ );
71109
+ }
71110
+ return AST12.tsPropertySignature(
71111
+ AST12.identifier(typeName),
71112
+ AST12.tsTypeAnnotation(
71113
+ AST12.tsTypeLiteral([
71114
+ AST12.tsPropertySignature(
71115
+ AST12.identifier("idFields"),
71116
+ AST12.tsTypeAnnotation(idFields)
71117
+ ),
71118
+ AST12.tsPropertySignature(
71119
+ AST12.identifier("fields"),
71120
+ AST12.tsTypeAnnotation(fields)
71121
+ ),
71122
+ AST12.tsPropertySignature(
71123
+ AST12.identifier("fragments"),
71124
+ AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
70763
71125
  )
70764
71126
  ])
70765
71127
  )
71128
+ );
71129
+ })
71130
+ );
71131
+ }
71132
+ function listDefinitions(config4, docs) {
71133
+ const lists = [];
71134
+ const visitedLists = /* @__PURE__ */ new Set();
71135
+ for (const doc of docs) {
71136
+ graphql19.visit(doc.document, {
71137
+ Directive(node, key, parent, path2, ancestors) {
71138
+ if (![config4.listDirective, config4.paginateDirective].includes(node.name.value)) {
71139
+ return;
71140
+ }
71141
+ const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
71142
+ const nameValue = nameArg?.value?.value || "";
71143
+ if (!nameValue || visitedLists.has(nameValue)) {
71144
+ return;
71145
+ }
71146
+ visitedLists.add(nameValue);
71147
+ const parentType = parentTypeFromAncestors(
71148
+ config4.schema,
71149
+ doc.filename,
71150
+ ancestors.slice(0, -1)
71151
+ );
71152
+ const targetField = ancestors[ancestors.length - 1];
71153
+ const targetFieldDefinition = parentType.getFields()[targetField.name.value];
71154
+ const { type: listType } = unwrapType(config4, targetFieldDefinition.type);
71155
+ const possibleTypes = [];
71156
+ if (graphql19.isAbstractType(listType)) {
71157
+ possibleTypes.push(
71158
+ ...config4.schema.getPossibleTypes(listType).map((possible) => possible.name)
71159
+ );
71160
+ } else {
71161
+ possibleTypes.push(listType.name);
71162
+ }
71163
+ lists.push(
71164
+ AST12.tsPropertySignature(
71165
+ AST12.identifier(nameValue),
71166
+ AST12.tsTypeAnnotation(
71167
+ AST12.tsTypeLiteral([
71168
+ AST12.tsPropertySignature(
71169
+ AST12.identifier("types"),
71170
+ AST12.tsTypeAnnotation(
71171
+ AST12.tsUnionType(
71172
+ possibleTypes.map(
71173
+ (possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
71174
+ )
71175
+ )
71176
+ )
71177
+ ),
71178
+ AST12.tsPropertySignature(
71179
+ AST12.identifier("filters"),
71180
+ AST12.tsTypeAnnotation(
71181
+ targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
71182
+ targetFieldDefinition.args.map((arg) => {
71183
+ const argDef = AST12.tsPropertySignature(
71184
+ AST12.identifier(arg.name),
71185
+ AST12.tsTypeAnnotation(
71186
+ tsTypeReference(
71187
+ config4,
71188
+ /* @__PURE__ */ new Set(),
71189
+ arg
71190
+ )
71191
+ )
71192
+ );
71193
+ argDef.optional = true;
71194
+ return argDef;
71195
+ })
71196
+ )
71197
+ )
71198
+ )
71199
+ ])
71200
+ )
71201
+ )
71202
+ );
71203
+ }
71204
+ });
71205
+ }
71206
+ return AST12.tsTypeLiteral(lists);
71207
+ }
71208
+ function queryDefinitions(config4, body, docs, returnType) {
71209
+ return AST12.tsTupleType(
71210
+ docs.reduce((prev, doc) => {
71211
+ if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
71212
+ return prev;
71213
+ }
71214
+ const definition = doc.document.definitions.find(
71215
+ (def) => def.kind === "OperationDefinition" && def.operation === "query"
71216
+ );
71217
+ if (!definition) {
71218
+ return prev;
71219
+ }
71220
+ const runtimeType = returnType(doc);
71221
+ const [shapeType, inputType] = ensureImports({
71222
+ config: config4,
71223
+ body,
71224
+ sourceModule: path_exports.relative(
71225
+ config4.runtimeDirectory,
71226
+ config4.artifactImportPath(doc.name)
71227
+ ),
71228
+ import: [`${doc.name}$result`, `${doc.name}$input`]
71229
+ });
71230
+ return prev.concat(
71231
+ AST12.tsTupleType([
71232
+ AST12.tsTypeReference(AST12.identifier(runtimeType)),
71233
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
71234
+ AST12.tsTypeReference(AST12.identifier(inputType))
71235
+ ])
71236
+ );
71237
+ }, [])
71238
+ );
71239
+ }
71240
+ function fragmentListMap(config4, concreteTypes, body, docs, return_type) {
71241
+ return docs.reduce((prev, doc) => {
71242
+ if (doc.kind !== "HoudiniFragment" /* Fragment */) {
71243
+ return prev;
71244
+ }
71245
+ const definition = doc.document.definitions.find(
71246
+ (def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
71247
+ );
71248
+ if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
71249
+ return prev;
71250
+ }
71251
+ const typeName = definition.typeCondition.name.value;
71252
+ const previousValue = prev[typeName]?.elementTypes ?? [];
71253
+ const tagResult = return_type(doc);
71254
+ const [shapeType] = ensureImports({
71255
+ config: config4,
71256
+ body,
71257
+ sourceModule: path_exports.relative(
71258
+ config4.runtimeDirectory,
71259
+ config4.artifactImportPath(doc.name)
70766
71260
  ),
70767
- AST12.exportNamedDeclaration(
70768
- AST12.tsTypeAliasDeclaration(
70769
- AST12.identifier(shapeTypeName),
70770
- inlineType({
71261
+ import: [`${definition.name.value}$data`]
71262
+ });
71263
+ let inputType = AST12.tsNeverKeyword();
71264
+ let directive = definition.directives?.find(
71265
+ (directive2) => directive2.name.value === config4.argumentsDirective
71266
+ );
71267
+ if (directive) {
71268
+ inputType = AST12.tsTypeReference(
71269
+ AST12.identifier(
71270
+ ensureImports({
70771
71271
  config: config4,
70772
- filepath,
70773
- rootType: type,
70774
- selections,
70775
- root: true,
70776
- allowReadonly: true,
70777
71272
  body,
70778
- visitedTypes,
70779
- missingScalars,
70780
- includeFragments: true
70781
- })
71273
+ sourceModule: path_exports.relative(
71274
+ config4.runtimeDirectory,
71275
+ config4.artifactImportPath(doc.name)
71276
+ ),
71277
+ import: [`${definition.name.value}$input`]
71278
+ })[0]
71279
+ )
71280
+ );
71281
+ }
71282
+ return {
71283
+ ...prev,
71284
+ [typeName]: AST12.tsTupleType(
71285
+ previousValue.concat(
71286
+ AST12.tsTupleType([
71287
+ AST12.tsTypeReference(AST12.identifier(tagResult)),
71288
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
71289
+ inputType
71290
+ ])
70782
71291
  )
70783
71292
  )
70784
- );
70785
- }
71293
+ };
71294
+ }, {});
71295
+ }
71296
+ var CacheTypeDefName = "CacheTypeDef";
71297
+ function record(name2) {
71298
+ return AST12.tsTypeReference(
71299
+ AST12.identifier("Record"),
71300
+ AST12.tsTypeParameterInstantiation([
71301
+ AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
71302
+ AST12.tsLiteralType(AST12.stringLiteral(name2))
71303
+ ])
71304
+ );
71305
+ }
71306
+
71307
+ // src/codegen/generators/typescript/index.ts
71308
+ async function typescriptGenerator(config4, docs) {
71309
+ await Promise.all([
71310
+ generateDocumentTypes(config4, docs),
71311
+ imperativeCacheTypef(config4, docs)
71312
+ ]);
70786
71313
  }
70787
71314
 
70788
71315
  // src/codegen/generators/persistedQueries/index.ts
70789
- var graphql19 = __toESM(require_graphql2(), 1);
71316
+ var graphql20 = __toESM(require_graphql2(), 1);
70790
71317
  async function persistOutputGenerator(config4, docs) {
70791
71318
  if (typeof config4.persistedQueryPath !== "string" || config4.persistedQueryPath.length === 0)
70792
71319
  return;
@@ -70798,8 +71325,8 @@ async function persistOutputGenerator(config4, docs) {
70798
71325
  if (!generateArtifact) {
70799
71326
  return acc;
70800
71327
  }
70801
- let rawString = graphql19.print(
70802
- graphql19.visit(document, {
71328
+ let rawString = graphql20.print(
71329
+ graphql20.visit(document, {
70803
71330
  Directive(node) {
70804
71331
  if (config4.isInternalDirective(node)) {
70805
71332
  return null;
@@ -70808,7 +71335,7 @@ async function persistOutputGenerator(config4, docs) {
70808
71335
  })
70809
71336
  );
70810
71337
  const operations = document.definitions.filter(
70811
- ({ kind }) => kind === graphql19.Kind.OPERATION_DEFINITION
71338
+ ({ kind }) => kind === graphql20.Kind.OPERATION_DEFINITION
70812
71339
  );
70813
71340
  if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
70814
71341
  acc[hashDocument(rawString)] = rawString;
@@ -70821,11 +71348,11 @@ async function persistOutputGenerator(config4, docs) {
70821
71348
  }
70822
71349
 
70823
71350
  // src/codegen/generators/definitions/enums.ts
70824
- var graphql20 = __toESM(require_graphql2(), 1);
71351
+ var graphql21 = __toESM(require_graphql2(), 1);
70825
71352
  var recast13 = __toESM(require_main2(), 1);
70826
71353
  var AST13 = recast13.types.builders;
70827
71354
  async function definitionsGenerator(config4) {
70828
- const enums = graphql20.parse(graphql20.printSchema(config4.schema)).definitions.filter(
71355
+ const enums = graphql21.parse(graphql21.printSchema(config4.schema)).definitions.filter(
70829
71356
  (definition) => definition.kind === "EnumTypeDefinition"
70830
71357
  ).filter((def) => !config4.isInternalEnum(def));
70831
71358
  const runtimeDefinitions = recast13.print(
@@ -70915,91 +71442,8 @@ async function writeIndexFile2(config4, docs) {
70915
71442
  await fs_exports.writeFile(path_exports.join(config4.rootDir, "index.js"), body);
70916
71443
  }
70917
71444
 
70918
- // src/codegen/transforms/composeQueries.ts
70919
- var import_graphql30 = __toESM(require_graphql2(), 1);
70920
- async function includeFragmentDefinitions(config4, documents) {
70921
- const fragments = collectFragments(config4, documents);
70922
- for (const [index, { name: name2, document, filename }] of documents.entries()) {
70923
- const operation = document.definitions.find(
70924
- ({ kind }) => kind === import_graphql30.Kind.OPERATION_DEFINITION
70925
- );
70926
- if (!operation) {
70927
- continue;
70928
- }
70929
- const allFragments = flattenFragments(
70930
- filename,
70931
- { requiredFragments: findRequiredFragments(operation.selectionSet) },
70932
- fragments
70933
- );
70934
- documents[index].document = {
70935
- ...document,
70936
- definitions: [
70937
- operation,
70938
- ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
70939
- ]
70940
- };
70941
- }
70942
- }
70943
- function collectFragments(config4, docs) {
70944
- return docs.reduce((acc, doc) => {
70945
- const definitions = doc.document.definitions.reduce(
70946
- (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
70947
- ...prev,
70948
- [definition.name.value]: {
70949
- definition,
70950
- requiredFragments: findRequiredFragments(definition.selectionSet),
70951
- document: doc
70952
- }
70953
- },
70954
- {}
70955
- );
70956
- return {
70957
- ...acc,
70958
- ...definitions
70959
- };
70960
- }, {});
70961
- }
70962
- function findRequiredFragments(selectionSet) {
70963
- if (selectionSet.selections.length === 0) {
70964
- return [];
70965
- }
70966
- const referencedFragments = [];
70967
- for (const selection2 of selectionSet.selections) {
70968
- if (selection2.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
70969
- referencedFragments.push(selection2.name.value);
70970
- } else if (selection2.selectionSet) {
70971
- referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
70972
- }
70973
- }
70974
- return referencedFragments;
70975
- }
70976
- function flattenFragments(filepath, operation, fragments) {
70977
- const frags = /* @__PURE__ */ new Set();
70978
- const remaining = [...operation.requiredFragments];
70979
- while (remaining.length > 0) {
70980
- const nextFragment = remaining.shift();
70981
- if (!nextFragment) {
70982
- continue;
70983
- }
70984
- if (!frags.has(nextFragment)) {
70985
- frags.add(nextFragment);
70986
- } else {
70987
- continue;
70988
- }
70989
- const targetFragment = fragments[nextFragment];
70990
- if (!targetFragment) {
70991
- throw new HoudiniError({
70992
- filepath,
70993
- message: "compose: could not find definition for fragment " + nextFragment
70994
- });
70995
- }
70996
- remaining.push(...targetFragment.requiredFragments);
70997
- }
70998
- return [...frags];
70999
- }
71000
-
71001
71445
  // src/codegen/transforms/schema.ts
71002
- var graphql21 = __toESM(require_graphql2(), 1);
71446
+ var graphql22 = __toESM(require_graphql2(), 1);
71003
71447
  async function graphqlExtensions(config4, documents) {
71004
71448
  const internalSchema = `
71005
71449
  enum CachePolicy {
@@ -71063,9 +71507,9 @@ directive @${config4.argumentsDirective} on FRAGMENT_DEFINITION
71063
71507
  directive @${config4.cacheDirective}(${config4.cachePolicyArg}: CachePolicy, ${config4.cachePartialArg}: Boolean) on QUERY
71064
71508
 
71065
71509
  """
71066
- @${config4.manualLoadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
71510
+ @${config4.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
71067
71511
  """
71068
- directive @${config4.manualLoadDirective} on QUERY
71512
+ directive @${config4.loadDirective} on QUERY
71069
71513
 
71070
71514
  """
71071
71515
  @${config4.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
@@ -71077,19 +71521,19 @@ directive @${config4.maskEnableDirective} on FRAGMENT_SPREAD
71077
71521
  """
71078
71522
  directive @${config4.maskDisableDirective} on FRAGMENT_SPREAD
71079
71523
  `;
71080
- let currentSchema = graphql21.printSchema(config4.schema);
71524
+ let currentSchema = graphql22.printSchema(config4.schema);
71081
71525
  if (!currentSchema.includes(`directive @${config4.listDirective}`)) {
71082
71526
  currentSchema += internalSchema;
71083
71527
  }
71084
71528
  config4.newSchema += internalSchema;
71085
- config4.schema = graphql21.buildSchema(currentSchema);
71529
+ config4.schema = graphql22.buildSchema(currentSchema);
71086
71530
  }
71087
71531
 
71088
71532
  // src/codegen/transforms/typename.ts
71089
- var graphql22 = __toESM(require_graphql2(), 1);
71533
+ var graphql23 = __toESM(require_graphql2(), 1);
71090
71534
  async function addTypename(config4, documents) {
71091
71535
  for (const doc of documents) {
71092
- doc.document = graphql22.visit(doc.document, {
71536
+ doc.document = graphql23.visit(doc.document, {
71093
71537
  Field(node, key, parent, path2, ancestors) {
71094
71538
  if (!node.selectionSet) {
71095
71539
  return;
@@ -71101,7 +71545,7 @@ async function addTypename(config4, documents) {
71101
71545
  );
71102
71546
  const field = type.getFields()[node.name.value];
71103
71547
  const fieldType = unwrapType(config4, field.type).type;
71104
- if (graphql22.isInterfaceType(fieldType) || graphql22.isUnionType(fieldType)) {
71548
+ if (graphql23.isInterfaceType(fieldType) || graphql23.isUnionType(fieldType)) {
71105
71549
  return {
71106
71550
  ...node,
71107
71551
  selectionSet: {
@@ -71109,9 +71553,9 @@ async function addTypename(config4, documents) {
71109
71553
  selections: [
71110
71554
  ...node.selectionSet.selections,
71111
71555
  {
71112
- kind: graphql22.Kind.FIELD,
71556
+ kind: graphql23.Kind.FIELD,
71113
71557
  name: {
71114
- kind: graphql22.Kind.NAME,
71558
+ kind: graphql23.Kind.NAME,
71115
71559
  value: "__typename"
71116
71560
  }
71117
71561
  }
@@ -71125,10 +71569,10 @@ async function addTypename(config4, documents) {
71125
71569
  }
71126
71570
 
71127
71571
  // src/codegen/transforms/addID.ts
71128
- var graphql23 = __toESM(require_graphql2(), 1);
71572
+ var graphql24 = __toESM(require_graphql2(), 1);
71129
71573
  async function addID(config4, documents) {
71130
71574
  for (const doc of documents) {
71131
- doc.document = graphql23.visit(doc.document, {
71575
+ doc.document = graphql24.visit(doc.document, {
71132
71576
  Field(node, key, parent, path2, ancestors) {
71133
71577
  if (!node.selectionSet) {
71134
71578
  return;
@@ -71141,7 +71585,7 @@ async function addID(config4, documents) {
71141
71585
  const field = type.getFields()[node.name.value];
71142
71586
  const fieldType = unwrapType(config4, field.type).type;
71143
71587
  if (node.selectionSet?.selections.length > 0) {
71144
- if (!graphql23.isObjectType(fieldType) && !graphql23.isInterfaceType(fieldType)) {
71588
+ if (!graphql24.isObjectType(fieldType) && !graphql24.isInterfaceType(fieldType)) {
71145
71589
  return;
71146
71590
  }
71147
71591
  const keyFields = config4.keyFieldsForType(fieldType.name);
@@ -71156,9 +71600,9 @@ async function addID(config4, documents) {
71156
71600
  continue;
71157
71601
  }
71158
71602
  selections.push({
71159
- kind: graphql23.Kind.FIELD,
71603
+ kind: graphql24.Kind.FIELD,
71160
71604
  name: {
71161
- kind: graphql23.Kind.NAME,
71605
+ kind: graphql24.Kind.NAME,
71162
71606
  value: keyField
71163
71607
  }
71164
71608
  });
@@ -71176,266 +71620,6 @@ async function addID(config4, documents) {
71176
71620
  }
71177
71621
  }
71178
71622
 
71179
- // src/codegen/transforms/fragmentVariables.ts
71180
- var graphql24 = __toESM(require_graphql2(), 1);
71181
- var GraphqlKinds2 = graphql24.Kind;
71182
- async function fragmentVariables(config4, documents) {
71183
- const fragments = collectFragments(config4, documents);
71184
- const generatedFragments = {};
71185
- const visitedFragments = /* @__PURE__ */ new Set();
71186
- for (const doc2 of documents) {
71187
- const operation = doc2.document.definitions.find(
71188
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
71189
- );
71190
- if (!operation) {
71191
- continue;
71192
- }
71193
- doc2.document = inlineFragmentArgs({
71194
- config: config4,
71195
- filepath: doc2.filename,
71196
- fragmentDefinitions: fragments,
71197
- document: doc2.document,
71198
- generatedFragments,
71199
- visitedFragments,
71200
- scope: null
71201
- });
71202
- }
71203
- const doc = {
71204
- kind: graphql24.Kind.DOCUMENT,
71205
- definitions: Object.values(generatedFragments)
71206
- };
71207
- documents.push({
71208
- name: "generated::fragmentVariables",
71209
- kind: "HoudiniFragment" /* Fragment */,
71210
- document: doc,
71211
- originalDocument: doc,
71212
- generateStore: false,
71213
- generateArtifact: false,
71214
- filename: "generated::fragmentVariables",
71215
- originalString: ""
71216
- });
71217
- }
71218
- function inlineFragmentArgs({
71219
- config: config4,
71220
- filepath,
71221
- fragmentDefinitions,
71222
- document,
71223
- generatedFragments,
71224
- visitedFragments,
71225
- scope,
71226
- newName
71227
- }) {
71228
- if (!scope) {
71229
- scope = operationScope(
71230
- document.definitions.find(
71231
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
71232
- )
71233
- );
71234
- }
71235
- const definitionArgs = fragmentArguments(
71236
- config4,
71237
- filepath,
71238
- document
71239
- ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
71240
- const result = graphql24.visit(document, {
71241
- FragmentSpread(node) {
71242
- const { definition } = fragmentDefinitions[node.name.value];
71243
- let { args, hash } = collectWithArguments(config4, filepath, node, scope);
71244
- const newFragmentName = `${node.name.value}${hash}`;
71245
- if (!visitedFragments.has(newFragmentName)) {
71246
- visitedFragments.add(newFragmentName);
71247
- const defaultArguments = collectDefaultArgumentValues(config4, filepath, definition);
71248
- if (args) {
71249
- for (const [field, value] of Object.entries(defaultArguments || {})) {
71250
- if (!args[field]) {
71251
- args[field] = value;
71252
- }
71253
- }
71254
- generatedFragments[newFragmentName] = inlineFragmentArgs({
71255
- config: config4,
71256
- filepath,
71257
- fragmentDefinitions,
71258
- document: fragmentDefinitions[node.name.value].definition,
71259
- generatedFragments,
71260
- visitedFragments,
71261
- scope: args,
71262
- newName: newFragmentName
71263
- });
71264
- } else {
71265
- const doc = fragmentDefinitions[node.name.value].document;
71266
- const definitionIndex = doc.document.definitions.findIndex(
71267
- (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
71268
- );
71269
- const localDefinitions = [...doc.document.definitions];
71270
- localDefinitions.splice(definitionIndex, 1);
71271
- localDefinitions.push(
71272
- inlineFragmentArgs({
71273
- config: config4,
71274
- filepath,
71275
- fragmentDefinitions,
71276
- document: fragmentDefinitions[node.name.value].definition,
71277
- generatedFragments,
71278
- visitedFragments,
71279
- scope: defaultArguments,
71280
- newName: ""
71281
- })
71282
- );
71283
- doc.document = {
71284
- ...doc.document,
71285
- definitions: localDefinitions
71286
- };
71287
- }
71288
- if (node.name.value !== newFragmentName) {
71289
- return {
71290
- ...node,
71291
- name: {
71292
- kind: "Name",
71293
- value: newFragmentName
71294
- }
71295
- };
71296
- }
71297
- }
71298
- },
71299
- Argument(node) {
71300
- const value = node.value;
71301
- if (value.kind !== "Variable") {
71302
- return;
71303
- }
71304
- if (!scope) {
71305
- throw new HoudiniError({
71306
- filepath,
71307
- message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
71308
- });
71309
- }
71310
- const newValue = scope[value.name.value];
71311
- if (newValue) {
71312
- return {
71313
- ...node,
71314
- value: newValue
71315
- };
71316
- }
71317
- if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
71318
- throw new HoudiniError({
71319
- filepath,
71320
- message: "Missing value for required arg: " + value.name.value
71321
- });
71322
- }
71323
- return null;
71324
- }
71325
- });
71326
- if (newName) {
71327
- result.name = {
71328
- kind: graphql24.Kind.NAME,
71329
- value: newName
71330
- };
71331
- }
71332
- return result;
71333
- }
71334
- function withArguments(config4, node) {
71335
- const withDirectives = node.directives?.filter(
71336
- (directive) => directive.name.value === config4.withDirective
71337
- );
71338
- if (!withDirectives || withDirectives.length === 0) {
71339
- return [];
71340
- }
71341
- return withDirectives.flatMap((directive) => directive.arguments || []);
71342
- }
71343
- function fragmentArguments(config4, filepath, definition) {
71344
- const directives = definition.directives?.filter(
71345
- (directive) => directive.name.value === config4.argumentsDirective
71346
- );
71347
- if (!directives || directives.length === 0) {
71348
- return [];
71349
- }
71350
- return directives.flatMap(
71351
- (directive) => directive.arguments?.flatMap((arg) => {
71352
- if (arg.value.kind !== "ObjectValue") {
71353
- throw new HoudiniError({
71354
- filepath,
71355
- message: "values of @argument must be objects"
71356
- });
71357
- }
71358
- const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
71359
- if (!typeArg || typeArg.kind !== "StringValue") {
71360
- return [];
71361
- }
71362
- let type = typeArg.value;
71363
- let name2 = arg.name.value;
71364
- let required = false;
71365
- let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
71366
- if (type[type.length - 1] === "!") {
71367
- type = type.slice(0, -1);
71368
- required = true;
71369
- defaultValue = null;
71370
- }
71371
- return [
71372
- {
71373
- name: name2,
71374
- type,
71375
- required,
71376
- defaultValue
71377
- }
71378
- ];
71379
- }) || []
71380
- );
71381
- }
71382
- function collectDefaultArgumentValues(config4, filepath, definition) {
71383
- let result = {};
71384
- for (const { name: name2, required, defaultValue } of fragmentArguments(
71385
- config4,
71386
- filepath,
71387
- definition
71388
- )) {
71389
- if (required || !defaultValue) {
71390
- continue;
71391
- }
71392
- result[name2] = defaultValue;
71393
- }
71394
- return result;
71395
- }
71396
- function collectWithArguments(config4, filepath, node, scope = {}) {
71397
- const withArgs = withArguments(config4, node);
71398
- if (withArgs.length === 0) {
71399
- return { args: null, hash: "" };
71400
- }
71401
- let args = {};
71402
- for (const arg of withArgs) {
71403
- let value = arg.value;
71404
- if (value.kind === GraphqlKinds2.VARIABLE) {
71405
- if (!scope || !scope[value.name.value]) {
71406
- throw new HoudiniError({
71407
- filepath,
71408
- message: "Encountered undefined variable: " + value.name.value
71409
- });
71410
- }
71411
- value = scope[value.name.value];
71412
- }
71413
- args[arg.name.value] = {
71414
- ...value,
71415
- loc: void 0
71416
- };
71417
- }
71418
- return {
71419
- args,
71420
- hash: "_" + murmurHash(JSON.stringify(args))
71421
- };
71422
- }
71423
- function operationScope(operation) {
71424
- return operation.variableDefinitions?.reduce(
71425
- (scope, definition) => ({
71426
- ...scope,
71427
- [definition.variable.name.value]: {
71428
- kind: "Variable",
71429
- name: {
71430
- kind: "Name",
71431
- value: definition.variable.name.value
71432
- }
71433
- }
71434
- }),
71435
- {}
71436
- ) || {};
71437
- }
71438
-
71439
71623
  // src/codegen/validators/typeCheck.ts
71440
71624
  var graphql25 = __toESM(require_graphql2(), 1);
71441
71625
  async function typeCheck(config4, docs) {