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