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
@@ -54615,7 +54615,7 @@ async function find_graphql(config2, parsedScript, walker) {
54615
54615
  return;
54616
54616
  }
54617
54617
  const parsedTag = graphql2.parse(documentString);
54618
- if (walker.where && !walker.where(parsedTag)) {
54618
+ if (walker.where && !walker.where(parsedTag, { node, parent })) {
54619
54619
  return;
54620
54620
  }
54621
54621
  const definition = config2.extractDefinition(parsedTag);
@@ -54656,7 +54656,7 @@ async function find_graphql(config2, parsedScript, walker) {
54656
54656
  }
54657
54657
 
54658
54658
  // src/codegen/generators/artifacts/index.ts
54659
- var graphql11 = __toESM(require_graphql2(), 1);
54659
+ var graphql12 = __toESM(require_graphql2(), 1);
54660
54660
  var recast5 = __toESM(require_main2(), 1);
54661
54661
 
54662
54662
  // src/codegen/utils/commonjs.ts
@@ -54914,159 +54914,534 @@ function murmurHash(str) {
54914
54914
  return s;
54915
54915
  }
54916
54916
 
54917
- // src/codegen/generators/artifacts/indexFile.ts
54918
- async function writeIndexFile(config2, docs) {
54919
- const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
54920
- let body = config2.module === "esm" ? docsToGenerate.reduce(
54921
- (content, doc) => content + `
54922
- export { default as ${doc.name}} from './${doc.name}'`,
54923
- ""
54924
- ) : docsToGenerate.reduce(
54925
- (content, doc) => content + `
54926
- ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
54927
- cjsIndexFilePreamble
54928
- );
54929
- await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
54930
- }
54931
-
54932
- // src/codegen/generators/artifacts/inputs.ts
54917
+ // src/codegen/transforms/fragmentVariables.ts
54933
54918
  var graphql3 = __toESM(require_graphql2(), 1);
54934
- var recast3 = __toESM(require_main2(), 1);
54935
- var AST3 = recast3.types.builders;
54936
- function inputObject(config2, inputs) {
54937
- const visitedTypes = /* @__PURE__ */ new Set();
54938
- const inputObj = {
54939
- fields: inputs.reduce((fields, input) => {
54940
- const { type } = unwrapType(config2, input.type);
54941
- return {
54942
- ...fields,
54943
- [input.variable.name.value]: type.name
54944
- };
54945
- }, {}),
54946
- types: {}
54947
- };
54948
- for (const input of inputs) {
54949
- walkInputs(config2, visitedTypes, inputObj, input.type);
54950
- }
54951
- return inputObj;
54952
- }
54953
- function walkInputs(config2, visitedTypes, inputObj, rootType) {
54954
- const { type } = unwrapType(config2, rootType);
54955
- if (visitedTypes.has(type.name)) {
54956
- return;
54957
- }
54958
- if (graphql3.isEnumType(type) || graphql3.isScalarType(type)) {
54959
- return;
54960
- }
54961
- if (graphql3.isUnionType(type)) {
54962
- return;
54963
- }
54964
- visitedTypes.add(type.name);
54965
- inputObj.types[type.name] = Object.values(type.getFields()).reduce(
54966
- (typeFields, field) => {
54967
- const { type: fieldType } = unwrapType(config2, field.type);
54968
- walkInputs(config2, visitedTypes, inputObj, fieldType);
54969
- return {
54970
- ...typeFields,
54971
- [field.name]: fieldType.toString()
54972
- };
54973
- },
54974
- {}
54975
- );
54976
- }
54977
54919
 
54978
- // src/codegen/generators/artifacts/operations.ts
54979
- var graphql5 = __toESM(require_graphql2(), 1);
54980
-
54981
- // src/codegen/generators/artifacts/utils.ts
54982
- var graphql4 = __toESM(require_graphql2(), 1);
54983
- var recast4 = __toESM(require_main2(), 1);
54984
- var AST4 = recast4.types.builders;
54985
- function serializeValue(value) {
54986
- if (Array.isArray(value)) {
54987
- return AST4.arrayExpression(value.map(serializeValue));
54920
+ // src/codegen/transforms/composeQueries.ts
54921
+ var import_graphql = __toESM(require_graphql2(), 1);
54922
+ async function includeFragmentDefinitions(config2, documents) {
54923
+ const fragments = collectFragments(config2, documents);
54924
+ for (const [index, { name: name2, document, filename }] of documents.entries()) {
54925
+ const operation = document.definitions.find(
54926
+ ({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
54927
+ );
54928
+ if (!operation) {
54929
+ continue;
54930
+ }
54931
+ const allFragments = flattenFragments(
54932
+ filename,
54933
+ { requiredFragments: findRequiredFragments(operation.selectionSet) },
54934
+ fragments
54935
+ );
54936
+ documents[index].document = {
54937
+ ...document,
54938
+ definitions: [
54939
+ operation,
54940
+ ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
54941
+ ]
54942
+ };
54988
54943
  }
54989
- if (typeof value === "object" && value !== null) {
54990
- return AST4.objectExpression(
54991
- Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
54992
- ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
54993
- )
54944
+ }
54945
+ function collectFragments(config2, docs) {
54946
+ return docs.reduce((acc, doc) => {
54947
+ const definitions = doc.document.definitions.reduce(
54948
+ (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
54949
+ ...prev,
54950
+ [definition.name.value]: {
54951
+ definition,
54952
+ requiredFragments: findRequiredFragments(definition.selectionSet),
54953
+ document: doc
54954
+ }
54955
+ },
54956
+ {}
54994
54957
  );
54958
+ return {
54959
+ ...acc,
54960
+ ...definitions
54961
+ };
54962
+ }, {});
54963
+ }
54964
+ function findRequiredFragments(selectionSet) {
54965
+ if (selectionSet.selections.length === 0) {
54966
+ return [];
54995
54967
  }
54996
- if (typeof value === "string") {
54997
- if (value.indexOf("\n") !== -1) {
54998
- return AST4.templateLiteral(
54999
- [AST4.templateElement({ raw: value, cooked: value }, true)],
55000
- []
55001
- );
54968
+ const referencedFragments = [];
54969
+ for (const selection2 of selectionSet.selections) {
54970
+ if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
54971
+ referencedFragments.push(selection2.name.value);
54972
+ } else if (selection2.selectionSet) {
54973
+ referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
55002
54974
  }
55003
- return AST4.stringLiteral(value);
55004
54975
  }
55005
- return AST4.literal(value);
54976
+ return referencedFragments;
55006
54977
  }
55007
- function deepMerge(filepath, ...targets) {
55008
- if (typeof targets[0] !== "object") {
55009
- const matches = targets.filter((val) => val !== targets[0]).length === 0;
55010
- if (!matches) {
55011
- throw new HoudiniError({ filepath, message: "could not merge: " + targets });
54978
+ function flattenFragments(filepath, operation, fragments) {
54979
+ const frags = /* @__PURE__ */ new Set();
54980
+ const remaining = [...operation.requiredFragments];
54981
+ while (remaining.length > 0) {
54982
+ const nextFragment = remaining.shift();
54983
+ if (!nextFragment) {
54984
+ continue;
55012
54985
  }
55013
- return targets[0];
55014
- }
55015
- if (Array.isArray(targets[0])) {
55016
- return targets[0].concat(...targets.slice(1));
55017
- }
55018
- const fields = {};
55019
- for (const target of targets) {
55020
- for (const [key, value] of Object.entries(target)) {
55021
- if (!fields[key]) {
55022
- fields[key] = [];
55023
- }
55024
- fields[key].push(value);
54986
+ if (!frags.has(nextFragment)) {
54987
+ frags.add(nextFragment);
54988
+ } else {
54989
+ continue;
54990
+ }
54991
+ const targetFragment = fragments[nextFragment];
54992
+ if (!targetFragment) {
54993
+ throw new HoudiniError({
54994
+ filepath,
54995
+ message: "compose: could not find definition for fragment " + nextFragment
54996
+ });
55025
54997
  }
54998
+ remaining.push(...targetFragment.requiredFragments);
55026
54999
  }
55027
- return Object.fromEntries(
55028
- Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
55029
- );
55000
+ return [...frags];
55030
55001
  }
55031
- function convertValue(config2, val) {
55032
- let value;
55033
- let kind;
55034
- if (val.kind === graphql4.Kind.INT) {
55035
- value = parseInt(val.value, 10);
55036
- kind = "Int";
55037
- } else if (val.kind === graphql4.Kind.FLOAT) {
55038
- value = parseFloat(val.value);
55039
- kind = "Float";
55040
- } else if (val.kind === graphql4.Kind.BOOLEAN) {
55041
- value = val.value;
55042
- kind = "Boolean";
55043
- } else if (val.kind === graphql4.Kind.VARIABLE) {
55044
- value = val.name.value;
55045
- kind = "Variable";
55046
- } else if (val.kind === graphql4.Kind.STRING) {
55047
- value = val.value;
55048
- kind = "String";
55002
+
55003
+ // src/codegen/transforms/fragmentVariables.ts
55004
+ var GraphqlKinds2 = graphql3.Kind;
55005
+ async function fragmentVariables(config2, documents) {
55006
+ const fragments = collectFragments(config2, documents);
55007
+ const generatedFragments = {};
55008
+ const visitedFragments = /* @__PURE__ */ new Set();
55009
+ for (const doc2 of documents) {
55010
+ const operation = doc2.document.definitions.find(
55011
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
55012
+ );
55013
+ if (!operation) {
55014
+ continue;
55015
+ }
55016
+ doc2.document = inlineFragmentArgs({
55017
+ config: config2,
55018
+ filepath: doc2.filename,
55019
+ fragmentDefinitions: fragments,
55020
+ document: doc2.document,
55021
+ generatedFragments,
55022
+ visitedFragments,
55023
+ scope: null
55024
+ });
55049
55025
  }
55050
- return { kind, value };
55026
+ const doc = {
55027
+ kind: graphql3.Kind.DOCUMENT,
55028
+ definitions: Object.values(generatedFragments)
55029
+ };
55030
+ documents.push({
55031
+ name: "generated::fragmentVariables",
55032
+ kind: "HoudiniFragment" /* Fragment */,
55033
+ document: doc,
55034
+ originalDocument: doc,
55035
+ generateStore: false,
55036
+ generateArtifact: false,
55037
+ filename: "generated::fragmentVariables",
55038
+ originalString: ""
55039
+ });
55051
55040
  }
55052
-
55053
- // src/codegen/generators/artifacts/operations.ts
55054
- function operationsByPath(config2, filepath, definition, filterTypes) {
55055
- if (!definition) {
55056
- return {};
55041
+ function inlineFragmentArgs({
55042
+ config: config2,
55043
+ filepath,
55044
+ fragmentDefinitions,
55045
+ document,
55046
+ generatedFragments,
55047
+ visitedFragments,
55048
+ scope,
55049
+ newName
55050
+ }) {
55051
+ if (!scope) {
55052
+ scope = operationScope(
55053
+ document.definitions.find(
55054
+ ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
55055
+ )
55056
+ );
55057
55057
  }
55058
- const pathOperations = {};
55059
- graphql5.visit(definition, {
55060
- FragmentSpread(node, _, __, ___, ancestors) {
55061
- if (!config2.isListFragment(node.name.value)) {
55062
- return;
55063
- }
55064
- const path2 = ancestorKey(ancestors);
55065
- if (!pathOperations[path2]) {
55066
- pathOperations[path2] = [];
55067
- }
55068
- pathOperations[path2].push(
55069
- operationObject({
55058
+ const definitionArgs = fragmentArguments(
55059
+ config2,
55060
+ filepath,
55061
+ document
55062
+ ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
55063
+ const result = graphql3.visit(document, {
55064
+ FragmentSpread(node) {
55065
+ const { definition } = fragmentDefinitions[node.name.value];
55066
+ let { args, hash } = collectWithArguments(config2, filepath, node, scope);
55067
+ const newFragmentName = `${node.name.value}${hash}`;
55068
+ if (!visitedFragments.has(newFragmentName)) {
55069
+ visitedFragments.add(newFragmentName);
55070
+ const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
55071
+ if (args) {
55072
+ for (const [field, value] of Object.entries(defaultArguments || {})) {
55073
+ if (!args[field]) {
55074
+ args[field] = value;
55075
+ }
55076
+ }
55077
+ generatedFragments[newFragmentName] = inlineFragmentArgs({
55078
+ config: config2,
55079
+ filepath,
55080
+ fragmentDefinitions,
55081
+ document: fragmentDefinitions[node.name.value].definition,
55082
+ generatedFragments,
55083
+ visitedFragments,
55084
+ scope: args,
55085
+ newName: newFragmentName
55086
+ });
55087
+ } else {
55088
+ const doc = fragmentDefinitions[node.name.value].document;
55089
+ const definitionIndex = doc.document.definitions.findIndex(
55090
+ (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
55091
+ );
55092
+ const localDefinitions = [...doc.document.definitions];
55093
+ localDefinitions.splice(definitionIndex, 1);
55094
+ localDefinitions.push(
55095
+ inlineFragmentArgs({
55096
+ config: config2,
55097
+ filepath,
55098
+ fragmentDefinitions,
55099
+ document: fragmentDefinitions[node.name.value].definition,
55100
+ generatedFragments,
55101
+ visitedFragments,
55102
+ scope: defaultArguments,
55103
+ newName: ""
55104
+ })
55105
+ );
55106
+ doc.document = {
55107
+ ...doc.document,
55108
+ definitions: localDefinitions
55109
+ };
55110
+ }
55111
+ if (node.name.value !== newFragmentName) {
55112
+ return {
55113
+ ...node,
55114
+ name: {
55115
+ kind: "Name",
55116
+ value: newFragmentName
55117
+ }
55118
+ };
55119
+ }
55120
+ }
55121
+ },
55122
+ Argument(node) {
55123
+ const value = node.value;
55124
+ if (value.kind !== "Variable") {
55125
+ return;
55126
+ }
55127
+ if (!scope) {
55128
+ throw new HoudiniError({
55129
+ filepath,
55130
+ message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
55131
+ });
55132
+ }
55133
+ const newValue = scope[value.name.value];
55134
+ if (newValue) {
55135
+ return {
55136
+ ...node,
55137
+ value: newValue
55138
+ };
55139
+ }
55140
+ if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
55141
+ throw new HoudiniError({
55142
+ filepath,
55143
+ message: "Missing value for required arg: " + value.name.value
55144
+ });
55145
+ }
55146
+ return null;
55147
+ }
55148
+ });
55149
+ if (newName) {
55150
+ result.name = {
55151
+ kind: graphql3.Kind.NAME,
55152
+ value: newName
55153
+ };
55154
+ }
55155
+ return result;
55156
+ }
55157
+ function withArguments(config2, node) {
55158
+ const withDirectives = node.directives?.filter(
55159
+ (directive) => directive.name.value === config2.withDirective
55160
+ );
55161
+ if (!withDirectives || withDirectives.length === 0) {
55162
+ return [];
55163
+ }
55164
+ return withDirectives.flatMap((directive) => directive.arguments || []);
55165
+ }
55166
+ function fragmentArguments(config2, filepath, definition) {
55167
+ const directives = definition.directives?.filter(
55168
+ (directive) => directive.name.value === config2.argumentsDirective
55169
+ );
55170
+ if (!directives || directives.length === 0) {
55171
+ return [];
55172
+ }
55173
+ return directives.flatMap(
55174
+ (directive) => directive.arguments?.flatMap((arg) => {
55175
+ if (arg.value.kind !== "ObjectValue") {
55176
+ throw new HoudiniError({
55177
+ filepath,
55178
+ message: "values of @argument must be objects"
55179
+ });
55180
+ }
55181
+ const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
55182
+ if (!typeArg || typeArg.kind !== "StringValue") {
55183
+ return [];
55184
+ }
55185
+ let type = typeArg.value;
55186
+ let name2 = arg.name.value;
55187
+ let required = false;
55188
+ let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
55189
+ if (type[type.length - 1] === "!") {
55190
+ type = type.slice(0, -1);
55191
+ required = true;
55192
+ defaultValue = null;
55193
+ }
55194
+ return [
55195
+ {
55196
+ name: name2,
55197
+ type,
55198
+ required,
55199
+ defaultValue
55200
+ }
55201
+ ];
55202
+ }) || []
55203
+ );
55204
+ }
55205
+ function collectDefaultArgumentValues(config2, filepath, definition) {
55206
+ let result = {};
55207
+ for (const { name: name2, required, defaultValue } of fragmentArguments(
55208
+ config2,
55209
+ filepath,
55210
+ definition
55211
+ )) {
55212
+ if (required || !defaultValue) {
55213
+ continue;
55214
+ }
55215
+ result[name2] = defaultValue;
55216
+ }
55217
+ return result;
55218
+ }
55219
+ function collectWithArguments(config2, filepath, node, scope = {}) {
55220
+ const withArgs = withArguments(config2, node);
55221
+ if (withArgs.length === 0) {
55222
+ return { args: null, hash: "" };
55223
+ }
55224
+ let args = {};
55225
+ for (const arg of withArgs) {
55226
+ let value = arg.value;
55227
+ if (value.kind === GraphqlKinds2.VARIABLE) {
55228
+ if (!scope || !scope[value.name.value]) {
55229
+ throw new HoudiniError({
55230
+ filepath,
55231
+ message: "Encountered undefined variable: " + value.name.value
55232
+ });
55233
+ }
55234
+ value = scope[value.name.value];
55235
+ }
55236
+ args[arg.name.value] = {
55237
+ ...value,
55238
+ loc: void 0
55239
+ };
55240
+ }
55241
+ return {
55242
+ args,
55243
+ hash: "_" + murmurHash(JSON.stringify(args))
55244
+ };
55245
+ }
55246
+ function operationScope(operation) {
55247
+ return operation.variableDefinitions?.reduce(
55248
+ (scope, definition) => ({
55249
+ ...scope,
55250
+ [definition.variable.name.value]: {
55251
+ kind: "Variable",
55252
+ name: {
55253
+ kind: "Name",
55254
+ value: definition.variable.name.value
55255
+ }
55256
+ }
55257
+ }),
55258
+ {}
55259
+ ) || {};
55260
+ }
55261
+ function fragmentArgumentsDefinitions(config2, filepath, definition) {
55262
+ const args = fragmentArguments(config2, filepath, definition);
55263
+ if (args.length === 0) {
55264
+ return [];
55265
+ }
55266
+ return args.map((arg) => {
55267
+ const innerType = {
55268
+ kind: "NamedType",
55269
+ name: {
55270
+ kind: "Name",
55271
+ value: arg.type
55272
+ }
55273
+ };
55274
+ return {
55275
+ kind: "VariableDefinition",
55276
+ type: arg.required ? innerType : {
55277
+ kind: "NonNullType",
55278
+ type: innerType
55279
+ },
55280
+ variable: {
55281
+ kind: "Variable",
55282
+ name: {
55283
+ kind: "Name",
55284
+ value: arg.name
55285
+ }
55286
+ },
55287
+ defaultValue: arg.defaultValue ?? void 0
55288
+ };
55289
+ });
55290
+ }
55291
+
55292
+ // src/codegen/generators/artifacts/indexFile.ts
55293
+ async function writeIndexFile(config2, docs) {
55294
+ const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
55295
+ let body = config2.module === "esm" ? docsToGenerate.reduce(
55296
+ (content, doc) => content + `
55297
+ export { default as ${doc.name}} from './${doc.name}'`,
55298
+ ""
55299
+ ) : docsToGenerate.reduce(
55300
+ (content, doc) => content + `
55301
+ ${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
55302
+ cjsIndexFilePreamble
55303
+ );
55304
+ await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
55305
+ }
55306
+
55307
+ // src/codegen/generators/artifacts/inputs.ts
55308
+ var graphql4 = __toESM(require_graphql2(), 1);
55309
+ var recast3 = __toESM(require_main2(), 1);
55310
+ var AST3 = recast3.types.builders;
55311
+ function inputObject(config2, inputs) {
55312
+ const visitedTypes = /* @__PURE__ */ new Set();
55313
+ const inputObj = {
55314
+ fields: inputs.reduce((fields, input) => {
55315
+ const { type } = unwrapType(config2, input.type);
55316
+ return {
55317
+ ...fields,
55318
+ [input.variable.name.value]: type.name
55319
+ };
55320
+ }, {}),
55321
+ types: {}
55322
+ };
55323
+ for (const input of inputs) {
55324
+ walkInputs(config2, visitedTypes, inputObj, input.type);
55325
+ }
55326
+ return inputObj;
55327
+ }
55328
+ function walkInputs(config2, visitedTypes, inputObj, rootType) {
55329
+ const { type } = unwrapType(config2, rootType);
55330
+ if (visitedTypes.has(type.name)) {
55331
+ return;
55332
+ }
55333
+ if (graphql4.isEnumType(type) || graphql4.isScalarType(type)) {
55334
+ return;
55335
+ }
55336
+ if (graphql4.isUnionType(type)) {
55337
+ return;
55338
+ }
55339
+ visitedTypes.add(type.name);
55340
+ inputObj.types[type.name] = Object.values(type.getFields()).reduce(
55341
+ (typeFields, field) => {
55342
+ const { type: fieldType } = unwrapType(config2, field.type);
55343
+ walkInputs(config2, visitedTypes, inputObj, fieldType);
55344
+ return {
55345
+ ...typeFields,
55346
+ [field.name]: fieldType.toString()
55347
+ };
55348
+ },
55349
+ {}
55350
+ );
55351
+ }
55352
+
55353
+ // src/codegen/generators/artifacts/operations.ts
55354
+ var graphql6 = __toESM(require_graphql2(), 1);
55355
+
55356
+ // src/codegen/generators/artifacts/utils.ts
55357
+ var graphql5 = __toESM(require_graphql2(), 1);
55358
+ var recast4 = __toESM(require_main2(), 1);
55359
+ var AST4 = recast4.types.builders;
55360
+ function serializeValue(value) {
55361
+ if (Array.isArray(value)) {
55362
+ return AST4.arrayExpression(value.map(serializeValue));
55363
+ }
55364
+ if (typeof value === "object" && value !== null) {
55365
+ return AST4.objectExpression(
55366
+ Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
55367
+ ([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
55368
+ )
55369
+ );
55370
+ }
55371
+ if (typeof value === "string") {
55372
+ if (value.indexOf("\n") !== -1) {
55373
+ return AST4.templateLiteral(
55374
+ [AST4.templateElement({ raw: value, cooked: value }, true)],
55375
+ []
55376
+ );
55377
+ }
55378
+ return AST4.stringLiteral(value);
55379
+ }
55380
+ return AST4.literal(value);
55381
+ }
55382
+ function deepMerge(filepath, ...targets) {
55383
+ if (typeof targets[0] !== "object") {
55384
+ const matches = targets.filter((val) => val !== targets[0]).length === 0;
55385
+ if (!matches) {
55386
+ throw new HoudiniError({ filepath, message: "could not merge: " + targets });
55387
+ }
55388
+ return targets[0];
55389
+ }
55390
+ if (Array.isArray(targets[0])) {
55391
+ return targets[0].concat(...targets.slice(1));
55392
+ }
55393
+ const fields = {};
55394
+ for (const target of targets) {
55395
+ for (const [key, value] of Object.entries(target)) {
55396
+ if (!fields[key]) {
55397
+ fields[key] = [];
55398
+ }
55399
+ fields[key].push(value);
55400
+ }
55401
+ }
55402
+ return Object.fromEntries(
55403
+ Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
55404
+ );
55405
+ }
55406
+ function convertValue(config2, val) {
55407
+ let value;
55408
+ let kind;
55409
+ if (val.kind === graphql5.Kind.INT) {
55410
+ value = parseInt(val.value, 10);
55411
+ kind = "Int";
55412
+ } else if (val.kind === graphql5.Kind.FLOAT) {
55413
+ value = parseFloat(val.value);
55414
+ kind = "Float";
55415
+ } else if (val.kind === graphql5.Kind.BOOLEAN) {
55416
+ value = val.value;
55417
+ kind = "Boolean";
55418
+ } else if (val.kind === graphql5.Kind.VARIABLE) {
55419
+ value = val.name.value;
55420
+ kind = "Variable";
55421
+ } else if (val.kind === graphql5.Kind.STRING) {
55422
+ value = val.value;
55423
+ kind = "String";
55424
+ }
55425
+ return { kind, value };
55426
+ }
55427
+
55428
+ // src/codegen/generators/artifacts/operations.ts
55429
+ function operationsByPath(config2, filepath, definition, filterTypes) {
55430
+ if (!definition) {
55431
+ return {};
55432
+ }
55433
+ const pathOperations = {};
55434
+ graphql6.visit(definition, {
55435
+ FragmentSpread(node, _, __, ___, ancestors) {
55436
+ if (!config2.isListFragment(node.name.value)) {
55437
+ return;
55438
+ }
55439
+ const path2 = ancestorKey(ancestors);
55440
+ if (!pathOperations[path2]) {
55441
+ pathOperations[path2] = [];
55442
+ }
55443
+ pathOperations[path2].push(
55444
+ operationObject({
55070
55445
  config: config2,
55071
55446
  filepath,
55072
55447
  listName: config2.listNameFromFragment(node.name.value),
@@ -55215,7 +55590,7 @@ function ancestorKey(ancestors) {
55215
55590
  }
55216
55591
 
55217
55592
  // src/codegen/generators/artifacts/selection.ts
55218
- var graphql10 = __toESM(require_graphql2(), 1);
55593
+ var graphql11 = __toESM(require_graphql2(), 1);
55219
55594
 
55220
55595
  // ../../node_modules/.pnpm/@kitql+helper@0.5.0/node_modules/@kitql/helper/index.mjs
55221
55596
  var config = {
@@ -55255,16 +55630,16 @@ function logYellow(str) {
55255
55630
  }
55256
55631
 
55257
55632
  // src/codegen/transforms/list.ts
55258
- var graphql8 = __toESM(require_graphql2(), 1);
55633
+ var graphql9 = __toESM(require_graphql2(), 1);
55259
55634
 
55260
55635
  // src/codegen/utils/objectIdentificationSelection.ts
55261
- var graphql6 = __toESM(require_graphql2(), 1);
55636
+ var graphql7 = __toESM(require_graphql2(), 1);
55262
55637
  var objectIdentificationSelection = (config2, type) => {
55263
55638
  return config2.keyFieldsForType(type.name).map((key) => {
55264
55639
  return {
55265
- kind: graphql6.Kind.FIELD,
55640
+ kind: graphql7.Kind.FIELD,
55266
55641
  name: {
55267
- kind: graphql6.Kind.NAME,
55642
+ kind: graphql7.Kind.NAME,
55268
55643
  value: key
55269
55644
  }
55270
55645
  };
@@ -55272,7 +55647,7 @@ var objectIdentificationSelection = (config2, type) => {
55272
55647
  };
55273
55648
 
55274
55649
  // src/codegen/transforms/paginate.ts
55275
- var graphql7 = __toESM(require_graphql2(), 1);
55650
+ var graphql8 = __toESM(require_graphql2(), 1);
55276
55651
  async function paginate(config2, documents) {
55277
55652
  const newDocs = [];
55278
55653
  for (const doc of documents) {
@@ -55305,7 +55680,7 @@ async function paginate(config2, documents) {
55305
55680
  };
55306
55681
  let cursorType = "String";
55307
55682
  let paginationPath = [];
55308
- doc.document = graphql7.visit(doc.document, {
55683
+ doc.document = graphql8.visit(doc.document, {
55309
55684
  Field(node, _, __, ___, ancestors) {
55310
55685
  const paginateDirective = node.directives?.find(
55311
55686
  (directive) => directive.name.value === config2.paginateDirective
@@ -55316,23 +55691,22 @@ async function paginate(config2, documents) {
55316
55691
  paginated = true;
55317
55692
  const fieldTypeFields = parentTypeFromAncestors(config2.schema, doc.filename, ancestors).getFields()[node.name.value];
55318
55693
  const args = new Set(fieldTypeFields.args.map((arg) => arg.name));
55319
- const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
55320
- const specifiedForwards = passedArgs.has("first");
55321
- const specifiedBackwards = passedArgs.has("last");
55322
55694
  cursorType = fieldTypeFields.args?.find((arg) => ["before", "after"].includes(arg.name))?.type?.name || "String";
55323
55695
  flags.after.type = cursorType;
55324
55696
  flags.before.type = cursorType;
55325
- const forwardPagination = !specifiedBackwards && args.has("first") && args.has("after");
55326
- const backwardsPagination = !specifiedForwards && args.has("last") && args.has("before");
55327
- const offsetPagination = !forwardPagination && !backwardsPagination && args.has("offset") && args.has("limit");
55328
- flags.first.enabled = forwardPagination;
55329
- flags.after.enabled = forwardPagination;
55330
- flags.last.enabled = backwardsPagination;
55331
- flags.before.enabled = backwardsPagination;
55697
+ const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
55698
+ const forwards = args.has("first") && args.has("after");
55699
+ const backwards = args.has("last") && args.has("after");
55700
+ const cursorPagination = passedArgs.has("last") || passedArgs.has("first");
55701
+ const offsetPagination = !cursorPagination && args.has("offset") && args.has("limit");
55702
+ flags.first.enabled = forwards;
55703
+ flags.after.enabled = forwards;
55704
+ flags.last.enabled = backwards;
55705
+ flags.before.enabled = backwards;
55332
55706
  flags.offset.enabled = offsetPagination;
55333
55707
  flags.limit.enabled = offsetPagination;
55334
55708
  paginationPath = ancestors.filter(
55335
- (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql7.Kind.FIELD
55709
+ (ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql8.Kind.FIELD
55336
55710
  ).concat(node).map((field) => field.alias?.value || field.name.value);
55337
55711
  return {
55338
55712
  ...node,
@@ -55348,12 +55722,8 @@ async function paginate(config2, documents) {
55348
55722
  let fragmentName = "";
55349
55723
  let refetchQueryName = "";
55350
55724
  let nodeQuery = false;
55351
- let refetchUpdate = "append" /* append */;
55352
- if (flags.last.enabled) {
55353
- refetchUpdate = "prepend" /* prepend */;
55354
- }
55355
55725
  let fragment = "";
55356
- doc.document = graphql7.visit(doc.document, {
55726
+ doc.document = graphql8.visit(doc.document, {
55357
55727
  OperationDefinition(node) {
55358
55728
  if (node.operation !== "query") {
55359
55729
  throw new HoudiniError({
@@ -55407,9 +55777,9 @@ async function paginate(config2, documents) {
55407
55777
  directives: [
55408
55778
  ...node.directives || [],
55409
55779
  {
55410
- kind: graphql7.Kind.DIRECTIVE,
55780
+ kind: graphql8.Kind.DIRECTIVE,
55411
55781
  name: {
55412
- kind: graphql7.Kind.NAME,
55782
+ kind: graphql8.Kind.NAME,
55413
55783
  value: config2.argumentsDirective
55414
55784
  }
55415
55785
  }
@@ -55446,42 +55816,40 @@ async function paginate(config2, documents) {
55446
55816
  targetType = fragment;
55447
55817
  }
55448
55818
  }
55819
+ const pageSize = flags.first.defaultValue ?? flags.last.defaultValue ?? flags.limit.defaultValue;
55820
+ const start = flags.after.defaultValue ?? flags.before.defaultValue ?? flags.offset.defaultValue;
55821
+ let direction = "forward";
55822
+ if (flags.before.enabled && flags.after.enabled) {
55823
+ direction = "both";
55824
+ } else if (flags.before.enabled) {
55825
+ direction = "backward";
55826
+ }
55449
55827
  doc.refetch = {
55450
- update: refetchUpdate,
55451
55828
  path: paginationPath,
55452
55829
  method: flags.first.enabled || flags.last.enabled ? "cursor" : "offset",
55453
- pageSize: 0,
55830
+ pageSize,
55454
55831
  embedded: nodeQuery,
55455
55832
  targetType,
55456
55833
  paginated: true,
55457
- direction: flags.last.enabled ? "backwards" : "forward"
55458
- };
55459
- if (flags.first.enabled) {
55460
- doc.refetch.pageSize = flags.first.defaultValue;
55461
- doc.refetch.start = flags.after.defaultValue;
55462
- } else if (flags.last.enabled) {
55463
- doc.refetch.pageSize = flags.last.defaultValue;
55464
- doc.refetch.start = flags.before.defaultValue;
55465
- } else if (flags.limit.enabled) {
55466
- doc.refetch.pageSize = flags.limit.defaultValue;
55467
- doc.refetch.start = flags.offset.defaultValue;
55468
- }
55834
+ direction,
55835
+ start
55836
+ };
55469
55837
  if (!fragment) {
55470
55838
  continue;
55471
55839
  }
55472
55840
  const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
55473
55841
  const fragmentSpreadSelection = [
55474
55842
  {
55475
- kind: graphql7.Kind.FRAGMENT_SPREAD,
55843
+ kind: graphql8.Kind.FRAGMENT_SPREAD,
55476
55844
  name: {
55477
- kind: graphql7.Kind.NAME,
55845
+ kind: graphql8.Kind.NAME,
55478
55846
  value: fragmentName
55479
55847
  },
55480
55848
  directives: [
55481
55849
  {
55482
- kind: graphql7.Kind.DIRECTIVE,
55850
+ kind: graphql8.Kind.DIRECTIVE,
55483
55851
  name: {
55484
- kind: graphql7.Kind.NAME,
55852
+ kind: graphql8.Kind.NAME,
55485
55853
  value: config2.withDirective
55486
55854
  },
55487
55855
  ["arguments"]: paginationArgs.map(
@@ -55509,29 +55877,29 @@ async function paginate(config2, documents) {
55509
55877
  });
55510
55878
  const typeConfig = config2.typeConfig?.[fragment];
55511
55879
  const queryDoc = {
55512
- kind: graphql7.Kind.DOCUMENT,
55880
+ kind: graphql8.Kind.DOCUMENT,
55513
55881
  definitions: [
55514
55882
  {
55515
- kind: graphql7.Kind.OPERATION_DEFINITION,
55883
+ kind: graphql8.Kind.OPERATION_DEFINITION,
55516
55884
  name: {
55517
- kind: graphql7.Kind.NAME,
55885
+ kind: graphql8.Kind.NAME,
55518
55886
  value: refetchQueryName
55519
55887
  },
55520
55888
  operation: "query",
55521
55889
  variableDefinitions: paginationArgs.map(
55522
55890
  (arg) => ({
55523
- kind: graphql7.Kind.VARIABLE_DEFINITION,
55891
+ kind: graphql8.Kind.VARIABLE_DEFINITION,
55524
55892
  type: {
55525
- kind: graphql7.Kind.NAMED_TYPE,
55893
+ kind: graphql8.Kind.NAMED_TYPE,
55526
55894
  name: {
55527
- kind: graphql7.Kind.NAME,
55895
+ kind: graphql8.Kind.NAME,
55528
55896
  value: arg.type
55529
55897
  }
55530
55898
  },
55531
55899
  variable: {
55532
- kind: graphql7.Kind.VARIABLE,
55900
+ kind: graphql8.Kind.VARIABLE,
55533
55901
  name: {
55534
- kind: graphql7.Kind.NAME,
55902
+ kind: graphql8.Kind.NAME,
55535
55903
  value: arg.name
55536
55904
  }
55537
55905
  },
@@ -55543,12 +55911,12 @@ async function paginate(config2, documents) {
55543
55911
  ).concat(
55544
55912
  !nodeQuery ? [] : keys.map(
55545
55913
  (key) => ({
55546
- kind: graphql7.Kind.VARIABLE_DEFINITION,
55914
+ kind: graphql8.Kind.VARIABLE_DEFINITION,
55547
55915
  type: key.type,
55548
55916
  variable: {
55549
- kind: graphql7.Kind.VARIABLE,
55917
+ kind: graphql8.Kind.VARIABLE,
55550
55918
  name: {
55551
- kind: graphql7.Kind.NAME,
55919
+ kind: graphql8.Kind.NAME,
55552
55920
  value: key.name
55553
55921
  }
55554
55922
  }
@@ -55556,42 +55924,42 @@ async function paginate(config2, documents) {
55556
55924
  )
55557
55925
  ),
55558
55926
  selectionSet: {
55559
- kind: graphql7.Kind.SELECTION_SET,
55927
+ kind: graphql8.Kind.SELECTION_SET,
55560
55928
  selections: !nodeQuery ? fragmentSpreadSelection : [
55561
55929
  {
55562
- kind: graphql7.Kind.FIELD,
55930
+ kind: graphql8.Kind.FIELD,
55563
55931
  name: {
55564
- kind: graphql7.Kind.NAME,
55932
+ kind: graphql8.Kind.NAME,
55565
55933
  value: typeConfig?.resolve?.queryField || "node"
55566
55934
  },
55567
55935
  ["arguments"]: keys.map((key) => ({
55568
- kind: graphql7.Kind.ARGUMENT,
55936
+ kind: graphql8.Kind.ARGUMENT,
55569
55937
  name: {
55570
- kind: graphql7.Kind.NAME,
55938
+ kind: graphql8.Kind.NAME,
55571
55939
  value: key.name
55572
55940
  },
55573
55941
  value: {
55574
- kind: graphql7.Kind.VARIABLE,
55942
+ kind: graphql8.Kind.VARIABLE,
55575
55943
  name: {
55576
- kind: graphql7.Kind.NAME,
55944
+ kind: graphql8.Kind.NAME,
55577
55945
  value: key.name
55578
55946
  }
55579
55947
  }
55580
55948
  })),
55581
55949
  selectionSet: {
55582
- kind: graphql7.Kind.SELECTION_SET,
55950
+ kind: graphql8.Kind.SELECTION_SET,
55583
55951
  selections: [
55584
55952
  {
55585
- kind: graphql7.Kind.FIELD,
55953
+ kind: graphql8.Kind.FIELD,
55586
55954
  name: {
55587
- kind: graphql7.Kind.NAME,
55955
+ kind: graphql8.Kind.NAME,
55588
55956
  value: "__typename"
55589
55957
  }
55590
55958
  },
55591
55959
  ...(typeConfig?.keys || ["id"]).map((key) => ({
55592
- kind: graphql7.Kind.FIELD,
55960
+ kind: graphql8.Kind.FIELD,
55593
55961
  name: {
55594
- kind: graphql7.Kind.NAME,
55962
+ kind: graphql8.Kind.NAME,
55595
55963
  value: key
55596
55964
  }
55597
55965
  })),
@@ -55641,27 +56009,21 @@ function replaceArgumentsWithVariables(args, flags) {
55641
56009
  if (flags[name2].defaultValue || !spec.enabled || seenArgs[name2]) {
55642
56010
  continue;
55643
56011
  }
55644
- if (["first", "after"].includes(name2) && flags["before"].enabled) {
55645
- continue;
55646
- }
55647
- if (["last", "before"].includes(name2) && flags["first"].enabled) {
55648
- continue;
55649
- }
55650
56012
  newArgs.push(variableAsArgument(name2));
55651
56013
  }
55652
56014
  return newArgs;
55653
56015
  }
55654
56016
  function variableAsArgument(name2, variable) {
55655
56017
  return {
55656
- kind: graphql7.Kind.ARGUMENT,
56018
+ kind: graphql8.Kind.ARGUMENT,
55657
56019
  name: {
55658
- kind: graphql7.Kind.NAME,
56020
+ kind: graphql8.Kind.NAME,
55659
56021
  value: name2
55660
56022
  },
55661
56023
  value: {
55662
- kind: graphql7.Kind.VARIABLE,
56024
+ kind: graphql8.Kind.VARIABLE,
55663
56025
  name: {
55664
- kind: graphql7.Kind.NAME,
56026
+ kind: graphql8.Kind.NAME,
55665
56027
  value: variable ?? name2
55666
56028
  }
55667
56029
  }
@@ -55669,18 +56031,18 @@ function variableAsArgument(name2, variable) {
55669
56031
  }
55670
56032
  function staticVariableDefinition(name2, type, defaultValue, variableName) {
55671
56033
  return {
55672
- kind: graphql7.Kind.VARIABLE_DEFINITION,
56034
+ kind: graphql8.Kind.VARIABLE_DEFINITION,
55673
56035
  type: {
55674
- kind: graphql7.Kind.NAMED_TYPE,
56036
+ kind: graphql8.Kind.NAMED_TYPE,
55675
56037
  name: {
55676
- kind: graphql7.Kind.NAME,
56038
+ kind: graphql8.Kind.NAME,
55677
56039
  value: type
55678
56040
  }
55679
56041
  },
55680
56042
  variable: {
55681
- kind: graphql7.Kind.VARIABLE,
56043
+ kind: graphql8.Kind.VARIABLE,
55682
56044
  name: {
55683
- kind: graphql7.Kind.NAME,
56045
+ kind: graphql8.Kind.NAME,
55684
56046
  value: variableName ?? name2
55685
56047
  }
55686
56048
  },
@@ -55692,9 +56054,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
55692
56054
  }
55693
56055
  function argumentNode(name2, value) {
55694
56056
  return {
55695
- kind: graphql7.Kind.ARGUMENT,
56057
+ kind: graphql8.Kind.ARGUMENT,
55696
56058
  name: {
55697
- kind: graphql7.Kind.NAME,
56059
+ kind: graphql8.Kind.NAME,
55698
56060
  value: name2
55699
56061
  },
55700
56062
  value: objectNode(value)
@@ -55702,16 +56064,16 @@ function argumentNode(name2, value) {
55702
56064
  }
55703
56065
  function objectNode([type, defaultValue]) {
55704
56066
  const node = {
55705
- kind: graphql7.Kind.OBJECT,
56067
+ kind: graphql8.Kind.OBJECT,
55706
56068
  fields: [
55707
56069
  {
55708
- kind: graphql7.Kind.OBJECT_FIELD,
56070
+ kind: graphql8.Kind.OBJECT_FIELD,
55709
56071
  name: {
55710
- kind: graphql7.Kind.NAME,
56072
+ kind: graphql8.Kind.NAME,
55711
56073
  value: "type"
55712
56074
  },
55713
56075
  value: {
55714
- kind: graphql7.Kind.STRING,
56076
+ kind: graphql8.Kind.STRING,
55715
56077
  value: type
55716
56078
  }
55717
56079
  }
@@ -55719,8 +56081,8 @@ function objectNode([type, defaultValue]) {
55719
56081
  };
55720
56082
  if (defaultValue) {
55721
56083
  node.fields.push({
55722
- kind: graphql7.Kind.OBJECT_FIELD,
55723
- name: { kind: graphql7.Kind.NAME, value: "default" },
56084
+ kind: graphql8.Kind.OBJECT_FIELD,
56085
+ name: { kind: graphql8.Kind.NAME, value: "default" },
55724
56086
  value: {
55725
56087
  kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
55726
56088
  value: defaultValue.toString()
@@ -55731,34 +56093,34 @@ function objectNode([type, defaultValue]) {
55731
56093
  }
55732
56094
  var pageInfoSelection = [
55733
56095
  {
55734
- kind: graphql7.Kind.FIELD,
56096
+ kind: graphql8.Kind.FIELD,
55735
56097
  name: {
55736
- kind: graphql7.Kind.NAME,
56098
+ kind: graphql8.Kind.NAME,
55737
56099
  value: "edges"
55738
56100
  },
55739
56101
  selectionSet: {
55740
- kind: graphql7.Kind.SELECTION_SET,
56102
+ kind: graphql8.Kind.SELECTION_SET,
55741
56103
  selections: [
55742
56104
  {
55743
- kind: graphql7.Kind.FIELD,
56105
+ kind: graphql8.Kind.FIELD,
55744
56106
  name: {
55745
- kind: graphql7.Kind.NAME,
56107
+ kind: graphql8.Kind.NAME,
55746
56108
  value: "cursor"
55747
56109
  }
55748
56110
  },
55749
56111
  {
55750
- kind: graphql7.Kind.FIELD,
56112
+ kind: graphql8.Kind.FIELD,
55751
56113
  name: {
55752
- kind: graphql7.Kind.NAME,
56114
+ kind: graphql8.Kind.NAME,
55753
56115
  value: "node"
55754
56116
  },
55755
56117
  selectionSet: {
55756
- kind: graphql7.Kind.SELECTION_SET,
56118
+ kind: graphql8.Kind.SELECTION_SET,
55757
56119
  selections: [
55758
56120
  {
55759
- kind: graphql7.Kind.FIELD,
56121
+ kind: graphql8.Kind.FIELD,
55760
56122
  name: {
55761
- kind: graphql7.Kind.NAME,
56123
+ kind: graphql8.Kind.NAME,
55762
56124
  value: "__typename"
55763
56125
  }
55764
56126
  }
@@ -55769,39 +56131,39 @@ var pageInfoSelection = [
55769
56131
  }
55770
56132
  },
55771
56133
  {
55772
- kind: graphql7.Kind.FIELD,
56134
+ kind: graphql8.Kind.FIELD,
55773
56135
  name: {
55774
- kind: graphql7.Kind.NAME,
56136
+ kind: graphql8.Kind.NAME,
55775
56137
  value: "pageInfo"
55776
56138
  },
55777
56139
  selectionSet: {
55778
- kind: graphql7.Kind.SELECTION_SET,
56140
+ kind: graphql8.Kind.SELECTION_SET,
55779
56141
  selections: [
55780
56142
  {
55781
- kind: graphql7.Kind.FIELD,
56143
+ kind: graphql8.Kind.FIELD,
55782
56144
  name: {
55783
- kind: graphql7.Kind.NAME,
56145
+ kind: graphql8.Kind.NAME,
55784
56146
  value: "hasPreviousPage"
55785
56147
  }
55786
56148
  },
55787
56149
  {
55788
- kind: graphql7.Kind.FIELD,
56150
+ kind: graphql8.Kind.FIELD,
55789
56151
  name: {
55790
- kind: graphql7.Kind.NAME,
56152
+ kind: graphql8.Kind.NAME,
55791
56153
  value: "hasNextPage"
55792
56154
  }
55793
56155
  },
55794
56156
  {
55795
- kind: graphql7.Kind.FIELD,
56157
+ kind: graphql8.Kind.FIELD,
55796
56158
  name: {
55797
- kind: graphql7.Kind.NAME,
56159
+ kind: graphql8.Kind.NAME,
55798
56160
  value: "startCursor"
55799
56161
  }
55800
56162
  },
55801
56163
  {
55802
- kind: graphql7.Kind.FIELD,
56164
+ kind: graphql8.Kind.FIELD,
55803
56165
  name: {
55804
- kind: graphql7.Kind.NAME,
56166
+ kind: graphql8.Kind.NAME,
55805
56167
  value: "endCursor"
55806
56168
  }
55807
56169
  }
@@ -55815,15 +56177,15 @@ async function addListFragments(config2, documents) {
55815
56177
  const lists = {};
55816
56178
  const errors = [];
55817
56179
  for (const doc of documents) {
55818
- doc.document = graphql8.visit(doc.document, {
56180
+ doc.document = graphql9.visit(doc.document, {
55819
56181
  Directive(node, key, parent, path2, ancestors) {
55820
56182
  if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
55821
56183
  const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
55822
56184
  let error = {
55823
- ...new graphql8.GraphQLError(
56185
+ ...new graphql9.GraphQLError(
55824
56186
  "",
55825
56187
  node,
55826
- new graphql8.Source(""),
56188
+ new graphql9.Source(""),
55827
56189
  node.loc ? [node.loc.start, node.loc.end] : null,
55828
56190
  path2
55829
56191
  ),
@@ -55875,7 +56237,7 @@ async function addListFragments(config2, documents) {
55875
56237
  {
55876
56238
  kind: "Argument",
55877
56239
  name: {
55878
- kind: graphql8.Kind.NAME,
56240
+ kind: graphql9.Kind.NAME,
55879
56241
  value: "connection"
55880
56242
  },
55881
56243
  value: {
@@ -55925,7 +56287,7 @@ async function addListFragments(config2, documents) {
55925
56287
  const validDeletes = [
55926
56288
  ...new Set(
55927
56289
  Object.values(lists).map(({ type }) => {
55928
- if (!(type instanceof graphql8.GraphQLObjectType)) {
56290
+ if (!(type instanceof graphql9.GraphQLObjectType)) {
55929
56291
  return "";
55930
56292
  }
55931
56293
  if (config2.keyFieldsForType(type.name).length !== 1) {
@@ -55939,7 +56301,7 @@ async function addListFragments(config2, documents) {
55939
56301
  return;
55940
56302
  }
55941
56303
  const generatedDoc = {
55942
- kind: graphql8.Kind.DOCUMENT,
56304
+ kind: graphql9.Kind.DOCUMENT,
55943
56305
  definitions: Object.entries(lists).flatMap(
55944
56306
  ([name2, { selection: selection2, type }]) => {
55945
56307
  const schemaType = config2.schema.getType(type.name);
@@ -55947,7 +56309,7 @@ async function addListFragments(config2, documents) {
55947
56309
  throw new HoudiniError({ message: "Lists must have a selection" });
55948
56310
  }
55949
56311
  const fragmentSelection = {
55950
- kind: graphql8.Kind.SELECTION_SET,
56312
+ kind: graphql9.Kind.SELECTION_SET,
55951
56313
  selections: [...selection2.selections]
55952
56314
  };
55953
56315
  if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
@@ -55962,14 +56324,14 @@ async function addListFragments(config2, documents) {
55962
56324
  {
55963
56325
  name: {
55964
56326
  value: config2.listInsertFragment(name2),
55965
- kind: graphql8.Kind.NAME
56327
+ kind: graphql9.Kind.NAME
55966
56328
  },
55967
- kind: graphql8.Kind.FRAGMENT_DEFINITION,
56329
+ kind: graphql9.Kind.FRAGMENT_DEFINITION,
55968
56330
  selectionSet: fragmentSelection,
55969
56331
  typeCondition: {
55970
- kind: graphql8.Kind.NAMED_TYPE,
56332
+ kind: graphql9.Kind.NAMED_TYPE,
55971
56333
  name: {
55972
- kind: graphql8.Kind.NAME,
56334
+ kind: graphql9.Kind.NAME,
55973
56335
  value: type.name
55974
56336
  }
55975
56337
  }
@@ -55977,32 +56339,32 @@ async function addListFragments(config2, documents) {
55977
56339
  {
55978
56340
  name: {
55979
56341
  value: config2.listToggleFragment(name2),
55980
- kind: graphql8.Kind.NAME
56342
+ kind: graphql9.Kind.NAME
55981
56343
  },
55982
- kind: graphql8.Kind.FRAGMENT_DEFINITION,
56344
+ kind: graphql9.Kind.FRAGMENT_DEFINITION,
55983
56345
  selectionSet: fragmentSelection,
55984
56346
  typeCondition: {
55985
- kind: graphql8.Kind.NAMED_TYPE,
56347
+ kind: graphql9.Kind.NAMED_TYPE,
55986
56348
  name: {
55987
- kind: graphql8.Kind.NAME,
56349
+ kind: graphql9.Kind.NAME,
55988
56350
  value: type.name
55989
56351
  }
55990
56352
  }
55991
56353
  },
55992
56354
  {
55993
- kind: graphql8.Kind.FRAGMENT_DEFINITION,
56355
+ kind: graphql9.Kind.FRAGMENT_DEFINITION,
55994
56356
  name: {
55995
56357
  value: config2.listRemoveFragment(name2),
55996
- kind: graphql8.Kind.NAME
56358
+ kind: graphql9.Kind.NAME
55997
56359
  },
55998
56360
  selectionSet: {
55999
- kind: graphql8.Kind.SELECTION_SET,
56361
+ kind: graphql9.Kind.SELECTION_SET,
56000
56362
  selections: [...objectIdentificationSelection(config2, type)]
56001
56363
  },
56002
56364
  typeCondition: {
56003
- kind: graphql8.Kind.NAMED_TYPE,
56365
+ kind: graphql9.Kind.NAMED_TYPE,
56004
56366
  name: {
56005
- kind: graphql8.Kind.NAME,
56367
+ kind: graphql9.Kind.NAME,
56006
56368
  value: type.name
56007
56369
  }
56008
56370
  }
@@ -56011,14 +56373,14 @@ async function addListFragments(config2, documents) {
56011
56373
  }
56012
56374
  ).concat(
56013
56375
  ...validDeletes.map((typeName) => ({
56014
- kind: graphql8.Kind.DIRECTIVE_DEFINITION,
56376
+ kind: graphql9.Kind.DIRECTIVE_DEFINITION,
56015
56377
  name: {
56016
- kind: graphql8.Kind.NAME,
56378
+ kind: graphql9.Kind.NAME,
56017
56379
  value: config2.listDeleteDirective(typeName)
56018
56380
  },
56019
56381
  locations: [
56020
56382
  {
56021
- kind: graphql8.Kind.NAME,
56383
+ kind: graphql9.Kind.NAME,
56022
56384
  value: "FIELD"
56023
56385
  }
56024
56386
  ],
@@ -56026,8 +56388,8 @@ async function addListFragments(config2, documents) {
56026
56388
  }))
56027
56389
  )
56028
56390
  };
56029
- config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql8.print).join("\n\n");
56030
- config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql8.print).join("\n\n");
56391
+ config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql9.print).join("\n\n");
56392
+ config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql9.print).join("\n\n");
56031
56393
  documents.push({
56032
56394
  name: "generated::lists",
56033
56395
  kind: "HoudiniFragment" /* Fragment */,
@@ -56112,11 +56474,11 @@ var nodeNotDefinedMessage = (config2) => `Looks like you are trying to use the $
56112
56474
  For more information, visit this link: ${siteURL}/guides/pagination`;
56113
56475
 
56114
56476
  // src/codegen/generators/artifacts/fieldKey.ts
56115
- var graphql9 = __toESM(require_graphql2(), 1);
56477
+ var graphql10 = __toESM(require_graphql2(), 1);
56116
56478
  function fieldKey(config2, field) {
56117
56479
  const attributeName = field.alias?.value || field.name.value;
56118
- const printed = graphql9.print(field);
56119
- const secondParse = graphql9.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
56480
+ const printed = graphql10.print(field);
56481
+ const secondParse = graphql10.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
56120
56482
  const paginated = !!field.directives?.find(
56121
56483
  (directive) => directive.name.value === config2.paginateDirective
56122
56484
  );
@@ -56154,7 +56516,7 @@ function selection({
56154
56516
  path: path2 = [],
56155
56517
  includeFragments,
56156
56518
  document,
56157
- markEdges
56519
+ inConnection
56158
56520
  }) {
56159
56521
  let object = {};
56160
56522
  const typeMap = {};
@@ -56211,8 +56573,8 @@ function selection({
56211
56573
  const typeConditionName = field.typeCondition.name.value;
56212
56574
  const typeCondition = config2.schema.getType(typeConditionName);
56213
56575
  const possibleTypes = [];
56214
- if (!graphql10.isAbstractType(typeCondition)) {
56215
- } else if (graphql10.isAbstractType(parentType)) {
56576
+ if (!graphql11.isAbstractType(typeCondition)) {
56577
+ } else if (graphql11.isAbstractType(parentType)) {
56216
56578
  const possibleParentTypes = config2.schema.getPossibleTypes(parentType).map((type) => type.name);
56217
56579
  for (const possible of config2.schema.getPossibleTypes(typeCondition)) {
56218
56580
  if (possibleParentTypes.includes(possible.name)) {
@@ -56260,7 +56622,7 @@ function selection({
56260
56622
  } else {
56261
56623
  let typeRef = type.getFields()[field.name.value].type;
56262
56624
  fieldType = getRootType(typeRef);
56263
- nullable = !graphql10.isNonNullType(typeRef);
56625
+ nullable = !graphql11.isNonNullType(typeRef);
56264
56626
  }
56265
56627
  const typeName = fieldType.toString();
56266
56628
  const pathSoFar = path2.concat(attributeName);
@@ -56296,14 +56658,23 @@ function selection({
56296
56658
  (directive) => directive.name.value === config2.paginateDirective
56297
56659
  );
56298
56660
  if (paginated && document.refetch && document.refetch.method === "offset") {
56299
- fieldObj.update = document.refetch.update;
56661
+ fieldObj.updates = ["append" /* append */];
56300
56662
  }
56301
- if (attributeName === "edges" && markEdges && document.refetch) {
56302
- fieldObj.update = document.refetch.update;
56303
- markEdges = "";
56663
+ let continueConnection = inConnection;
56664
+ if ([
56665
+ "edges",
56666
+ "endCursor",
56667
+ "startCursor",
56668
+ "hasNextPage",
56669
+ "hasPreviousPage"
56670
+ ].includes(attributeName) && inConnection && document.refetch) {
56671
+ fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
56672
+ }
56673
+ if (attributeName === "node" && inConnection) {
56674
+ continueConnection = false;
56304
56675
  }
56305
56676
  if (field.selectionSet) {
56306
- const edgesMark = paginated && document.refetch?.method === "cursor" ? document.refetch.update : markEdges;
56677
+ const connectionState = paginated && document.refetch?.method === "cursor" || continueConnection;
56307
56678
  fieldObj.selection = selection({
56308
56679
  config: config2,
56309
56680
  filepath,
@@ -56313,7 +56684,7 @@ function selection({
56313
56684
  path: pathSoFar,
56314
56685
  includeFragments,
56315
56686
  document,
56316
- markEdges: edgesMark
56687
+ inConnection: connectionState
56317
56688
  });
56318
56689
  }
56319
56690
  if (field.arguments?.length && fieldObj.list) {
@@ -56325,7 +56696,7 @@ function selection({
56325
56696
  {}
56326
56697
  );
56327
56698
  }
56328
- if (graphql10.isInterfaceType(fieldType) || graphql10.isUnionType(fieldType)) {
56699
+ if (graphql11.isInterfaceType(fieldType) || graphql11.isUnionType(fieldType)) {
56329
56700
  fieldObj.abstract = true;
56330
56701
  }
56331
56702
  object.fields = {
@@ -56382,7 +56753,7 @@ function artifactGenerator(stats) {
56382
56753
  return async function(config2, docs) {
56383
56754
  const filterTypes = {};
56384
56755
  for (const doc of docs) {
56385
- graphql11.visit(doc.document, {
56756
+ graphql12.visit(doc.document, {
56386
56757
  Directive(node, _, __, ___, ancestors) {
56387
56758
  if (node.name.value !== config2.listDirective) {
56388
56759
  return;
@@ -56441,7 +56812,7 @@ function artifactGenerator(stats) {
56441
56812
  return;
56442
56813
  }
56443
56814
  const usedVariableNames = /* @__PURE__ */ new Set();
56444
- let documentWithoutInternalDirectives = graphql11.visit(document, {
56815
+ let documentWithoutInternalDirectives = graphql12.visit(document, {
56445
56816
  Directive(node) {
56446
56817
  if (config2.isInternalDirective(node)) {
56447
56818
  return null;
@@ -56454,7 +56825,7 @@ function artifactGenerator(stats) {
56454
56825
  }
56455
56826
  }
56456
56827
  });
56457
- let documentWithoutExtraVariables = graphql11.visit(
56828
+ let documentWithoutExtraVariables = graphql12.visit(
56458
56829
  documentWithoutInternalDirectives,
56459
56830
  {
56460
56831
  VariableDefinition(variableDefinitionNode) {
@@ -56465,13 +56836,13 @@ function artifactGenerator(stats) {
56465
56836
  }
56466
56837
  }
56467
56838
  );
56468
- let rawString = graphql11.print(documentWithoutExtraVariables);
56839
+ let rawString = graphql12.print(documentWithoutExtraVariables);
56469
56840
  let docKind = doc.kind;
56470
56841
  const operations = document.definitions.filter(
56471
- ({ kind }) => kind === graphql11.Kind.OPERATION_DEFINITION
56842
+ ({ kind }) => kind === graphql12.Kind.OPERATION_DEFINITION
56472
56843
  );
56473
56844
  const fragments = document.definitions.filter(
56474
- ({ kind }) => kind === graphql11.Kind.FRAGMENT_DEFINITION
56845
+ ({ kind }) => kind === graphql12.Kind.FRAGMENT_DEFINITION
56475
56846
  );
56476
56847
  let rootType = "";
56477
56848
  let selectionSet;
@@ -56504,7 +56875,13 @@ function artifactGenerator(stats) {
56504
56875
  rootType = matchingFragment.typeCondition.name.value;
56505
56876
  selectionSet = matchingFragment.selectionSet;
56506
56877
  }
56507
- const inputs = operations[0]?.variableDefinitions;
56878
+ let inputs = operations[0]?.variableDefinitions;
56879
+ let directive = fragments[0]?.directives?.find(
56880
+ (directive2) => directive2.name.value === config2.argumentsDirective
56881
+ );
56882
+ if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
56883
+ inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
56884
+ }
56508
56885
  const mergedSelection = flattenSelections({
56509
56886
  config: config2,
56510
56887
  filepath: doc.filename,
@@ -56565,7 +56942,7 @@ function artifactGenerator(stats) {
56565
56942
  }
56566
56943
  if (docKind === "HoudiniQuery") {
56567
56944
  const cacheDirective = operations[0].directives?.find(
56568
- (directive) => directive.name.value === config2.cacheDirective
56945
+ (directive2) => directive2.name.value === config2.cacheDirective
56569
56946
  );
56570
56947
  if (cacheDirective) {
56571
56948
  const args = cacheDirective.arguments?.reduce(
@@ -56781,19 +57158,19 @@ async function generatePluginRuntime(config2, plugin) {
56781
57158
  );
56782
57159
  }
56783
57160
 
56784
- // src/codegen/generators/typescript/index.ts
56785
- var recast12 = __toESM(require_main2(), 1);
57161
+ // src/codegen/generators/typescript/documentTypes.ts
57162
+ var recast11 = __toESM(require_main2(), 1);
56786
57163
 
56787
57164
  // src/codegen/generators/typescript/addReferencedInputTypes.ts
56788
- var graphql14 = __toESM(require_graphql2(), 1);
57165
+ var graphql15 = __toESM(require_graphql2(), 1);
56789
57166
  var recast9 = __toESM(require_main2(), 1);
56790
57167
 
56791
57168
  // src/codegen/generators/typescript/typeReference.ts
56792
- var graphql13 = __toESM(require_graphql2(), 1);
57169
+ var graphql14 = __toESM(require_graphql2(), 1);
56793
57170
  var recast8 = __toESM(require_main2(), 1);
56794
57171
 
56795
57172
  // src/codegen/generators/typescript/types.ts
56796
- var graphql12 = __toESM(require_graphql2(), 1);
57173
+ var graphql13 = __toESM(require_graphql2(), 1);
56797
57174
  var recast7 = __toESM(require_main2(), 1);
56798
57175
  var AST7 = recast7.types.builders;
56799
57176
  function readonlyProperty(prop, enable = true) {
@@ -56824,336 +57201,89 @@ function scalarPropertyValue(config2, missingScalars, target) {
56824
57201
  return AST7.tsBooleanKeyword();
56825
57202
  }
56826
57203
  case "ID": {
56827
- return AST7.tsStringKeyword();
56828
- }
56829
- default: {
56830
- if (graphql12.isNonNullType(target) && "ofType" in target) {
56831
- return scalarPropertyValue(
56832
- config2,
56833
- missingScalars,
56834
- target.ofType
56835
- );
56836
- }
56837
- if (config2.scalars?.[target.name]) {
56838
- return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
56839
- }
56840
- missingScalars.add(target.name);
56841
- return AST7.tsAnyKeyword();
56842
- }
56843
- }
56844
- }
56845
-
56846
- // src/codegen/generators/typescript/typeReference.ts
56847
- var AST8 = recast8.types.builders;
56848
- function tsTypeReference(config2, missingScalars, definition) {
56849
- const { type, wrappers } = unwrapType(config2, definition.type);
56850
- let result;
56851
- if (graphql13.isScalarType(type)) {
56852
- result = scalarPropertyValue(config2, missingScalars, type);
56853
- } else {
56854
- result = AST8.tsTypeReference(AST8.identifier(type.name));
56855
- }
56856
- for (const toWrap of wrappers) {
56857
- if (toWrap === "NonNull" /* NonNull */) {
56858
- continue;
56859
- } else if (toWrap === "Nullable" /* Nullable */) {
56860
- result = nullableField(result, true);
56861
- } else if (toWrap === "List" /* List */) {
56862
- result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
56863
- }
56864
- }
56865
- return result;
56866
- }
56867
-
56868
- // src/codegen/generators/typescript/addReferencedInputTypes.ts
56869
- var AST9 = recast9.types.builders;
56870
- function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
56871
- const { type } = unwrapType(config2, rootType);
56872
- if (graphql14.isScalarType(type)) {
56873
- return;
56874
- }
56875
- if (visitedTypes.has(type.name)) {
56876
- return;
56877
- }
56878
- if (graphql14.isUnionType(type)) {
56879
- throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
56880
- }
56881
- visitedTypes.add(type.name);
56882
- if (graphql14.isEnumType(type)) {
56883
- ensureImports({
56884
- config: config2,
56885
- body,
56886
- import: [type.name],
56887
- sourceModule: "$houdini/graphql/enums",
56888
- importKind: "type"
56889
- });
56890
- return;
56891
- }
56892
- const members = [];
56893
- for (const field of Object.values(type.getFields())) {
56894
- addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
56895
- members.push(
56896
- AST9.tsPropertySignature(
56897
- AST9.identifier(field.name),
56898
- AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
56899
- graphql14.isNullableType(field.type)
56900
- )
56901
- );
56902
- }
56903
- body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
56904
- }
56905
-
56906
- // src/codegen/generators/typescript/imperativeCache.ts
56907
- var graphql15 = __toESM(require_graphql2(), 1);
56908
- var recast10 = __toESM(require_main2(), 1);
56909
- var AST10 = recast10.types.builders;
56910
- async function imperativeCacheTypef(config2, docs) {
56911
- const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
56912
- const body = [];
56913
- const declaration = AST10.tsTypeAliasDeclaration(
56914
- AST10.identifier(CacheTypeDefName),
56915
- AST10.tsTypeLiteral([
56916
- AST10.tsPropertySignature(
56917
- AST10.identifier("types"),
56918
- AST10.tsTypeAnnotation(typeDefinitions(config2, body))
56919
- ),
56920
- AST10.tsPropertySignature(
56921
- AST10.identifier("lists"),
56922
- AST10.tsTypeAnnotation(listDefinitions(config2, docs))
56923
- )
56924
- ])
56925
- );
56926
- declaration.declare = true;
56927
- const importRecord = AST10.importDeclaration(
56928
- [AST10.importSpecifier(AST10.identifier("Record"))],
56929
- AST10.stringLiteral("./public/record")
56930
- );
56931
- importRecord.importKind = "type";
56932
- await fs_exports.writeFile(
56933
- target,
56934
- recast10.prettyPrint(
56935
- AST10.program([importRecord, ...body, AST10.exportNamedDeclaration(declaration)])
56936
- ).code
56937
- );
56938
- }
56939
- function typeDefinitions(config2, body) {
56940
- const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
56941
- const visitedTypes = /* @__PURE__ */ new Set();
56942
- const types14 = Object.values(config2.schema.getTypeMap()).filter(
56943
- (type) => !graphql15.isAbstractType(type) && !graphql15.isScalarType(type) && !graphql15.isEnumType(type) && !graphql15.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
56944
- );
56945
- return AST10.tsTypeLiteral(
56946
- types14.map((type) => {
56947
- let typeName = type.name;
56948
- if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
56949
- typeName = "__ROOT__";
56950
- }
56951
- let idFields = AST10.tsNeverKeyword();
56952
- const keys = keyFieldsForType(config2.configFile, type.name);
56953
- if (graphql15.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
56954
- idFields = AST10.tsTypeLiteral(
56955
- keys.map((key) => {
56956
- const fieldType = type.getFields()[key];
56957
- const unwrapped = unwrapType(config2, fieldType.type);
56958
- return AST10.tsPropertySignature(
56959
- AST10.identifier(key),
56960
- AST10.tsTypeAnnotation(
56961
- scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
56962
- )
56963
- );
56964
- })
56965
- );
56966
- } else if (typeName === "__ROOT__") {
56967
- idFields = AST10.tsTypeLiteral([]);
56968
- }
56969
- let fields = AST10.tsTypeLiteral([]);
56970
- if (graphql15.isObjectType(type)) {
56971
- fields = AST10.tsTypeLiteral(
56972
- Object.entries(type.getFields()).map(
56973
- ([key, fieldType]) => {
56974
- const unwrapped = unwrapType(config2, fieldType.type);
56975
- let typeOptions = AST10.tsUnionType([]);
56976
- if (graphql15.isScalarType(unwrapped.type)) {
56977
- typeOptions.types.push(
56978
- scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
56979
- );
56980
- } else if (graphql15.isEnumType(unwrapped.type)) {
56981
- typeOptions.types.push(
56982
- AST10.tsTypeReference(AST10.identifier(unwrapped.type.name))
56983
- );
56984
- } else if (!graphql15.isAbstractType(unwrapped.type)) {
56985
- typeOptions.types.push(record(unwrapped.type.name));
56986
- } else {
56987
- typeOptions.types.push(
56988
- ...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
56989
- );
56990
- }
56991
- for (const wrapper of unwrapped.wrappers) {
56992
- if (wrapper === "Nullable" /* Nullable */) {
56993
- typeOptions = AST10.tsParenthesizedType(
56994
- AST10.tsUnionType([typeOptions, AST10.tsNullKeyword()])
56995
- );
56996
- } else if (wrapper === "List" /* List */) {
56997
- typeOptions = AST10.tsArrayType(
56998
- AST10.tsParenthesizedType(typeOptions)
56999
- );
57000
- }
57001
- }
57002
- if (typeOptions.type === "TSParenthesizedType") {
57003
- typeOptions = typeOptions.typeAnnotation;
57004
- }
57005
- let args = AST10.tsNeverKeyword();
57006
- if (fieldType.args?.length > 0) {
57007
- args = AST10.tsTypeLiteral(
57008
- fieldType.args.map((arg) => {
57009
- addReferencedInputTypes(
57010
- config2,
57011
- "",
57012
- body,
57013
- visitedTypes,
57014
- /* @__PURE__ */ new Set(),
57015
- arg.type
57016
- );
57017
- const prop = AST10.tsPropertySignature(
57018
- AST10.identifier(arg.name),
57019
- AST10.tsTypeAnnotation(
57020
- tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
57021
- )
57022
- );
57023
- const unwrapped2 = unwrapType(config2, arg.type);
57024
- prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
57025
- return prop;
57026
- })
57027
- );
57028
- }
57029
- return AST10.tsPropertySignature(
57030
- AST10.identifier(key),
57031
- AST10.tsTypeAnnotation(
57032
- AST10.tsTypeLiteral([
57033
- AST10.tsPropertySignature(
57034
- AST10.identifier("type"),
57035
- AST10.tsTypeAnnotation(typeOptions)
57036
- ),
57037
- AST10.tsPropertySignature(
57038
- AST10.identifier("args"),
57039
- AST10.tsTypeAnnotation(args)
57040
- )
57041
- ])
57042
- )
57043
- );
57044
- }
57045
- )
57204
+ return AST7.tsStringKeyword();
57205
+ }
57206
+ default: {
57207
+ if (graphql13.isNonNullType(target) && "ofType" in target) {
57208
+ return scalarPropertyValue(
57209
+ config2,
57210
+ missingScalars,
57211
+ target.ofType
57046
57212
  );
57047
57213
  }
57048
- return AST10.tsPropertySignature(
57049
- AST10.identifier(typeName),
57050
- AST10.tsTypeAnnotation(
57051
- AST10.tsTypeLiteral([
57052
- AST10.tsPropertySignature(
57053
- AST10.identifier("idFields"),
57054
- AST10.tsTypeAnnotation(idFields)
57055
- ),
57056
- AST10.tsPropertySignature(
57057
- AST10.identifier("fields"),
57058
- AST10.tsTypeAnnotation(fields)
57059
- )
57060
- ])
57061
- )
57062
- );
57063
- })
57064
- );
57065
- }
57066
- function listDefinitions(config2, docs) {
57067
- const lists = [];
57068
- const visitedLists = /* @__PURE__ */ new Set();
57069
- for (const doc of docs) {
57070
- graphql15.visit(doc.document, {
57071
- Directive(node, key, parent, path2, ancestors) {
57072
- if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
57073
- return;
57074
- }
57075
- const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
57076
- const nameValue = nameArg?.value?.value || "";
57077
- if (!nameValue || visitedLists.has(nameValue)) {
57078
- return;
57079
- }
57080
- visitedLists.add(nameValue);
57081
- const parentType = parentTypeFromAncestors(
57082
- config2.schema,
57083
- doc.filename,
57084
- ancestors.slice(0, -1)
57085
- );
57086
- const targetField = ancestors[ancestors.length - 1];
57087
- const targetFieldDefinition = parentType.getFields()[targetField.name.value];
57088
- const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
57089
- const possibleTypes = [];
57090
- if (graphql15.isAbstractType(listType)) {
57091
- possibleTypes.push(
57092
- ...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
57093
- );
57094
- } else {
57095
- possibleTypes.push(listType.name);
57096
- }
57097
- lists.push(
57098
- AST10.tsPropertySignature(
57099
- AST10.identifier(nameValue),
57100
- AST10.tsTypeAnnotation(
57101
- AST10.tsTypeLiteral([
57102
- AST10.tsPropertySignature(
57103
- AST10.identifier("types"),
57104
- AST10.tsTypeAnnotation(
57105
- AST10.tsUnionType(
57106
- possibleTypes.map(
57107
- (possible) => AST10.tsLiteralType(AST10.stringLiteral(possible))
57108
- )
57109
- )
57110
- )
57111
- ),
57112
- AST10.tsPropertySignature(
57113
- AST10.identifier("filters"),
57114
- AST10.tsTypeAnnotation(
57115
- targetFieldDefinition.args.length === 0 ? AST10.tsNeverKeyword() : AST10.tsTypeLiteral(
57116
- targetFieldDefinition.args.map((arg) => {
57117
- const argDef = AST10.tsPropertySignature(
57118
- AST10.identifier(arg.name),
57119
- AST10.tsTypeAnnotation(
57120
- tsTypeReference(
57121
- config2,
57122
- /* @__PURE__ */ new Set(),
57123
- arg
57124
- )
57125
- )
57126
- );
57127
- argDef.optional = true;
57128
- return argDef;
57129
- })
57130
- )
57131
- )
57132
- )
57133
- ])
57134
- )
57135
- )
57136
- );
57214
+ if (config2.scalars?.[target.name]) {
57215
+ return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
57137
57216
  }
57138
- });
57217
+ missingScalars.add(target.name);
57218
+ return AST7.tsAnyKeyword();
57219
+ }
57139
57220
  }
57140
- return AST10.tsTypeLiteral(lists);
57141
57221
  }
57142
- var CacheTypeDefName = "CacheTypeDef";
57143
- function record(name2) {
57144
- return AST10.tsTypeReference(
57145
- AST10.identifier("Record"),
57146
- AST10.tsTypeParameterInstantiation([
57147
- AST10.tsTypeReference(AST10.identifier(CacheTypeDefName)),
57148
- AST10.tsLiteralType(AST10.stringLiteral(name2))
57149
- ])
57150
- );
57222
+
57223
+ // src/codegen/generators/typescript/typeReference.ts
57224
+ var AST8 = recast8.types.builders;
57225
+ function tsTypeReference(config2, missingScalars, definition) {
57226
+ const { type, wrappers } = unwrapType(config2, definition.type);
57227
+ let result;
57228
+ if (graphql14.isScalarType(type)) {
57229
+ result = scalarPropertyValue(config2, missingScalars, type);
57230
+ } else {
57231
+ result = AST8.tsTypeReference(AST8.identifier(type.name));
57232
+ }
57233
+ for (const toWrap of wrappers) {
57234
+ if (toWrap === "NonNull" /* NonNull */) {
57235
+ continue;
57236
+ } else if (toWrap === "Nullable" /* Nullable */) {
57237
+ result = nullableField(result, true);
57238
+ } else if (toWrap === "List" /* List */) {
57239
+ result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
57240
+ }
57241
+ }
57242
+ return result;
57243
+ }
57244
+
57245
+ // src/codegen/generators/typescript/addReferencedInputTypes.ts
57246
+ var AST9 = recast9.types.builders;
57247
+ function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
57248
+ const { type } = unwrapType(config2, rootType);
57249
+ if (graphql15.isScalarType(type)) {
57250
+ return;
57251
+ }
57252
+ if (visitedTypes.has(type.name)) {
57253
+ return;
57254
+ }
57255
+ if (graphql15.isUnionType(type)) {
57256
+ throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
57257
+ }
57258
+ visitedTypes.add(type.name);
57259
+ if (graphql15.isEnumType(type)) {
57260
+ ensureImports({
57261
+ config: config2,
57262
+ body,
57263
+ import: [type.name],
57264
+ sourceModule: "$houdini/graphql/enums",
57265
+ importKind: "type"
57266
+ });
57267
+ return;
57268
+ }
57269
+ const members = [];
57270
+ for (const field of Object.values(type.getFields())) {
57271
+ addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
57272
+ members.push(
57273
+ AST9.tsPropertySignature(
57274
+ AST9.identifier(field.name),
57275
+ AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
57276
+ graphql15.isNullableType(field.type)
57277
+ )
57278
+ );
57279
+ }
57280
+ body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
57151
57281
  }
57152
57282
 
57153
57283
  // src/codegen/generators/typescript/inlineType.ts
57154
57284
  var graphql16 = __toESM(require_graphql2(), 1);
57155
- var recast11 = __toESM(require_main2(), 1);
57156
- var AST11 = recast11.types.builders;
57285
+ var recast10 = __toESM(require_main2(), 1);
57286
+ var AST10 = recast10.types.builders;
57157
57287
  var fragmentKey = "$fragments";
57158
57288
  function inlineType({
57159
57289
  config: config2,
@@ -57182,7 +57312,7 @@ function inlineType({
57182
57312
  });
57183
57313
  visitedTypes.add(type.name);
57184
57314
  }
57185
- result = AST11.tsTypeReference(AST11.identifier(type.name));
57315
+ result = AST10.tsTypeReference(AST10.identifier(type.name));
57186
57316
  } else if (selections) {
57187
57317
  const rootObj = type;
57188
57318
  const inlineFragments = {};
@@ -57233,7 +57363,7 @@ function inlineType({
57233
57363
  selectedFields.push(selection2);
57234
57364
  }
57235
57365
  }
57236
- result = AST11.tsTypeLiteral([
57366
+ result = AST10.tsTypeLiteral([
57237
57367
  ...(selectedFields || []).filter(
57238
57368
  (field) => field.kind === "Field"
57239
57369
  ).map((selection2) => {
@@ -57253,9 +57383,9 @@ function inlineType({
57253
57383
  allOptional
57254
57384
  });
57255
57385
  const prop = readonlyProperty(
57256
- AST11.tsPropertySignature(
57257
- AST11.identifier(attributeName),
57258
- AST11.tsTypeAnnotation(attributeType)
57386
+ AST10.tsPropertySignature(
57387
+ AST10.identifier(attributeName),
57388
+ AST10.tsTypeAnnotation(attributeType)
57259
57389
  ),
57260
57390
  allowReadonly
57261
57391
  );
@@ -57269,15 +57399,15 @@ function inlineType({
57269
57399
  if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
57270
57400
  result.members.push(
57271
57401
  readonlyProperty(
57272
- AST11.tsPropertySignature(
57273
- AST11.identifier(fragmentKey),
57274
- AST11.tsTypeAnnotation(
57275
- AST11.tsTypeLiteral(
57402
+ AST10.tsPropertySignature(
57403
+ AST10.identifier(fragmentKey),
57404
+ AST10.tsTypeAnnotation(
57405
+ AST10.tsTypeLiteral(
57276
57406
  (fragmentSpreads || []).map(
57277
- (fragmentSpread) => AST11.tsPropertySignature(
57278
- AST11.identifier(fragmentSpread.name.value),
57279
- AST11.tsTypeAnnotation(
57280
- AST11.tsLiteralType(AST11.booleanLiteral(true))
57407
+ (fragmentSpread) => AST10.tsPropertySignature(
57408
+ AST10.identifier(fragmentSpread.name.value),
57409
+ AST10.tsTypeAnnotation(
57410
+ AST10.tsLiteralType(AST10.booleanLiteral(true))
57281
57411
  )
57282
57412
  )
57283
57413
  )
@@ -57323,9 +57453,9 @@ function inlineType({
57323
57453
  }
57324
57454
  objectType.members.push(
57325
57455
  readonlyProperty(
57326
- AST11.tsPropertySignature(
57327
- AST11.identifier("__typename"),
57328
- AST11.tsTypeAnnotation(AST11.tsLiteralType(AST11.stringLiteral(typeName)))
57456
+ AST10.tsPropertySignature(
57457
+ AST10.identifier("__typename"),
57458
+ AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
57329
57459
  ),
57330
57460
  allowReadonly
57331
57461
  )
@@ -57336,8 +57466,8 @@ function inlineType({
57336
57466
  if (Object.keys(inlineFragmentSelections).length > 0) {
57337
57467
  let selectionTypes = Object.entries(inlineFragmentSelections).map(
57338
57468
  ([typeName, { type: type2, tsType }]) => {
57339
- return AST11.tsParenthesizedType(
57340
- AST11.tsIntersectionType(
57469
+ return AST10.tsParenthesizedType(
57470
+ AST10.tsIntersectionType(
57341
57471
  [tsType].flatMap((type3) => {
57342
57472
  if (type3.type === "TSUnionType") {
57343
57473
  return type3.types.filter(
@@ -57350,9 +57480,9 @@ function inlineType({
57350
57480
  );
57351
57481
  }
57352
57482
  );
57353
- result = AST11.tsIntersectionType([
57483
+ result = AST10.tsIntersectionType([
57354
57484
  result,
57355
- AST11.tsParenthesizedType(AST11.tsUnionType(selectionTypes))
57485
+ AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
57356
57486
  ]);
57357
57487
  }
57358
57488
  } else {
@@ -57364,7 +57494,7 @@ function inlineType({
57364
57494
  } else if (toWrap === "NonNull" /* NonNull */) {
57365
57495
  continue;
57366
57496
  } else if (toWrap === "List" /* List */) {
57367
- result = AST11.tsArrayType(AST11.tsParenthesizedType(result));
57497
+ result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
57368
57498
  }
57369
57499
  }
57370
57500
  return result;
@@ -57408,9 +57538,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
57408
57538
  return { field, type: selectionType };
57409
57539
  }
57410
57540
 
57411
- // src/codegen/generators/typescript/index.ts
57412
- var AST12 = recast12.types.builders;
57413
- async function typescriptGenerator(config2, docs) {
57541
+ // src/codegen/generators/typescript/documentTypes.ts
57542
+ var AST11 = recast11.types.builders;
57543
+ async function generateDocumentTypes(config2, docs) {
57414
57544
  const typePaths = [];
57415
57545
  const fragmentDefinitions = {};
57416
57546
  for (const document of docs) {
@@ -57427,7 +57557,7 @@ async function typescriptGenerator(config2, docs) {
57427
57557
  return;
57428
57558
  }
57429
57559
  const typeDefPath = config2.artifactTypePath(originalDocument);
57430
- const program = AST12.program([]);
57560
+ const program = AST11.program([]);
57431
57561
  const visitedTypes = /* @__PURE__ */ new Set();
57432
57562
  let definition = originalDocument.definitions.find(
57433
57563
  (def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
@@ -57460,21 +57590,21 @@ async function typescriptGenerator(config2, docs) {
57460
57590
  missingScalars
57461
57591
  );
57462
57592
  }
57463
- await fs_exports.writeFile(typeDefPath, recast12.print(program).code);
57593
+ await fs_exports.writeFile(typeDefPath, recast11.print(program).code);
57464
57594
  typePaths.push(typeDefPath);
57465
57595
  })
57466
57596
  );
57467
- const typeIndex = AST12.program(
57597
+ const typeIndex = AST11.program(
57468
57598
  typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
57469
- return AST12.exportAllDeclaration(
57470
- AST12.literal(
57599
+ return AST11.exportAllDeclaration(
57600
+ AST11.literal(
57471
57601
  "./" + path_exports.relative(path_exports.resolve(config2.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
57472
57602
  ),
57473
57603
  null
57474
57604
  );
57475
57605
  }).concat([
57476
- AST12.exportAllDeclaration(AST12.literal("./runtime"), null),
57477
- AST12.exportAllDeclaration(AST12.literal("./graphql"), null)
57606
+ AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
57607
+ AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
57478
57608
  ])
57479
57609
  );
57480
57610
  const export_default_as = ({ module, as }) => `
@@ -57483,7 +57613,7 @@ export { default as ${as} } from "${module}"
57483
57613
  const export_star_from = ({ module }) => `
57484
57614
  export * from "${module}"
57485
57615
  `;
57486
- let indexContent = recast12.print(typeIndex).code;
57616
+ let indexContent = recast11.print(typeIndex).code;
57487
57617
  for (const plugin of config2.plugins) {
57488
57618
  if (!plugin.index_file) {
57489
57619
  continue;
@@ -57504,7 +57634,6 @@ export * from "${module}"
57504
57634
  }
57505
57635
  }
57506
57636
  await fs_exports.writeFile(config2.typeIndexPath, indexContent);
57507
- await imperativeCacheTypef(config2, docs);
57508
57637
  if (missingScalars.size > 0) {
57509
57638
  console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
57510
57639
  ", "
@@ -57546,23 +57675,23 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57546
57675
  const optimisticTypeName = `${definition.name.value}$optimistic`;
57547
57676
  const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
57548
57677
  body.push(
57549
- AST12.exportNamedDeclaration(
57550
- AST12.tsTypeAliasDeclaration(
57551
- AST12.identifier(definition.name.value),
57552
- AST12.tsTypeLiteral([
57678
+ AST11.exportNamedDeclaration(
57679
+ AST11.tsTypeAliasDeclaration(
57680
+ AST11.identifier(definition.name.value),
57681
+ AST11.tsTypeLiteral([
57553
57682
  readonlyProperty(
57554
- AST12.tsPropertySignature(
57555
- AST12.stringLiteral("input"),
57556
- AST12.tsTypeAnnotation(AST12.tsTypeReference(AST12.identifier(inputTypeName)))
57683
+ AST11.tsPropertySignature(
57684
+ AST11.stringLiteral("input"),
57685
+ AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
57557
57686
  )
57558
57687
  ),
57559
57688
  readonlyProperty(
57560
- AST12.tsPropertySignature(
57561
- AST12.stringLiteral("result"),
57562
- AST12.tsTypeAnnotation(
57563
- definition.operation === "mutation" ? AST12.tsTypeReference(AST12.identifier(shapeTypeName)) : AST12.tsUnionType([
57564
- AST12.tsTypeReference(AST12.identifier(shapeTypeName)),
57565
- AST12.tsUndefinedKeyword()
57689
+ AST11.tsPropertySignature(
57690
+ AST11.stringLiteral("result"),
57691
+ AST11.tsTypeAnnotation(
57692
+ definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
57693
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
57694
+ AST11.tsUndefinedKeyword()
57566
57695
  ])
57567
57696
  )
57568
57697
  )
@@ -57570,9 +57699,9 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57570
57699
  ])
57571
57700
  )
57572
57701
  ),
57573
- AST12.exportNamedDeclaration(
57574
- AST12.tsTypeAliasDeclaration(
57575
- AST12.identifier(shapeTypeName),
57702
+ AST11.exportNamedDeclaration(
57703
+ AST11.tsTypeAliasDeclaration(
57704
+ AST11.identifier(shapeTypeName),
57576
57705
  inlineType({
57577
57706
  config: config2,
57578
57707
  filepath,
@@ -57600,15 +57729,15 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57600
57729
  );
57601
57730
  }
57602
57731
  body.push(
57603
- AST12.exportNamedDeclaration(
57604
- AST12.tsTypeAliasDeclaration(
57605
- AST12.identifier(inputTypeName),
57606
- AST12.tsTypeLiteral(
57732
+ AST11.exportNamedDeclaration(
57733
+ AST11.tsTypeAliasDeclaration(
57734
+ AST11.identifier(inputTypeName),
57735
+ AST11.tsTypeLiteral(
57607
57736
  (definition.variableDefinitions || []).map(
57608
57737
  (definition2) => {
57609
- return AST12.tsPropertySignature(
57610
- AST12.identifier(definition2.variable.name.value),
57611
- AST12.tsTypeAnnotation(
57738
+ return AST11.tsPropertySignature(
57739
+ AST11.identifier(definition2.variable.name.value),
57740
+ AST11.tsTypeAnnotation(
57612
57741
  tsTypeReference(config2, missingScalars, definition2)
57613
57742
  ),
57614
57743
  definition2.type.kind !== "NonNullType"
@@ -57621,16 +57750,16 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
57621
57750
  );
57622
57751
  } else {
57623
57752
  body.push(
57624
- AST12.exportNamedDeclaration(
57625
- AST12.tsTypeAliasDeclaration(AST12.identifier(inputTypeName), AST12.tsNullKeyword())
57753
+ AST11.exportNamedDeclaration(
57754
+ AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
57626
57755
  )
57627
57756
  );
57628
57757
  }
57629
57758
  if (definition.operation === "mutation") {
57630
57759
  body.push(
57631
- AST12.exportNamedDeclaration(
57632
- AST12.tsTypeAliasDeclaration(
57633
- AST12.identifier(optimisticTypeName),
57760
+ AST11.exportNamedDeclaration(
57761
+ AST11.tsTypeAliasDeclaration(
57762
+ AST11.identifier(optimisticTypeName),
57634
57763
  inlineType({
57635
57764
  config: config2,
57636
57765
  filepath,
@@ -57656,65 +57785,463 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
57656
57785
  }
57657
57786
  const propTypeName = definition.name.value;
57658
57787
  const shapeTypeName = `${definition.name.value}$data`;
57788
+ const inputTypeName = `${definition.name.value}$input`;
57659
57789
  const type = config2.schema.getType(definition.typeCondition.name.value);
57660
57790
  if (!type) {
57661
57791
  throw new Error("Should not get here");
57662
57792
  }
57793
+ let extraExports = [];
57794
+ let directive = definition.directives?.find(
57795
+ (directive2) => directive2.name.value === config2.argumentsDirective
57796
+ );
57797
+ if (directive) {
57798
+ extraExports.push(
57799
+ AST11.exportNamedDeclaration(
57800
+ AST11.tsTypeAliasDeclaration(
57801
+ AST11.identifier(inputTypeName),
57802
+ AST11.tsTypeLiteral(
57803
+ (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
57804
+ (definition2) => {
57805
+ return AST11.tsPropertySignature(
57806
+ AST11.identifier(definition2.variable.name.value),
57807
+ AST11.tsTypeAnnotation(
57808
+ tsTypeReference(config2, missingScalars, definition2)
57809
+ ),
57810
+ definition2.type.kind !== "NonNullType"
57811
+ );
57812
+ }
57813
+ )
57814
+ )
57815
+ )
57816
+ )
57817
+ );
57818
+ }
57663
57819
  body.push(
57664
- AST12.exportNamedDeclaration(
57665
- AST12.tsTypeAliasDeclaration(
57666
- AST12.identifier(propTypeName),
57667
- AST12.tsTypeLiteral([
57820
+ ...extraExports,
57821
+ AST11.exportNamedDeclaration(
57822
+ AST11.tsTypeAliasDeclaration(
57823
+ AST11.identifier(propTypeName),
57824
+ AST11.tsTypeLiteral([
57668
57825
  readonlyProperty(
57669
- AST12.tsPropertySignature(
57670
- AST12.stringLiteral("shape"),
57671
- AST12.tsTypeAnnotation(
57672
- AST12.tsTypeReference(AST12.identifier(shapeTypeName))
57826
+ AST11.tsPropertySignature(
57827
+ AST11.stringLiteral("shape"),
57828
+ AST11.tsTypeAnnotation(
57829
+ AST11.tsTypeReference(AST11.identifier(shapeTypeName))
57673
57830
  ),
57674
57831
  true
57675
57832
  )
57676
57833
  ),
57677
57834
  readonlyProperty(
57678
- AST12.tsPropertySignature(
57679
- AST12.stringLiteral(fragmentKey),
57835
+ AST11.tsPropertySignature(
57836
+ AST11.stringLiteral(fragmentKey),
57837
+ AST11.tsTypeAnnotation(
57838
+ AST11.tsTypeLiteral([
57839
+ AST11.tsPropertySignature(
57840
+ AST11.stringLiteral(propTypeName),
57841
+ AST11.tsTypeAnnotation(
57842
+ AST11.tsLiteralType(AST11.booleanLiteral(true))
57843
+ )
57844
+ )
57845
+ ])
57846
+ )
57847
+ )
57848
+ )
57849
+ ])
57850
+ )
57851
+ ),
57852
+ AST11.exportNamedDeclaration(
57853
+ AST11.tsTypeAliasDeclaration(
57854
+ AST11.identifier(shapeTypeName),
57855
+ inlineType({
57856
+ config: config2,
57857
+ filepath,
57858
+ rootType: type,
57859
+ selections,
57860
+ root: true,
57861
+ allowReadonly: true,
57862
+ body,
57863
+ visitedTypes,
57864
+ missingScalars,
57865
+ includeFragments: true
57866
+ })
57867
+ )
57868
+ )
57869
+ );
57870
+ }
57871
+ }
57872
+
57873
+ // src/codegen/generators/typescript/imperativeTypeDef.ts
57874
+ var graphql17 = __toESM(require_graphql2(), 1);
57875
+ var recast12 = __toESM(require_main2(), 1);
57876
+ var AST12 = recast12.types.builders;
57877
+ async function imperativeCacheTypef(config2, docs) {
57878
+ const returnType = (doc) => config2.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
57879
+ config: config2,
57880
+ doc,
57881
+ ensure_import({ identifier, module }) {
57882
+ ensureImports({
57883
+ config: config2,
57884
+ body,
57885
+ sourceModule: module,
57886
+ import: [identifier]
57887
+ });
57888
+ }
57889
+ }) ?? "any";
57890
+ const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
57891
+ const body = [];
57892
+ const declaration = AST12.tsTypeAliasDeclaration(
57893
+ AST12.identifier(CacheTypeDefName),
57894
+ AST12.tsTypeLiteral([
57895
+ AST12.tsPropertySignature(
57896
+ AST12.identifier("types"),
57897
+ AST12.tsTypeAnnotation(typeDefinitions(config2, body, docs, returnType))
57898
+ ),
57899
+ AST12.tsPropertySignature(
57900
+ AST12.identifier("lists"),
57901
+ AST12.tsTypeAnnotation(listDefinitions(config2, docs))
57902
+ ),
57903
+ AST12.tsPropertySignature(
57904
+ AST12.identifier("queries"),
57905
+ AST12.tsTypeAnnotation(queryDefinitions(config2, body, docs, returnType))
57906
+ )
57907
+ ])
57908
+ );
57909
+ declaration.declare = true;
57910
+ const importRecord = AST12.importDeclaration(
57911
+ [AST12.importSpecifier(AST12.identifier("Record"))],
57912
+ AST12.stringLiteral("./public/record")
57913
+ );
57914
+ importRecord.importKind = "type";
57915
+ await fs_exports.writeFile(
57916
+ target,
57917
+ recast12.prettyPrint(
57918
+ AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
57919
+ ).code
57920
+ );
57921
+ }
57922
+ function typeDefinitions(config2, body, docs, returnType) {
57923
+ const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
57924
+ const visitedTypes = /* @__PURE__ */ new Set();
57925
+ const types14 = Object.values(config2.schema.getTypeMap()).filter(
57926
+ (type) => !graphql17.isAbstractType(type) && !graphql17.isScalarType(type) && !graphql17.isEnumType(type) && !graphql17.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
57927
+ );
57928
+ const fragmentMap = fragmentListMap(
57929
+ config2,
57930
+ types14.map((type) => type.name),
57931
+ body,
57932
+ docs,
57933
+ returnType
57934
+ );
57935
+ return AST12.tsTypeLiteral(
57936
+ types14.map((type) => {
57937
+ let typeName = type.name;
57938
+ if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
57939
+ typeName = "__ROOT__";
57940
+ }
57941
+ let idFields = AST12.tsNeverKeyword();
57942
+ const keys = keyFieldsForType(config2.configFile, type.name);
57943
+ if (graphql17.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
57944
+ idFields = AST12.tsTypeLiteral(
57945
+ keys.map((key) => {
57946
+ const fieldType = type.getFields()[key];
57947
+ const unwrapped = unwrapType(config2, fieldType.type);
57948
+ return AST12.tsPropertySignature(
57949
+ AST12.identifier(key),
57950
+ AST12.tsTypeAnnotation(
57951
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
57952
+ )
57953
+ );
57954
+ })
57955
+ );
57956
+ } else if (typeName === "__ROOT__") {
57957
+ idFields = AST12.tsTypeLiteral([]);
57958
+ }
57959
+ let fields = AST12.tsTypeLiteral([]);
57960
+ if (graphql17.isObjectType(type)) {
57961
+ fields = AST12.tsTypeLiteral(
57962
+ Object.entries(type.getFields()).map(
57963
+ ([key, fieldType]) => {
57964
+ const unwrapped = unwrapType(config2, fieldType.type);
57965
+ let typeOptions = AST12.tsUnionType([]);
57966
+ if (graphql17.isScalarType(unwrapped.type)) {
57967
+ typeOptions.types.push(
57968
+ scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
57969
+ );
57970
+ } else if (graphql17.isEnumType(unwrapped.type)) {
57971
+ typeOptions.types.push(
57972
+ AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
57973
+ );
57974
+ } else if (!graphql17.isAbstractType(unwrapped.type)) {
57975
+ typeOptions.types.push(record(unwrapped.type.name));
57976
+ } else {
57977
+ typeOptions.types.push(
57978
+ ...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
57979
+ );
57980
+ }
57981
+ for (const wrapper of unwrapped.wrappers) {
57982
+ if (wrapper === "Nullable" /* Nullable */) {
57983
+ typeOptions = AST12.tsParenthesizedType(
57984
+ AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
57985
+ );
57986
+ } else if (wrapper === "List" /* List */) {
57987
+ typeOptions = AST12.tsArrayType(
57988
+ AST12.tsParenthesizedType(typeOptions)
57989
+ );
57990
+ }
57991
+ }
57992
+ if (typeOptions.type === "TSParenthesizedType") {
57993
+ typeOptions = typeOptions.typeAnnotation;
57994
+ }
57995
+ let args = AST12.tsNeverKeyword();
57996
+ if (fieldType.args?.length > 0) {
57997
+ args = AST12.tsTypeLiteral(
57998
+ fieldType.args.map((arg) => {
57999
+ addReferencedInputTypes(
58000
+ config2,
58001
+ "",
58002
+ body,
58003
+ visitedTypes,
58004
+ /* @__PURE__ */ new Set(),
58005
+ arg.type
58006
+ );
58007
+ const prop = AST12.tsPropertySignature(
58008
+ AST12.identifier(arg.name),
58009
+ AST12.tsTypeAnnotation(
58010
+ tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
58011
+ )
58012
+ );
58013
+ const unwrapped2 = unwrapType(config2, arg.type);
58014
+ prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
58015
+ return prop;
58016
+ })
58017
+ );
58018
+ }
58019
+ return AST12.tsPropertySignature(
58020
+ AST12.identifier(key),
57680
58021
  AST12.tsTypeAnnotation(
57681
58022
  AST12.tsTypeLiteral([
57682
58023
  AST12.tsPropertySignature(
57683
- AST12.stringLiteral(propTypeName),
57684
- AST12.tsTypeAnnotation(
57685
- AST12.tsLiteralType(AST12.booleanLiteral(true))
57686
- )
58024
+ AST12.identifier("type"),
58025
+ AST12.tsTypeAnnotation(typeOptions)
58026
+ ),
58027
+ AST12.tsPropertySignature(
58028
+ AST12.identifier("args"),
58029
+ AST12.tsTypeAnnotation(args)
57687
58030
  )
57688
58031
  ])
57689
58032
  )
57690
- )
58033
+ );
58034
+ }
58035
+ )
58036
+ );
58037
+ }
58038
+ return AST12.tsPropertySignature(
58039
+ AST12.identifier(typeName),
58040
+ AST12.tsTypeAnnotation(
58041
+ AST12.tsTypeLiteral([
58042
+ AST12.tsPropertySignature(
58043
+ AST12.identifier("idFields"),
58044
+ AST12.tsTypeAnnotation(idFields)
58045
+ ),
58046
+ AST12.tsPropertySignature(
58047
+ AST12.identifier("fields"),
58048
+ AST12.tsTypeAnnotation(fields)
58049
+ ),
58050
+ AST12.tsPropertySignature(
58051
+ AST12.identifier("fragments"),
58052
+ AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
57691
58053
  )
57692
58054
  ])
57693
58055
  )
58056
+ );
58057
+ })
58058
+ );
58059
+ }
58060
+ function listDefinitions(config2, docs) {
58061
+ const lists = [];
58062
+ const visitedLists = /* @__PURE__ */ new Set();
58063
+ for (const doc of docs) {
58064
+ graphql17.visit(doc.document, {
58065
+ Directive(node, key, parent, path2, ancestors) {
58066
+ if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
58067
+ return;
58068
+ }
58069
+ const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
58070
+ const nameValue = nameArg?.value?.value || "";
58071
+ if (!nameValue || visitedLists.has(nameValue)) {
58072
+ return;
58073
+ }
58074
+ visitedLists.add(nameValue);
58075
+ const parentType = parentTypeFromAncestors(
58076
+ config2.schema,
58077
+ doc.filename,
58078
+ ancestors.slice(0, -1)
58079
+ );
58080
+ const targetField = ancestors[ancestors.length - 1];
58081
+ const targetFieldDefinition = parentType.getFields()[targetField.name.value];
58082
+ const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
58083
+ const possibleTypes = [];
58084
+ if (graphql17.isAbstractType(listType)) {
58085
+ possibleTypes.push(
58086
+ ...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
58087
+ );
58088
+ } else {
58089
+ possibleTypes.push(listType.name);
58090
+ }
58091
+ lists.push(
58092
+ AST12.tsPropertySignature(
58093
+ AST12.identifier(nameValue),
58094
+ AST12.tsTypeAnnotation(
58095
+ AST12.tsTypeLiteral([
58096
+ AST12.tsPropertySignature(
58097
+ AST12.identifier("types"),
58098
+ AST12.tsTypeAnnotation(
58099
+ AST12.tsUnionType(
58100
+ possibleTypes.map(
58101
+ (possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
58102
+ )
58103
+ )
58104
+ )
58105
+ ),
58106
+ AST12.tsPropertySignature(
58107
+ AST12.identifier("filters"),
58108
+ AST12.tsTypeAnnotation(
58109
+ targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
58110
+ targetFieldDefinition.args.map((arg) => {
58111
+ const argDef = AST12.tsPropertySignature(
58112
+ AST12.identifier(arg.name),
58113
+ AST12.tsTypeAnnotation(
58114
+ tsTypeReference(
58115
+ config2,
58116
+ /* @__PURE__ */ new Set(),
58117
+ arg
58118
+ )
58119
+ )
58120
+ );
58121
+ argDef.optional = true;
58122
+ return argDef;
58123
+ })
58124
+ )
58125
+ )
58126
+ )
58127
+ ])
58128
+ )
58129
+ )
58130
+ );
58131
+ }
58132
+ });
58133
+ }
58134
+ return AST12.tsTypeLiteral(lists);
58135
+ }
58136
+ function queryDefinitions(config2, body, docs, returnType) {
58137
+ return AST12.tsTupleType(
58138
+ docs.reduce((prev, doc) => {
58139
+ if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
58140
+ return prev;
58141
+ }
58142
+ const definition = doc.document.definitions.find(
58143
+ (def) => def.kind === "OperationDefinition" && def.operation === "query"
58144
+ );
58145
+ if (!definition) {
58146
+ return prev;
58147
+ }
58148
+ const runtimeType = returnType(doc);
58149
+ const [shapeType, inputType] = ensureImports({
58150
+ config: config2,
58151
+ body,
58152
+ sourceModule: path_exports.relative(
58153
+ config2.runtimeDirectory,
58154
+ config2.artifactImportPath(doc.name)
58155
+ ),
58156
+ import: [`${doc.name}$result`, `${doc.name}$input`]
58157
+ });
58158
+ return prev.concat(
58159
+ AST12.tsTupleType([
58160
+ AST12.tsTypeReference(AST12.identifier(runtimeType)),
58161
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
58162
+ AST12.tsTypeReference(AST12.identifier(inputType))
58163
+ ])
58164
+ );
58165
+ }, [])
58166
+ );
58167
+ }
58168
+ function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
58169
+ return docs.reduce((prev, doc) => {
58170
+ if (doc.kind !== "HoudiniFragment" /* Fragment */) {
58171
+ return prev;
58172
+ }
58173
+ const definition = doc.document.definitions.find(
58174
+ (def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
58175
+ );
58176
+ if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
58177
+ return prev;
58178
+ }
58179
+ const typeName = definition.typeCondition.name.value;
58180
+ const previousValue = prev[typeName]?.elementTypes ?? [];
58181
+ const tagResult = return_type(doc);
58182
+ const [shapeType] = ensureImports({
58183
+ config: config2,
58184
+ body,
58185
+ sourceModule: path_exports.relative(
58186
+ config2.runtimeDirectory,
58187
+ config2.artifactImportPath(doc.name)
57694
58188
  ),
57695
- AST12.exportNamedDeclaration(
57696
- AST12.tsTypeAliasDeclaration(
57697
- AST12.identifier(shapeTypeName),
57698
- inlineType({
58189
+ import: [`${definition.name.value}$data`]
58190
+ });
58191
+ let inputType = AST12.tsNeverKeyword();
58192
+ let directive = definition.directives?.find(
58193
+ (directive2) => directive2.name.value === config2.argumentsDirective
58194
+ );
58195
+ if (directive) {
58196
+ inputType = AST12.tsTypeReference(
58197
+ AST12.identifier(
58198
+ ensureImports({
57699
58199
  config: config2,
57700
- filepath,
57701
- rootType: type,
57702
- selections,
57703
- root: true,
57704
- allowReadonly: true,
57705
58200
  body,
57706
- visitedTypes,
57707
- missingScalars,
57708
- includeFragments: true
57709
- })
58201
+ sourceModule: path_exports.relative(
58202
+ config2.runtimeDirectory,
58203
+ config2.artifactImportPath(doc.name)
58204
+ ),
58205
+ import: [`${definition.name.value}$input`]
58206
+ })[0]
58207
+ )
58208
+ );
58209
+ }
58210
+ return {
58211
+ ...prev,
58212
+ [typeName]: AST12.tsTupleType(
58213
+ previousValue.concat(
58214
+ AST12.tsTupleType([
58215
+ AST12.tsTypeReference(AST12.identifier(tagResult)),
58216
+ AST12.tsTypeReference(AST12.identifier(shapeType)),
58217
+ inputType
58218
+ ])
57710
58219
  )
57711
58220
  )
57712
- );
57713
- }
58221
+ };
58222
+ }, {});
58223
+ }
58224
+ var CacheTypeDefName = "CacheTypeDef";
58225
+ function record(name2) {
58226
+ return AST12.tsTypeReference(
58227
+ AST12.identifier("Record"),
58228
+ AST12.tsTypeParameterInstantiation([
58229
+ AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
58230
+ AST12.tsLiteralType(AST12.stringLiteral(name2))
58231
+ ])
58232
+ );
58233
+ }
58234
+
58235
+ // src/codegen/generators/typescript/index.ts
58236
+ async function typescriptGenerator(config2, docs) {
58237
+ await Promise.all([
58238
+ generateDocumentTypes(config2, docs),
58239
+ imperativeCacheTypef(config2, docs)
58240
+ ]);
57714
58241
  }
57715
58242
 
57716
58243
  // src/codegen/generators/persistedQueries/index.ts
57717
- var graphql17 = __toESM(require_graphql2(), 1);
58244
+ var graphql18 = __toESM(require_graphql2(), 1);
57718
58245
  async function persistOutputGenerator(config2, docs) {
57719
58246
  if (typeof config2.persistedQueryPath !== "string" || config2.persistedQueryPath.length === 0)
57720
58247
  return;
@@ -57726,8 +58253,8 @@ async function persistOutputGenerator(config2, docs) {
57726
58253
  if (!generateArtifact) {
57727
58254
  return acc;
57728
58255
  }
57729
- let rawString = graphql17.print(
57730
- graphql17.visit(document, {
58256
+ let rawString = graphql18.print(
58257
+ graphql18.visit(document, {
57731
58258
  Directive(node) {
57732
58259
  if (config2.isInternalDirective(node)) {
57733
58260
  return null;
@@ -57736,7 +58263,7 @@ async function persistOutputGenerator(config2, docs) {
57736
58263
  })
57737
58264
  );
57738
58265
  const operations = document.definitions.filter(
57739
- ({ kind }) => kind === graphql17.Kind.OPERATION_DEFINITION
58266
+ ({ kind }) => kind === graphql18.Kind.OPERATION_DEFINITION
57740
58267
  );
57741
58268
  if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
57742
58269
  acc[hashDocument(rawString)] = rawString;
@@ -57749,11 +58276,11 @@ async function persistOutputGenerator(config2, docs) {
57749
58276
  }
57750
58277
 
57751
58278
  // src/codegen/generators/definitions/enums.ts
57752
- var graphql18 = __toESM(require_graphql2(), 1);
58279
+ var graphql19 = __toESM(require_graphql2(), 1);
57753
58280
  var recast13 = __toESM(require_main2(), 1);
57754
58281
  var AST13 = recast13.types.builders;
57755
58282
  async function definitionsGenerator(config2) {
57756
- const enums = graphql18.parse(graphql18.printSchema(config2.schema)).definitions.filter(
58283
+ const enums = graphql19.parse(graphql19.printSchema(config2.schema)).definitions.filter(
57757
58284
  (definition) => definition.kind === "EnumTypeDefinition"
57758
58285
  ).filter((def) => !config2.isInternalEnum(def));
57759
58286
  const runtimeDefinitions = recast13.print(
@@ -57843,91 +58370,8 @@ async function writeIndexFile2(config2, docs) {
57843
58370
  await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
57844
58371
  }
57845
58372
 
57846
- // src/codegen/transforms/composeQueries.ts
57847
- var import_graphql = __toESM(require_graphql2(), 1);
57848
- async function includeFragmentDefinitions(config2, documents) {
57849
- const fragments = collectFragments(config2, documents);
57850
- for (const [index, { name: name2, document, filename }] of documents.entries()) {
57851
- const operation = document.definitions.find(
57852
- ({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
57853
- );
57854
- if (!operation) {
57855
- continue;
57856
- }
57857
- const allFragments = flattenFragments(
57858
- filename,
57859
- { requiredFragments: findRequiredFragments(operation.selectionSet) },
57860
- fragments
57861
- );
57862
- documents[index].document = {
57863
- ...document,
57864
- definitions: [
57865
- operation,
57866
- ...allFragments.map((fragmentName) => fragments[fragmentName].definition)
57867
- ]
57868
- };
57869
- }
57870
- }
57871
- function collectFragments(config2, docs) {
57872
- return docs.reduce((acc, doc) => {
57873
- const definitions = doc.document.definitions.reduce(
57874
- (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
57875
- ...prev,
57876
- [definition.name.value]: {
57877
- definition,
57878
- requiredFragments: findRequiredFragments(definition.selectionSet),
57879
- document: doc
57880
- }
57881
- },
57882
- {}
57883
- );
57884
- return {
57885
- ...acc,
57886
- ...definitions
57887
- };
57888
- }, {});
57889
- }
57890
- function findRequiredFragments(selectionSet) {
57891
- if (selectionSet.selections.length === 0) {
57892
- return [];
57893
- }
57894
- const referencedFragments = [];
57895
- for (const selection2 of selectionSet.selections) {
57896
- if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
57897
- referencedFragments.push(selection2.name.value);
57898
- } else if (selection2.selectionSet) {
57899
- referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
57900
- }
57901
- }
57902
- return referencedFragments;
57903
- }
57904
- function flattenFragments(filepath, operation, fragments) {
57905
- const frags = /* @__PURE__ */ new Set();
57906
- const remaining = [...operation.requiredFragments];
57907
- while (remaining.length > 0) {
57908
- const nextFragment = remaining.shift();
57909
- if (!nextFragment) {
57910
- continue;
57911
- }
57912
- if (!frags.has(nextFragment)) {
57913
- frags.add(nextFragment);
57914
- } else {
57915
- continue;
57916
- }
57917
- const targetFragment = fragments[nextFragment];
57918
- if (!targetFragment) {
57919
- throw new HoudiniError({
57920
- filepath,
57921
- message: "compose: could not find definition for fragment " + nextFragment
57922
- });
57923
- }
57924
- remaining.push(...targetFragment.requiredFragments);
57925
- }
57926
- return [...frags];
57927
- }
57928
-
57929
58373
  // src/codegen/transforms/schema.ts
57930
- var graphql19 = __toESM(require_graphql2(), 1);
58374
+ var graphql20 = __toESM(require_graphql2(), 1);
57931
58375
  async function graphqlExtensions(config2, documents) {
57932
58376
  const internalSchema = `
57933
58377
  enum CachePolicy {
@@ -57991,9 +58435,9 @@ directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
57991
58435
  directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
57992
58436
 
57993
58437
  """
57994
- @${config2.manualLoadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
58438
+ @${config2.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
57995
58439
  """
57996
- directive @${config2.manualLoadDirective} on QUERY
58440
+ directive @${config2.loadDirective} on QUERY
57997
58441
 
57998
58442
  """
57999
58443
  @${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
@@ -58005,19 +58449,19 @@ directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
58005
58449
  """
58006
58450
  directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
58007
58451
  `;
58008
- let currentSchema = graphql19.printSchema(config2.schema);
58452
+ let currentSchema = graphql20.printSchema(config2.schema);
58009
58453
  if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
58010
58454
  currentSchema += internalSchema;
58011
58455
  }
58012
58456
  config2.newSchema += internalSchema;
58013
- config2.schema = graphql19.buildSchema(currentSchema);
58457
+ config2.schema = graphql20.buildSchema(currentSchema);
58014
58458
  }
58015
58459
 
58016
58460
  // src/codegen/transforms/typename.ts
58017
- var graphql20 = __toESM(require_graphql2(), 1);
58461
+ var graphql21 = __toESM(require_graphql2(), 1);
58018
58462
  async function addTypename(config2, documents) {
58019
58463
  for (const doc of documents) {
58020
- doc.document = graphql20.visit(doc.document, {
58464
+ doc.document = graphql21.visit(doc.document, {
58021
58465
  Field(node, key, parent, path2, ancestors) {
58022
58466
  if (!node.selectionSet) {
58023
58467
  return;
@@ -58029,7 +58473,7 @@ async function addTypename(config2, documents) {
58029
58473
  );
58030
58474
  const field = type.getFields()[node.name.value];
58031
58475
  const fieldType = unwrapType(config2, field.type).type;
58032
- if (graphql20.isInterfaceType(fieldType) || graphql20.isUnionType(fieldType)) {
58476
+ if (graphql21.isInterfaceType(fieldType) || graphql21.isUnionType(fieldType)) {
58033
58477
  return {
58034
58478
  ...node,
58035
58479
  selectionSet: {
@@ -58037,9 +58481,9 @@ async function addTypename(config2, documents) {
58037
58481
  selections: [
58038
58482
  ...node.selectionSet.selections,
58039
58483
  {
58040
- kind: graphql20.Kind.FIELD,
58484
+ kind: graphql21.Kind.FIELD,
58041
58485
  name: {
58042
- kind: graphql20.Kind.NAME,
58486
+ kind: graphql21.Kind.NAME,
58043
58487
  value: "__typename"
58044
58488
  }
58045
58489
  }
@@ -58053,10 +58497,10 @@ async function addTypename(config2, documents) {
58053
58497
  }
58054
58498
 
58055
58499
  // src/codegen/transforms/addID.ts
58056
- var graphql21 = __toESM(require_graphql2(), 1);
58500
+ var graphql22 = __toESM(require_graphql2(), 1);
58057
58501
  async function addID(config2, documents) {
58058
58502
  for (const doc of documents) {
58059
- doc.document = graphql21.visit(doc.document, {
58503
+ doc.document = graphql22.visit(doc.document, {
58060
58504
  Field(node, key, parent, path2, ancestors) {
58061
58505
  if (!node.selectionSet) {
58062
58506
  return;
@@ -58069,7 +58513,7 @@ async function addID(config2, documents) {
58069
58513
  const field = type.getFields()[node.name.value];
58070
58514
  const fieldType = unwrapType(config2, field.type).type;
58071
58515
  if (node.selectionSet?.selections.length > 0) {
58072
- if (!graphql21.isObjectType(fieldType) && !graphql21.isInterfaceType(fieldType)) {
58516
+ if (!graphql22.isObjectType(fieldType) && !graphql22.isInterfaceType(fieldType)) {
58073
58517
  return;
58074
58518
  }
58075
58519
  const keyFields = config2.keyFieldsForType(fieldType.name);
@@ -58084,9 +58528,9 @@ async function addID(config2, documents) {
58084
58528
  continue;
58085
58529
  }
58086
58530
  selections.push({
58087
- kind: graphql21.Kind.FIELD,
58531
+ kind: graphql22.Kind.FIELD,
58088
58532
  name: {
58089
- kind: graphql21.Kind.NAME,
58533
+ kind: graphql22.Kind.NAME,
58090
58534
  value: keyField
58091
58535
  }
58092
58536
  });
@@ -58104,266 +58548,6 @@ async function addID(config2, documents) {
58104
58548
  }
58105
58549
  }
58106
58550
 
58107
- // src/codegen/transforms/fragmentVariables.ts
58108
- var graphql22 = __toESM(require_graphql2(), 1);
58109
- var GraphqlKinds2 = graphql22.Kind;
58110
- async function fragmentVariables(config2, documents) {
58111
- const fragments = collectFragments(config2, documents);
58112
- const generatedFragments = {};
58113
- const visitedFragments = /* @__PURE__ */ new Set();
58114
- for (const doc2 of documents) {
58115
- const operation = doc2.document.definitions.find(
58116
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
58117
- );
58118
- if (!operation) {
58119
- continue;
58120
- }
58121
- doc2.document = inlineFragmentArgs({
58122
- config: config2,
58123
- filepath: doc2.filename,
58124
- fragmentDefinitions: fragments,
58125
- document: doc2.document,
58126
- generatedFragments,
58127
- visitedFragments,
58128
- scope: null
58129
- });
58130
- }
58131
- const doc = {
58132
- kind: graphql22.Kind.DOCUMENT,
58133
- definitions: Object.values(generatedFragments)
58134
- };
58135
- documents.push({
58136
- name: "generated::fragmentVariables",
58137
- kind: "HoudiniFragment" /* Fragment */,
58138
- document: doc,
58139
- originalDocument: doc,
58140
- generateStore: false,
58141
- generateArtifact: false,
58142
- filename: "generated::fragmentVariables",
58143
- originalString: ""
58144
- });
58145
- }
58146
- function inlineFragmentArgs({
58147
- config: config2,
58148
- filepath,
58149
- fragmentDefinitions,
58150
- document,
58151
- generatedFragments,
58152
- visitedFragments,
58153
- scope,
58154
- newName
58155
- }) {
58156
- if (!scope) {
58157
- scope = operationScope(
58158
- document.definitions.find(
58159
- ({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
58160
- )
58161
- );
58162
- }
58163
- const definitionArgs = fragmentArguments(
58164
- config2,
58165
- filepath,
58166
- document
58167
- ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
58168
- const result = graphql22.visit(document, {
58169
- FragmentSpread(node) {
58170
- const { definition } = fragmentDefinitions[node.name.value];
58171
- let { args, hash } = collectWithArguments(config2, filepath, node, scope);
58172
- const newFragmentName = `${node.name.value}${hash}`;
58173
- if (!visitedFragments.has(newFragmentName)) {
58174
- visitedFragments.add(newFragmentName);
58175
- const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
58176
- if (args) {
58177
- for (const [field, value] of Object.entries(defaultArguments || {})) {
58178
- if (!args[field]) {
58179
- args[field] = value;
58180
- }
58181
- }
58182
- generatedFragments[newFragmentName] = inlineFragmentArgs({
58183
- config: config2,
58184
- filepath,
58185
- fragmentDefinitions,
58186
- document: fragmentDefinitions[node.name.value].definition,
58187
- generatedFragments,
58188
- visitedFragments,
58189
- scope: args,
58190
- newName: newFragmentName
58191
- });
58192
- } else {
58193
- const doc = fragmentDefinitions[node.name.value].document;
58194
- const definitionIndex = doc.document.definitions.findIndex(
58195
- (definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
58196
- );
58197
- const localDefinitions = [...doc.document.definitions];
58198
- localDefinitions.splice(definitionIndex, 1);
58199
- localDefinitions.push(
58200
- inlineFragmentArgs({
58201
- config: config2,
58202
- filepath,
58203
- fragmentDefinitions,
58204
- document: fragmentDefinitions[node.name.value].definition,
58205
- generatedFragments,
58206
- visitedFragments,
58207
- scope: defaultArguments,
58208
- newName: ""
58209
- })
58210
- );
58211
- doc.document = {
58212
- ...doc.document,
58213
- definitions: localDefinitions
58214
- };
58215
- }
58216
- if (node.name.value !== newFragmentName) {
58217
- return {
58218
- ...node,
58219
- name: {
58220
- kind: "Name",
58221
- value: newFragmentName
58222
- }
58223
- };
58224
- }
58225
- }
58226
- },
58227
- Argument(node) {
58228
- const value = node.value;
58229
- if (value.kind !== "Variable") {
58230
- return;
58231
- }
58232
- if (!scope) {
58233
- throw new HoudiniError({
58234
- filepath,
58235
- message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
58236
- });
58237
- }
58238
- const newValue = scope[value.name.value];
58239
- if (newValue) {
58240
- return {
58241
- ...node,
58242
- value: newValue
58243
- };
58244
- }
58245
- if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
58246
- throw new HoudiniError({
58247
- filepath,
58248
- message: "Missing value for required arg: " + value.name.value
58249
- });
58250
- }
58251
- return null;
58252
- }
58253
- });
58254
- if (newName) {
58255
- result.name = {
58256
- kind: graphql22.Kind.NAME,
58257
- value: newName
58258
- };
58259
- }
58260
- return result;
58261
- }
58262
- function withArguments(config2, node) {
58263
- const withDirectives = node.directives?.filter(
58264
- (directive) => directive.name.value === config2.withDirective
58265
- );
58266
- if (!withDirectives || withDirectives.length === 0) {
58267
- return [];
58268
- }
58269
- return withDirectives.flatMap((directive) => directive.arguments || []);
58270
- }
58271
- function fragmentArguments(config2, filepath, definition) {
58272
- const directives = definition.directives?.filter(
58273
- (directive) => directive.name.value === config2.argumentsDirective
58274
- );
58275
- if (!directives || directives.length === 0) {
58276
- return [];
58277
- }
58278
- return directives.flatMap(
58279
- (directive) => directive.arguments?.flatMap((arg) => {
58280
- if (arg.value.kind !== "ObjectValue") {
58281
- throw new HoudiniError({
58282
- filepath,
58283
- message: "values of @argument must be objects"
58284
- });
58285
- }
58286
- const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
58287
- if (!typeArg || typeArg.kind !== "StringValue") {
58288
- return [];
58289
- }
58290
- let type = typeArg.value;
58291
- let name2 = arg.name.value;
58292
- let required = false;
58293
- let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
58294
- if (type[type.length - 1] === "!") {
58295
- type = type.slice(0, -1);
58296
- required = true;
58297
- defaultValue = null;
58298
- }
58299
- return [
58300
- {
58301
- name: name2,
58302
- type,
58303
- required,
58304
- defaultValue
58305
- }
58306
- ];
58307
- }) || []
58308
- );
58309
- }
58310
- function collectDefaultArgumentValues(config2, filepath, definition) {
58311
- let result = {};
58312
- for (const { name: name2, required, defaultValue } of fragmentArguments(
58313
- config2,
58314
- filepath,
58315
- definition
58316
- )) {
58317
- if (required || !defaultValue) {
58318
- continue;
58319
- }
58320
- result[name2] = defaultValue;
58321
- }
58322
- return result;
58323
- }
58324
- function collectWithArguments(config2, filepath, node, scope = {}) {
58325
- const withArgs = withArguments(config2, node);
58326
- if (withArgs.length === 0) {
58327
- return { args: null, hash: "" };
58328
- }
58329
- let args = {};
58330
- for (const arg of withArgs) {
58331
- let value = arg.value;
58332
- if (value.kind === GraphqlKinds2.VARIABLE) {
58333
- if (!scope || !scope[value.name.value]) {
58334
- throw new HoudiniError({
58335
- filepath,
58336
- message: "Encountered undefined variable: " + value.name.value
58337
- });
58338
- }
58339
- value = scope[value.name.value];
58340
- }
58341
- args[arg.name.value] = {
58342
- ...value,
58343
- loc: void 0
58344
- };
58345
- }
58346
- return {
58347
- args,
58348
- hash: "_" + murmurHash(JSON.stringify(args))
58349
- };
58350
- }
58351
- function operationScope(operation) {
58352
- return operation.variableDefinitions?.reduce(
58353
- (scope, definition) => ({
58354
- ...scope,
58355
- [definition.variable.name.value]: {
58356
- kind: "Variable",
58357
- name: {
58358
- kind: "Name",
58359
- value: definition.variable.name.value
58360
- }
58361
- }
58362
- }),
58363
- {}
58364
- ) || {};
58365
- }
58366
-
58367
58551
  // src/codegen/validators/typeCheck.ts
58368
58552
  var graphql23 = __toESM(require_graphql2(), 1);
58369
58553
  async function typeCheck(config2, docs) {