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

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