houdini 1.0.10 → 1.1.0

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 (67) hide show
  1. package/build/cmd-cjs/index.js +639 -325
  2. package/build/cmd-esm/index.js +639 -325
  3. package/build/codegen/generators/artifacts/selection.d.ts +5 -2
  4. package/build/codegen/generators/typescript/inlineType.d.ts +1 -1
  5. package/build/codegen/transforms/{composeQueries.d.ts → collectDefinitions.d.ts} +1 -1
  6. package/build/codegen/transforms/fragmentVariables.d.ts +2 -4
  7. package/build/codegen/transforms/index.d.ts +1 -1
  8. package/build/codegen/utils/flattenSelections.d.ts +2 -2
  9. package/build/codegen-cjs/index.js +584 -321
  10. package/build/codegen-esm/index.js +584 -321
  11. package/build/lib/config.d.ts +10 -1
  12. package/build/lib/deepMerge.d.ts +1 -1
  13. package/build/lib/types.d.ts +1 -0
  14. package/build/lib-cjs/index.js +261 -115
  15. package/build/lib-esm/index.js +260 -115
  16. package/build/runtime/cache/cache.d.ts +17 -6
  17. package/build/runtime/client/documentStore.d.ts +1 -0
  18. package/build/runtime/client/plugins/cache.d.ts +3 -2
  19. package/build/runtime/client/plugins/fragment.d.ts +2 -0
  20. package/build/runtime/client/plugins/index.d.ts +1 -0
  21. package/build/runtime/lib/scalars.d.ts +0 -1
  22. package/build/runtime/lib/types.d.ts +55 -7
  23. package/build/runtime-cjs/cache/cache.d.ts +17 -6
  24. package/build/runtime-cjs/cache/cache.js +89 -21
  25. package/build/runtime-cjs/cache/lists.js +2 -1
  26. package/build/runtime-cjs/cache/subscription.js +11 -2
  27. package/build/runtime-cjs/client/documentStore.d.ts +1 -0
  28. package/build/runtime-cjs/client/documentStore.js +5 -14
  29. package/build/runtime-cjs/client/index.js +2 -1
  30. package/build/runtime-cjs/client/plugins/cache.d.ts +3 -2
  31. package/build/runtime-cjs/client/plugins/cache.js +19 -3
  32. package/build/runtime-cjs/client/plugins/fetch.js +4 -1
  33. package/build/runtime-cjs/client/plugins/fragment.d.ts +2 -0
  34. package/build/runtime-cjs/client/plugins/fragment.js +76 -0
  35. package/build/runtime-cjs/client/plugins/index.d.ts +1 -0
  36. package/build/runtime-cjs/client/plugins/index.js +1 -0
  37. package/build/runtime-cjs/client/plugins/query.js +3 -5
  38. package/build/runtime-cjs/lib/scalars.d.ts +0 -1
  39. package/build/runtime-cjs/lib/scalars.js +2 -43
  40. package/build/runtime-cjs/lib/types.d.ts +55 -7
  41. package/build/runtime-cjs/lib/types.js +5 -2
  42. package/build/runtime-cjs/public/tests/test.js +4 -2
  43. package/build/runtime-esm/cache/cache.d.ts +17 -6
  44. package/build/runtime-esm/cache/cache.js +89 -22
  45. package/build/runtime-esm/cache/lists.js +2 -1
  46. package/build/runtime-esm/cache/subscription.js +11 -2
  47. package/build/runtime-esm/client/documentStore.d.ts +1 -0
  48. package/build/runtime-esm/client/documentStore.js +6 -15
  49. package/build/runtime-esm/client/index.js +3 -1
  50. package/build/runtime-esm/client/plugins/cache.d.ts +3 -2
  51. package/build/runtime-esm/client/plugins/cache.js +19 -3
  52. package/build/runtime-esm/client/plugins/fetch.js +5 -2
  53. package/build/runtime-esm/client/plugins/fragment.d.ts +2 -0
  54. package/build/runtime-esm/client/plugins/fragment.js +46 -0
  55. package/build/runtime-esm/client/plugins/index.d.ts +1 -0
  56. package/build/runtime-esm/client/plugins/index.js +1 -0
  57. package/build/runtime-esm/client/plugins/query.js +3 -5
  58. package/build/runtime-esm/lib/scalars.d.ts +0 -1
  59. package/build/runtime-esm/lib/scalars.js +1 -41
  60. package/build/runtime-esm/lib/types.d.ts +55 -7
  61. package/build/runtime-esm/lib/types.js +3 -1
  62. package/build/runtime-esm/public/tests/test.js +4 -2
  63. package/build/test-cjs/index.js +638 -324
  64. package/build/test-esm/index.js +638 -324
  65. package/build/vite-cjs/index.js +637 -323
  66. package/build/vite-esm/index.js +637 -323
  67. package/package.json +2 -2
@@ -5122,7 +5122,7 @@ var require_definition = __commonJS({
5122
5122
  exports.assertLeafType = assertLeafType;
5123
5123
  exports.isCompositeType = isCompositeType;
5124
5124
  exports.assertCompositeType = assertCompositeType;
5125
- exports.isAbstractType = isAbstractType3;
5125
+ exports.isAbstractType = isAbstractType4;
5126
5126
  exports.assertAbstractType = assertAbstractType;
5127
5127
  exports.GraphQLList = GraphQLList6;
5128
5128
  exports.GraphQLNonNull = GraphQLNonNull6;
@@ -5293,11 +5293,11 @@ var require_definition = __commonJS({
5293
5293
  }
5294
5294
  return type;
5295
5295
  }
5296
- function isAbstractType3(type) {
5296
+ function isAbstractType4(type) {
5297
5297
  return isInterfaceType12(type) || isUnionType13(type);
5298
5298
  }
5299
5299
  function assertAbstractType(type) {
5300
- if (!isAbstractType3(type)) {
5300
+ if (!isAbstractType4(type)) {
5301
5301
  throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL abstract type."));
5302
5302
  }
5303
5303
  return type;
@@ -8561,8 +8561,8 @@ var require_KnownFragmentNamesRule = __commonJS({
8561
8561
  return {
8562
8562
  FragmentSpread: function FragmentSpread(node) {
8563
8563
  var fragmentName = node.name.value;
8564
- var fragment = context.getFragment(fragmentName);
8565
- if (!fragment) {
8564
+ var fragment2 = context.getFragment(fragmentName);
8565
+ if (!fragment2) {
8566
8566
  context.reportError(new _GraphQLError.GraphQLError('Unknown fragment "'.concat(fragmentName, '".'), node.name));
8567
8567
  }
8568
8568
  }
@@ -8598,8 +8598,8 @@ var require_NoUnusedFragmentsRule = __commonJS({
8598
8598
  for (var _i2 = 0; _i2 < operationDefs.length; _i2++) {
8599
8599
  var operation = operationDefs[_i2];
8600
8600
  for (var _i4 = 0, _context$getRecursive2 = context.getRecursivelyReferencedFragments(operation); _i4 < _context$getRecursive2.length; _i4++) {
8601
- var fragment = _context$getRecursive2[_i4];
8602
- fragmentNameUsed[fragment.name.value] = true;
8601
+ var fragment2 = _context$getRecursive2[_i4];
8602
+ fragmentNameUsed[fragment2.name.value] = true;
8603
8603
  }
8604
8604
  }
8605
8605
  for (var _i6 = 0; _i6 < fragmentDefs.length; _i6++) {
@@ -8689,13 +8689,13 @@ var require_NoFragmentCyclesRule = __commonJS({
8689
8689
  return false;
8690
8690
  }
8691
8691
  };
8692
- function detectCycleRecursive(fragment) {
8693
- if (visitedFrags[fragment.name.value]) {
8692
+ function detectCycleRecursive(fragment2) {
8693
+ if (visitedFrags[fragment2.name.value]) {
8694
8694
  return;
8695
8695
  }
8696
- var fragmentName = fragment.name.value;
8696
+ var fragmentName = fragment2.name.value;
8697
8697
  visitedFrags[fragmentName] = true;
8698
- var spreadNodes = context.getFragmentSpreads(fragment.selectionSet);
8698
+ var spreadNodes = context.getFragmentSpreads(fragment2.selectionSet);
8699
8699
  if (spreadNodes.length === 0) {
8700
8700
  return;
8701
8701
  }
@@ -9516,11 +9516,11 @@ var require_OverlappingFieldsCanBeMergedRule = __commonJS({
9516
9516
  return conflicts;
9517
9517
  }
9518
9518
  function collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap, fragmentName) {
9519
- var fragment = context.getFragment(fragmentName);
9520
- if (!fragment) {
9519
+ var fragment2 = context.getFragment(fragmentName);
9520
+ if (!fragment2) {
9521
9521
  return;
9522
9522
  }
9523
- var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment), fieldMap2 = _getReferencedFieldsA[0], fragmentNames2 = _getReferencedFieldsA[1];
9523
+ var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2), fieldMap2 = _getReferencedFieldsA[0], fragmentNames2 = _getReferencedFieldsA[1];
9524
9524
  if (fieldMap === fieldMap2) {
9525
9525
  return;
9526
9526
  }
@@ -9691,38 +9691,38 @@ var require_OverlappingFieldsCanBeMergedRule = __commonJS({
9691
9691
  }
9692
9692
  return cached;
9693
9693
  }
9694
- function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment) {
9695
- var cached = cachedFieldsAndFragmentNames.get(fragment.selectionSet);
9694
+ function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2) {
9695
+ var cached = cachedFieldsAndFragmentNames.get(fragment2.selectionSet);
9696
9696
  if (cached) {
9697
9697
  return cached;
9698
9698
  }
9699
- var fragmentType = (0, _typeFromAST.typeFromAST)(context.getSchema(), fragment.typeCondition);
9700
- return getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragmentType, fragment.selectionSet);
9699
+ var fragmentType = (0, _typeFromAST.typeFromAST)(context.getSchema(), fragment2.typeCondition);
9700
+ return getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragmentType, fragment2.selectionSet);
9701
9701
  }
9702
9702
  function _collectFieldsAndFragmentNames(context, parentType, selectionSet, nodeAndDefs, fragmentNames) {
9703
9703
  for (var _i9 = 0, _selectionSet$selecti2 = selectionSet.selections; _i9 < _selectionSet$selecti2.length; _i9++) {
9704
- var selection2 = _selectionSet$selecti2[_i9];
9705
- switch (selection2.kind) {
9704
+ var selection = _selectionSet$selecti2[_i9];
9705
+ switch (selection.kind) {
9706
9706
  case _kinds.Kind.FIELD: {
9707
- var fieldName = selection2.name.value;
9707
+ var fieldName = selection.name.value;
9708
9708
  var fieldDef = void 0;
9709
9709
  if ((0, _definition.isObjectType)(parentType) || (0, _definition.isInterfaceType)(parentType)) {
9710
9710
  fieldDef = parentType.getFields()[fieldName];
9711
9711
  }
9712
- var responseName = selection2.alias ? selection2.alias.value : fieldName;
9712
+ var responseName = selection.alias ? selection.alias.value : fieldName;
9713
9713
  if (!nodeAndDefs[responseName]) {
9714
9714
  nodeAndDefs[responseName] = [];
9715
9715
  }
9716
- nodeAndDefs[responseName].push([parentType, selection2, fieldDef]);
9716
+ nodeAndDefs[responseName].push([parentType, selection, fieldDef]);
9717
9717
  break;
9718
9718
  }
9719
9719
  case _kinds.Kind.FRAGMENT_SPREAD:
9720
- fragmentNames[selection2.name.value] = true;
9720
+ fragmentNames[selection.name.value] = true;
9721
9721
  break;
9722
9722
  case _kinds.Kind.INLINE_FRAGMENT: {
9723
- var typeCondition = selection2.typeCondition;
9723
+ var typeCondition = selection.typeCondition;
9724
9724
  var inlineFragmentType = typeCondition ? (0, _typeFromAST.typeFromAST)(context.getSchema(), typeCondition) : parentType;
9725
- _collectFieldsAndFragmentNames(context, inlineFragmentType, selection2.selectionSet, nodeAndDefs, fragmentNames);
9725
+ _collectFieldsAndFragmentNames(context, inlineFragmentType, selection.selectionSet, nodeAndDefs, fragmentNames);
9726
9726
  break;
9727
9727
  }
9728
9728
  }
@@ -10258,11 +10258,11 @@ var require_ValidationContext = __commonJS({
10258
10258
  while (setsToVisit.length !== 0) {
10259
10259
  var set = setsToVisit.pop();
10260
10260
  for (var _i2 = 0, _set$selections2 = set.selections; _i2 < _set$selections2.length; _i2++) {
10261
- var selection2 = _set$selections2[_i2];
10262
- if (selection2.kind === _kinds.Kind.FRAGMENT_SPREAD) {
10263
- spreads.push(selection2);
10264
- } else if (selection2.selectionSet) {
10265
- setsToVisit.push(selection2.selectionSet);
10261
+ var selection = _set$selections2[_i2];
10262
+ if (selection.kind === _kinds.Kind.FRAGMENT_SPREAD) {
10263
+ spreads.push(selection);
10264
+ } else if (selection.selectionSet) {
10265
+ setsToVisit.push(selection.selectionSet);
10266
10266
  }
10267
10267
  }
10268
10268
  }
@@ -10283,10 +10283,10 @@ var require_ValidationContext = __commonJS({
10283
10283
  var fragName = spread.name.value;
10284
10284
  if (collectedNames[fragName] !== true) {
10285
10285
  collectedNames[fragName] = true;
10286
- var fragment = this.getFragment(fragName);
10287
- if (fragment) {
10288
- fragments.push(fragment);
10289
- nodesToVisit.push(fragment.selectionSet);
10286
+ var fragment2 = this.getFragment(fragName);
10287
+ if (fragment2) {
10288
+ fragments.push(fragment2);
10289
+ nodesToVisit.push(fragment2.selectionSet);
10290
10290
  }
10291
10291
  }
10292
10292
  }
@@ -11199,37 +11199,37 @@ var require_execute = __commonJS({
11199
11199
  }
11200
11200
  function collectFields(exeContext, runtimeType, selectionSet, fields, visitedFragmentNames) {
11201
11201
  for (var _i6 = 0, _selectionSet$selecti2 = selectionSet.selections; _i6 < _selectionSet$selecti2.length; _i6++) {
11202
- var selection2 = _selectionSet$selecti2[_i6];
11203
- switch (selection2.kind) {
11202
+ var selection = _selectionSet$selecti2[_i6];
11203
+ switch (selection.kind) {
11204
11204
  case _kinds.Kind.FIELD: {
11205
- if (!shouldIncludeNode(exeContext, selection2)) {
11205
+ if (!shouldIncludeNode(exeContext, selection)) {
11206
11206
  continue;
11207
11207
  }
11208
- var name = getFieldEntryKey(selection2);
11208
+ var name = getFieldEntryKey(selection);
11209
11209
  if (!fields[name]) {
11210
11210
  fields[name] = [];
11211
11211
  }
11212
- fields[name].push(selection2);
11212
+ fields[name].push(selection);
11213
11213
  break;
11214
11214
  }
11215
11215
  case _kinds.Kind.INLINE_FRAGMENT: {
11216
- if (!shouldIncludeNode(exeContext, selection2) || !doesFragmentConditionMatch(exeContext, selection2, runtimeType)) {
11216
+ if (!shouldIncludeNode(exeContext, selection) || !doesFragmentConditionMatch(exeContext, selection, runtimeType)) {
11217
11217
  continue;
11218
11218
  }
11219
- collectFields(exeContext, runtimeType, selection2.selectionSet, fields, visitedFragmentNames);
11219
+ collectFields(exeContext, runtimeType, selection.selectionSet, fields, visitedFragmentNames);
11220
11220
  break;
11221
11221
  }
11222
11222
  case _kinds.Kind.FRAGMENT_SPREAD: {
11223
- var fragName = selection2.name.value;
11224
- if (visitedFragmentNames[fragName] || !shouldIncludeNode(exeContext, selection2)) {
11223
+ var fragName = selection.name.value;
11224
+ if (visitedFragmentNames[fragName] || !shouldIncludeNode(exeContext, selection)) {
11225
11225
  continue;
11226
11226
  }
11227
11227
  visitedFragmentNames[fragName] = true;
11228
- var fragment = exeContext.fragments[fragName];
11229
- if (!fragment || !doesFragmentConditionMatch(exeContext, fragment, runtimeType)) {
11228
+ var fragment2 = exeContext.fragments[fragName];
11229
+ if (!fragment2 || !doesFragmentConditionMatch(exeContext, fragment2, runtimeType)) {
11230
11230
  continue;
11231
11231
  }
11232
- collectFields(exeContext, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
11232
+ collectFields(exeContext, runtimeType, fragment2.selectionSet, fields, visitedFragmentNames);
11233
11233
  break;
11234
11234
  }
11235
11235
  }
@@ -11247,8 +11247,8 @@ var require_execute = __commonJS({
11247
11247
  }
11248
11248
  return true;
11249
11249
  }
11250
- function doesFragmentConditionMatch(exeContext, fragment, type) {
11251
- var typeConditionNode = fragment.typeCondition;
11250
+ function doesFragmentConditionMatch(exeContext, fragment2, type) {
11251
+ var typeConditionNode = fragment2.typeCondition;
11252
11252
  if (!typeConditionNode) {
11253
11253
  return true;
11254
11254
  }
@@ -68481,14 +68481,14 @@ function deepEquals(objA, objB, map = /* @__PURE__ */ new WeakMap()) {
68481
68481
  }
68482
68482
 
68483
68483
  // src/runtime/lib/selection.ts
68484
- function getFieldsForType(selection2, __typename) {
68485
- let targetSelection = selection2.fields || {};
68486
- if (selection2.abstractFields && __typename) {
68487
- const mappedType = selection2.abstractFields.typeMap[__typename];
68484
+ function getFieldsForType(selection, __typename) {
68485
+ let targetSelection = selection.fields || {};
68486
+ if (selection.abstractFields && __typename) {
68487
+ const mappedType = selection.abstractFields.typeMap[__typename];
68488
68488
  if (mappedType) {
68489
- targetSelection = selection2.abstractFields.fields[mappedType];
68490
- } else if (selection2.abstractFields.fields[__typename]) {
68491
- targetSelection = selection2.abstractFields.fields[__typename];
68489
+ targetSelection = selection.abstractFields.fields[mappedType];
68490
+ } else if (selection.abstractFields.fields[__typename]) {
68491
+ targetSelection = selection.abstractFields.fields[__typename];
68492
68492
  }
68493
68493
  }
68494
68494
  return targetSelection;
@@ -68496,7 +68496,7 @@ function getFieldsForType(selection2, __typename) {
68496
68496
 
68497
68497
  // src/runtime/lib/scalars.ts
68498
68498
  async function marshalSelection({
68499
- selection: selection2,
68499
+ selection,
68500
68500
  data
68501
68501
  }) {
68502
68502
  const config2 = getCurrentConfig();
@@ -68504,18 +68504,18 @@ async function marshalSelection({
68504
68504
  return data;
68505
68505
  }
68506
68506
  if (Array.isArray(data)) {
68507
- return await Promise.all(data.map((val) => marshalSelection({ selection: selection2, data: val })));
68507
+ return await Promise.all(data.map((val) => marshalSelection({ selection, data: val })));
68508
68508
  }
68509
- const targetSelection = getFieldsForType(selection2, data["__typename"]);
68509
+ const targetSelection = getFieldsForType(selection, data["__typename"]);
68510
68510
  return Object.fromEntries(
68511
68511
  await Promise.all(
68512
68512
  Object.entries(data).map(async ([fieldName, value]) => {
68513
- const { type, selection: selection3 } = targetSelection[fieldName];
68513
+ const { type, selection: selection2 } = targetSelection[fieldName];
68514
68514
  if (!type) {
68515
68515
  return [fieldName, value];
68516
68516
  }
68517
- if (selection3) {
68518
- return [fieldName, await marshalSelection({ selection: selection3, data: value })];
68517
+ if (selection2) {
68518
+ return [fieldName, await marshalSelection({ selection: selection2, data: value })];
68519
68519
  }
68520
68520
  if (config2.scalars?.[type]) {
68521
68521
  const marshalFn = config2.scalars[type].marshal;
@@ -68566,6 +68566,7 @@ var DataSource = {
68566
68566
  Network: "network",
68567
68567
  Ssr: "ssr"
68568
68568
  };
68569
+ var fragmentKey = " $fragments";
68569
68570
 
68570
68571
  // src/runtime/lib/key.ts
68571
68572
  var computeKey = ({ field, args }) => {
@@ -70308,7 +70309,7 @@ var List = class {
70308
70309
  recordType,
70309
70310
  key,
70310
70311
  listType,
70311
- selection: selection2,
70312
+ selection,
70312
70313
  when,
70313
70314
  filters,
70314
70315
  connection,
@@ -70320,7 +70321,7 @@ var List = class {
70320
70321
  this.key = key;
70321
70322
  this.type = listType;
70322
70323
  this.cache = manager.cache;
70323
- this.selection = selection2;
70324
+ this.selection = selection;
70324
70325
  this._when = when;
70325
70326
  this.filters = filters;
70326
70327
  this.name = name;
@@ -70331,19 +70332,19 @@ var List = class {
70331
70332
  when(when) {
70332
70333
  return this.manager.lists.get(this.name).get(this.recordID).when(when);
70333
70334
  }
70334
- append(selection2, data, variables = {}) {
70335
- return this.addToList(selection2, data, variables, "last");
70335
+ append(selection, data, variables = {}) {
70336
+ return this.addToList(selection, data, variables, "last");
70336
70337
  }
70337
- prepend(selection2, data, variables = {}) {
70338
- return this.addToList(selection2, data, variables, "first");
70338
+ prepend(selection, data, variables = {}) {
70339
+ return this.addToList(selection, data, variables, "first");
70339
70340
  }
70340
- addToList(selection2, data, variables = {}, where) {
70341
+ addToList(selection, data, variables = {}, where) {
70341
70342
  const listType = this.listType(data);
70342
70343
  const dataID = this.cache._internal_unstable.id(listType, data);
70343
70344
  if (!this.validateWhen() || !dataID) {
70344
70345
  return;
70345
70346
  }
70346
- let insertSelection = selection2;
70347
+ let insertSelection = selection;
70347
70348
  let insertData = data;
70348
70349
  if (this.connection) {
70349
70350
  insertSelection = {
@@ -70363,9 +70364,9 @@ var List = class {
70363
70364
  type: listType,
70364
70365
  keyRaw: "node",
70365
70366
  selection: {
70366
- ...selection2,
70367
+ ...selection,
70367
70368
  fields: {
70368
- ...selection2.fields,
70369
+ ...selection.fields,
70369
70370
  __typename: {
70370
70371
  keyRaw: "__typename",
70371
70372
  type: "String"
@@ -70394,9 +70395,9 @@ var List = class {
70394
70395
  type: listType,
70395
70396
  updates: ["append", "prepend"],
70396
70397
  selection: {
70397
- ...selection2,
70398
+ ...selection,
70398
70399
  fields: {
70399
- ...selection2.fields,
70400
+ ...selection.fields,
70400
70401
  __typename: {
70401
70402
  keyRaw: "__typename",
70402
70403
  type: "String"
@@ -70471,7 +70472,8 @@ var List = class {
70471
70472
  this.cache._internal_unstable.getSelection({
70472
70473
  parent: spec.parentID || this.manager.rootID,
70473
70474
  selection: spec.selection,
70474
- variables: spec.variables?.() || {}
70475
+ variables: spec.variables?.() || {},
70476
+ ignoreMasking: false
70475
70477
  }).data
70476
70478
  );
70477
70479
  }
@@ -70507,9 +70509,9 @@ var List = class {
70507
70509
  }
70508
70510
  return ok;
70509
70511
  }
70510
- toggleElement(selection2, data, variables = {}, where) {
70512
+ toggleElement(selection, data, variables = {}, where) {
70511
70513
  if (!this.remove(data, variables)) {
70512
- this.addToList(selection2, data, variables, where);
70514
+ this.addToList(selection, data, variables, where);
70513
70515
  }
70514
70516
  }
70515
70517
  *[Symbol.iterator]() {
@@ -71084,14 +71086,24 @@ var InMemorySubscriptions = class {
71084
71086
  add({
71085
71087
  parent,
71086
71088
  spec,
71087
- selection: selection2,
71089
+ selection,
71088
71090
  variables,
71089
71091
  parentType
71090
71092
  }) {
71091
71093
  const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
71092
- let targetSelection = getFieldsForType(selection2, __typename);
71094
+ let targetSelection = getFieldsForType(selection, __typename);
71093
71095
  for (const fieldSelection of Object.values(targetSelection || {})) {
71094
- const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
71096
+ const {
71097
+ keyRaw,
71098
+ selection: innerSelection,
71099
+ type,
71100
+ list,
71101
+ filters,
71102
+ visible
71103
+ } = fieldSelection;
71104
+ if (!visible) {
71105
+ continue;
71106
+ }
71095
71107
  const key = evaluateKey(keyRaw, variables);
71096
71108
  let targetSelection2;
71097
71109
  if (innerSelection) {
@@ -71139,10 +71151,10 @@ var InMemorySubscriptions = class {
71139
71151
  addFieldSubscription({
71140
71152
  id,
71141
71153
  key,
71142
- selection: selection2,
71154
+ selection,
71143
71155
  type
71144
71156
  }) {
71145
- const spec = selection2[0];
71157
+ const spec = selection[0];
71146
71158
  if (!this.subscribers[id]) {
71147
71159
  this.subscribers[id] = {};
71148
71160
  }
@@ -71154,7 +71166,7 @@ var InMemorySubscriptions = class {
71154
71166
  }
71155
71167
  this.keyVersions[key].add(key);
71156
71168
  if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
71157
- this.subscribers[id][key].push([spec, selection2[1]]);
71169
+ this.subscribers[id][key].push([spec, selection[1]]);
71158
71170
  }
71159
71171
  if (!this.referenceCounts[id]) {
71160
71172
  this.referenceCounts[id] = {};
@@ -71165,14 +71177,13 @@ var InMemorySubscriptions = class {
71165
71177
  const counts = this.referenceCounts[id][key];
71166
71178
  counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
71167
71179
  this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
71168
- const { selection: innerSelection } = selection2[1]?.[key] ?? {};
71169
71180
  }
71170
71181
  registerList({
71171
71182
  list,
71172
71183
  id,
71173
71184
  key,
71174
71185
  parentType,
71175
- selection: selection2,
71186
+ selection,
71176
71187
  filters,
71177
71188
  variables
71178
71189
  }) {
@@ -71183,7 +71194,7 @@ var InMemorySubscriptions = class {
71183
71194
  recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
71184
71195
  listType: list.type,
71185
71196
  key,
71186
- selection: selection2,
71197
+ selection,
71187
71198
  filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
71188
71199
  return {
71189
71200
  ...acc,
@@ -71199,14 +71210,14 @@ var InMemorySubscriptions = class {
71199
71210
  parentType
71200
71211
  }) {
71201
71212
  for (const [spec, targetSelection] of subscribers) {
71202
- for (const selection2 of Object.values(targetSelection ?? {})) {
71213
+ for (const selection of Object.values(targetSelection ?? {})) {
71203
71214
  const {
71204
71215
  type: linkedType,
71205
71216
  keyRaw,
71206
71217
  selection: innerSelection,
71207
71218
  list,
71208
71219
  filters
71209
- } = selection2;
71220
+ } = selection;
71210
71221
  const key = evaluateKey(keyRaw, variables);
71211
71222
  const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
71212
71223
  this.addFieldSubscription({
@@ -71226,7 +71237,7 @@ var InMemorySubscriptions = class {
71226
71237
  parentType: parentType || spec.rootType
71227
71238
  });
71228
71239
  }
71229
- const childSelection = selection2.selection;
71240
+ const childSelection = selection.selection;
71230
71241
  if (childSelection) {
71231
71242
  const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
71232
71243
  const children = !Array.isArray(link) ? [link] : flatten(link);
@@ -71253,11 +71264,11 @@ var InMemorySubscriptions = class {
71253
71264
  get(id, field) {
71254
71265
  return this.subscribers[id]?.[field] || [];
71255
71266
  }
71256
- remove(id, selection2, targets, variables, visited = []) {
71267
+ remove(id, selection, targets, variables, visited = []) {
71257
71268
  visited.push(id);
71258
71269
  const linkedIDs = [];
71259
71270
  const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
71260
- let targetSelection = getFieldsForType(selection2, __typename);
71271
+ let targetSelection = getFieldsForType(selection, __typename);
71261
71272
  for (const fieldSelection of Object.values(targetSelection || {})) {
71262
71273
  const key = evaluateKey(fieldSelection.keyRaw, variables);
71263
71274
  this.removeSubscribers(id, key, targets);
@@ -71319,7 +71330,7 @@ var InMemorySubscriptions = class {
71319
71330
  // src/runtime/cache/cache.ts
71320
71331
  var Cache = class {
71321
71332
  _internal_unstable;
71322
- constructor(config2) {
71333
+ constructor({ disabled, ...config2 } = {}) {
71323
71334
  this._internal_unstable = new CacheInternal({
71324
71335
  cache: this,
71325
71336
  storage: new InMemoryStorage(),
@@ -71327,9 +71338,10 @@ var Cache = class {
71327
71338
  lists: new ListManager(this, rootID),
71328
71339
  lifetimes: new GarbageCollector(this),
71329
71340
  staleManager: new StaleManager(this),
71330
- schema: new SchemaManager(this)
71341
+ schema: new SchemaManager(this),
71342
+ disabled: disabled ?? typeof globalThis.window === "undefined"
71331
71343
  });
71332
- if (config2) {
71344
+ if (Object.keys(config2).length > 0) {
71333
71345
  this.setConfig(defaultConfigValues(config2));
71334
71346
  }
71335
71347
  }
@@ -71348,7 +71360,8 @@ var Cache = class {
71348
71360
  this._internal_unstable.getSelection({
71349
71361
  parent: spec.parentID || rootID,
71350
71362
  selection: spec.selection,
71351
- variables: spec.variables?.() || {}
71363
+ variables: spec.variables?.() || {},
71364
+ ignoreMasking: false
71352
71365
  }).data
71353
71366
  );
71354
71367
  }
@@ -71423,16 +71436,13 @@ var Cache = class {
71423
71436
  getFieldTime(id, field) {
71424
71437
  return this._internal_unstable.staleManager.getFieldTime(id, field);
71425
71438
  }
71439
+ config() {
71440
+ return this._internal_unstable.config;
71441
+ }
71426
71442
  };
71427
71443
  var CacheInternal = class {
71428
71444
  _disabled = false;
71429
- config = defaultConfigValues({
71430
- plugins: {
71431
- "houdini-svelte": {
71432
- client: ""
71433
- }
71434
- }
71435
- });
71445
+ _config;
71436
71446
  storage;
71437
71447
  subscriptions;
71438
71448
  lists;
@@ -71447,7 +71457,9 @@ var CacheInternal = class {
71447
71457
  cache,
71448
71458
  lifetimes,
71449
71459
  staleManager,
71450
- schema
71460
+ schema,
71461
+ disabled,
71462
+ config: config2
71451
71463
  }) {
71452
71464
  this.storage = storage;
71453
71465
  this.subscriptions = subscriptions;
@@ -71456,7 +71468,8 @@ var CacheInternal = class {
71456
71468
  this.lifetimes = lifetimes;
71457
71469
  this.staleManager = staleManager;
71458
71470
  this.schema = schema;
71459
- this._disabled = typeof globalThis.window === "undefined";
71471
+ this._config = config2;
71472
+ this._disabled = disabled;
71460
71473
  try {
71461
71474
  if (process.env.HOUDINI_TEST === "true") {
71462
71475
  this._disabled = false;
@@ -71464,12 +71477,15 @@ var CacheInternal = class {
71464
71477
  } catch {
71465
71478
  }
71466
71479
  }
71480
+ get config() {
71481
+ return this._config ?? getCurrentConfig();
71482
+ }
71467
71483
  setConfig(config2) {
71468
- this.config = config2;
71484
+ this._config = config2;
71469
71485
  }
71470
71486
  writeSelection({
71471
71487
  data,
71472
- selection: selection2,
71488
+ selection,
71473
71489
  variables = {},
71474
71490
  parent = rootID,
71475
71491
  applyUpdates,
@@ -71481,9 +71497,9 @@ var CacheInternal = class {
71481
71497
  if (this._disabled) {
71482
71498
  return [];
71483
71499
  }
71484
- let targetSelection = getFieldsForType(selection2, data["__typename"]);
71500
+ let targetSelection = getFieldsForType(selection, data["__typename"]);
71485
71501
  for (const [field, value] of Object.entries(data)) {
71486
- if (!selection2 || !targetSelection[field]) {
71502
+ if (!selection || !targetSelection[field]) {
71487
71503
  continue;
71488
71504
  }
71489
71505
  let {
@@ -71739,25 +71755,40 @@ var CacheInternal = class {
71739
71755
  return toNotify;
71740
71756
  }
71741
71757
  getSelection({
71742
- selection: selection2,
71758
+ selection,
71743
71759
  parent = rootID,
71744
71760
  variables,
71745
- stepsFromConnection = null
71761
+ stepsFromConnection = null,
71762
+ ignoreMasking
71746
71763
  }) {
71747
71764
  if (parent === null) {
71748
71765
  return { data: null, partial: false, stale: false, hasData: true };
71749
71766
  }
71750
71767
  const target = {};
71768
+ if (selection.fragments) {
71769
+ target[fragmentKey] = Object.fromEntries(
71770
+ Object.entries(selection.fragments).map(([key, value]) => [
71771
+ key,
71772
+ {
71773
+ parent,
71774
+ variables: evaluateFragmentVariables(value, variables ?? {})
71775
+ }
71776
+ ])
71777
+ );
71778
+ }
71751
71779
  let hasData = false;
71752
71780
  let partial = false;
71753
71781
  let cascadeNull = false;
71754
71782
  let stale = false;
71755
71783
  const typename = this.storage.get(parent, "__typename").value;
71756
- let targetSelection = getFieldsForType(selection2, typename);
71784
+ let targetSelection = getFieldsForType(selection, typename);
71757
71785
  for (const [
71758
71786
  attributeName,
71759
- { type, keyRaw, selection: fieldSelection, nullable, list }
71787
+ { type, keyRaw, selection: fieldSelection, nullable, list, visible }
71760
71788
  ] of Object.entries(targetSelection)) {
71789
+ if (!visible && !ignoreMasking) {
71790
+ continue;
71791
+ }
71761
71792
  const key = evaluateKey(keyRaw, variables);
71762
71793
  const { value } = this.storage.get(parent, key);
71763
71794
  const dt_field = this.staleManager.getFieldTime(parent, key);
@@ -71797,7 +71828,8 @@ var CacheInternal = class {
71797
71828
  fields: fieldSelection,
71798
71829
  variables,
71799
71830
  linkedList: value,
71800
- stepsFromConnection: nextStep
71831
+ stepsFromConnection: nextStep,
71832
+ ignoreMasking: !!ignoreMasking
71801
71833
  });
71802
71834
  target[attributeName] = listValue.data;
71803
71835
  if (listValue.partial) {
@@ -71814,7 +71846,8 @@ var CacheInternal = class {
71814
71846
  parent: value,
71815
71847
  selection: fieldSelection,
71816
71848
  variables,
71817
- stepsFromConnection: nextStep
71849
+ stepsFromConnection: nextStep,
71850
+ ignoreMasking
71818
71851
  });
71819
71852
  target[attributeName] = objectFields.data;
71820
71853
  if (objectFields.partial) {
@@ -71858,7 +71891,8 @@ var CacheInternal = class {
71858
71891
  fields,
71859
71892
  variables,
71860
71893
  linkedList,
71861
- stepsFromConnection
71894
+ stepsFromConnection,
71895
+ ignoreMasking
71862
71896
  }) {
71863
71897
  const result = [];
71864
71898
  let partialData = false;
@@ -71870,7 +71904,8 @@ var CacheInternal = class {
71870
71904
  fields,
71871
71905
  variables,
71872
71906
  linkedList: entry,
71873
- stepsFromConnection
71907
+ stepsFromConnection,
71908
+ ignoreMasking
71874
71909
  });
71875
71910
  result.push(nestedValue.data);
71876
71911
  if (nestedValue.partial) {
@@ -71891,7 +71926,8 @@ var CacheInternal = class {
71891
71926
  parent: entry,
71892
71927
  selection: fields,
71893
71928
  variables,
71894
- stepsFromConnection
71929
+ stepsFromConnection,
71930
+ ignoreMasking
71895
71931
  });
71896
71932
  result.push(data);
71897
71933
  if (partial) {
@@ -71994,11 +72030,54 @@ var CacheInternal = class {
71994
72030
  }
71995
72031
  }
71996
72032
  };
72033
+ function evaluateFragmentVariables(variables, args) {
72034
+ return Object.fromEntries(
72035
+ Object.entries(variables).map(([key, value]) => [key, fragmentVariableValue(value, args)])
72036
+ );
72037
+ }
72038
+ function fragmentVariableValue(value, args) {
72039
+ if (value.kind === "StringValue") {
72040
+ return value.value;
72041
+ }
72042
+ if (value.kind === "BooleanValue") {
72043
+ return value.value;
72044
+ }
72045
+ if (value.kind === "EnumValue") {
72046
+ return value.value;
72047
+ }
72048
+ if (value.kind === "FloatValue") {
72049
+ return parseFloat(value.value);
72050
+ }
72051
+ if (value.kind === "IntValue") {
72052
+ return parseInt(value.value, 10);
72053
+ }
72054
+ if (value.kind === "NullValue") {
72055
+ return null;
72056
+ }
72057
+ if (value.kind === "Variable") {
72058
+ return args[value.name.value];
72059
+ }
72060
+ if (value.kind === "ListValue") {
72061
+ return value.values.map((value2) => fragmentVariableValue(value2, args));
72062
+ }
72063
+ if (value.kind === "ObjectValue") {
72064
+ return value.fields.reduce(
72065
+ (obj, field) => ({
72066
+ ...obj,
72067
+ [field.name.value]: fragmentVariableValue(field.value, args)
72068
+ }),
72069
+ {}
72070
+ );
72071
+ }
72072
+ }
71997
72073
  var rootID = "_ROOT_";
71998
72074
 
71999
72075
  // src/runtime/cache/index.ts
72000
72076
  var cache_default = new Cache();
72001
72077
 
72078
+ // src/runtime/client/plugins/cache.ts
72079
+ var serverSide = typeof globalThis.window === "undefined";
72080
+
72002
72081
  // src/runtime/client/utils/documentPlugins.ts
72003
72082
  var documentPlugin = (kind, source) => {
72004
72083
  return () => {
@@ -72034,7 +72113,6 @@ var documentPlugin = (kind, source) => {
72034
72113
  var query = documentPlugin(ArtifactKind.Query, function() {
72035
72114
  let subscriptionSpec = null;
72036
72115
  let lastVariables = null;
72037
- let artifactName = "";
72038
72116
  return {
72039
72117
  start(ctx, { next }) {
72040
72118
  ctx.variables = {
@@ -72044,8 +72122,7 @@ var query = documentPlugin(ArtifactKind.Query, function() {
72044
72122
  next(ctx);
72045
72123
  },
72046
72124
  end(ctx, { resolve: resolve2, marshalVariables, variablesChanged }) {
72047
- if (variablesChanged(ctx)) {
72048
- artifactName = ctx.artifact.name;
72125
+ if (variablesChanged(ctx) && !ctx.cacheParams?.disableSubscriptions) {
72049
72126
  if (subscriptionSpec) {
72050
72127
  cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
72051
72128
  }
@@ -72066,19 +72143,61 @@ var query = documentPlugin(ArtifactKind.Query, function() {
72066
72143
  });
72067
72144
  }
72068
72145
  };
72069
- cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
72146
+ cache_default.subscribe(subscriptionSpec, lastVariables);
72070
72147
  }
72071
72148
  resolve2(ctx);
72072
72149
  },
72073
72150
  cleanup() {
72074
72151
  if (subscriptionSpec) {
72075
- cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
72152
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.());
72076
72153
  lastVariables = null;
72077
72154
  }
72078
72155
  }
72079
72156
  };
72080
72157
  });
72081
72158
 
72159
+ // src/runtime/client/plugins/fragment.ts
72160
+ var fragment = documentPlugin(ArtifactKind.Fragment, function() {
72161
+ let subscriptionSpec = null;
72162
+ return {
72163
+ start(ctx, { next, resolve: resolve2, variablesChanged, marshalVariables }) {
72164
+ if (!ctx.stuff.parentID) {
72165
+ return next(ctx);
72166
+ }
72167
+ if (variablesChanged(ctx) && !ctx.cacheParams?.disableSubscriptions) {
72168
+ if (subscriptionSpec) {
72169
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
72170
+ }
72171
+ const variables = marshalVariables(ctx);
72172
+ subscriptionSpec = {
72173
+ rootType: ctx.artifact.rootType,
72174
+ selection: ctx.artifact.selection,
72175
+ variables: () => variables,
72176
+ parentID: ctx.stuff.parentID,
72177
+ set: (newValue) => {
72178
+ resolve2(ctx, {
72179
+ data: newValue,
72180
+ errors: null,
72181
+ fetching: false,
72182
+ partial: false,
72183
+ stale: false,
72184
+ source: DataSource.Cache,
72185
+ variables
72186
+ });
72187
+ }
72188
+ };
72189
+ cache_default.subscribe(subscriptionSpec, variables);
72190
+ }
72191
+ next(ctx);
72192
+ },
72193
+ cleanup() {
72194
+ if (subscriptionSpec) {
72195
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.());
72196
+ }
72197
+ }
72198
+ };
72199
+ });
72200
+
72082
72201
  // src/runtime/client/plugins/mutation.ts
72083
72202
  var mutation = documentPlugin(ArtifactKind.Mutation, () => {
72084
72203
  return {
@@ -72234,6 +72353,7 @@ var Config = class {
72234
72353
  this.schemaPollInterval = watchSchema?.interval ?? 2e3;
72235
72354
  this.schemaPollHeaders = watchSchema?.headers ?? {};
72236
72355
  this.rootDir = join2(this.projectRoot, "$houdini");
72356
+ this.#fragmentVariableMaps = {};
72237
72357
  if (defaultKeys) {
72238
72358
  this.defaultKeys = defaultKeys;
72239
72359
  }
@@ -72383,7 +72503,7 @@ var Config = class {
72383
72503
  return `$houdini/${this.artifactDirectoryName}/${name}`;
72384
72504
  }
72385
72505
  keyFieldsForType(type) {
72386
- return keyFieldsForType(this.configFile, type);
72506
+ return this.schema.getQueryType()?.name === type ? [] : keyFieldsForType(this.configFile, type);
72387
72507
  }
72388
72508
  computeID(type, data) {
72389
72509
  return computeID(this.configFile, type, data);
@@ -72402,7 +72522,7 @@ var Config = class {
72402
72522
  ({ kind }) => kind === graphql2.Kind.FRAGMENT_DEFINITION
72403
72523
  );
72404
72524
  if (fragmentDefinitions.length) {
72405
- return fragmentDefinitions.map((fragment) => fragment.name.value).join("_");
72525
+ return fragmentDefinitions[0].name.value;
72406
72526
  }
72407
72527
  throw new Error("Could not generate artifact name for document: " + graphql2.print(document));
72408
72528
  }
@@ -72574,6 +72694,56 @@ var Config = class {
72574
72694
  }, []) ?? [];
72575
72695
  return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
72576
72696
  }
72697
+ #fragmentVariableMaps;
72698
+ registerFragmentVariablesHash({
72699
+ hash,
72700
+ args,
72701
+ fragment: fragment2
72702
+ }) {
72703
+ this.#fragmentVariableMaps[hash] = {
72704
+ args: this.#serializeValueMap(args),
72705
+ fragment: fragment2
72706
+ };
72707
+ }
72708
+ getFragmentVariablesHash(hash) {
72709
+ return this.#fragmentVariableMaps[hash] ?? {
72710
+ fragment: hash,
72711
+ args: {},
72712
+ hash
72713
+ };
72714
+ }
72715
+ #serializeValueMap(map) {
72716
+ if (!map) {
72717
+ return null;
72718
+ }
72719
+ return Object.fromEntries(
72720
+ Object.entries(map).map(([key, input]) => {
72721
+ const result = {
72722
+ kind: input.kind
72723
+ };
72724
+ if (typeof input === "object") {
72725
+ if ("value" in input) {
72726
+ result.value = input.value;
72727
+ }
72728
+ if ("values" in input) {
72729
+ result.values = input.values.map(
72730
+ (value) => this.#serializeValueMap({ foo: value }).foo
72731
+ );
72732
+ }
72733
+ if ("name" in input) {
72734
+ result.name = input.name;
72735
+ }
72736
+ if ("fields" in input) {
72737
+ result.fields = input.fields.map((field) => ({
72738
+ name: field.name,
72739
+ value: this.#serializeValueMap({ foo: field.value }).foo
72740
+ }));
72741
+ }
72742
+ }
72743
+ return [key, result];
72744
+ })
72745
+ );
72746
+ }
72577
72747
  isListFragment(name) {
72578
72748
  return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
72579
72749
  }
@@ -73079,11 +73249,17 @@ function deepMerge(filepath, ...targets) {
73079
73249
  if (targets.length === 1) {
73080
73250
  return targets[0];
73081
73251
  } else if (targets.length === 2) {
73082
- return (0, import_deepmerge.default)(targets[0], targets[1]);
73252
+ return (0, import_deepmerge.default)(targets[0], targets[1], {
73253
+ arrayMerge: (source, update) => [...new Set(source.concat(update))]
73254
+ });
73083
73255
  }
73084
73256
  return deepMerge(filepath, targets[0], deepMerge(filepath, ...targets.slice(1)));
73085
73257
  } catch (e2) {
73086
- throw new HoudiniError({ filepath, message: "could not merge: " + targets });
73258
+ throw new HoudiniError({
73259
+ filepath,
73260
+ message: "could not merge: " + targets,
73261
+ description: e2.message
73262
+ });
73087
73263
  }
73088
73264
  }
73089
73265
 
@@ -73365,16 +73541,16 @@ function flattenSelections({
73365
73541
  filepath,
73366
73542
  selections,
73367
73543
  fragmentDefinitions,
73368
- applyFragments,
73369
- ignoreMaskDisable
73544
+ ignoreMaskDisable,
73545
+ keepFragmentSpreadNodes
73370
73546
  }) {
73371
73547
  const fields = new FieldCollection({
73372
73548
  config: config2,
73373
73549
  filepath,
73374
73550
  selections,
73375
73551
  fragmentDefinitions,
73376
- applyFragments,
73377
- ignoreMaskDisable: !!ignoreMaskDisable
73552
+ ignoreMaskDisable: !!ignoreMaskDisable,
73553
+ keepFragmentSpreadNodes: !!keepFragmentSpreadNodes
73378
73554
  });
73379
73555
  return fields.toSelectionSet();
73380
73556
  }
@@ -73385,57 +73561,59 @@ var FieldCollection = class {
73385
73561
  fields;
73386
73562
  inlineFragments;
73387
73563
  fragmentSpreads;
73388
- applyFragments;
73389
73564
  ignoreMaskDisable;
73565
+ keepFragmentSpreadNodes;
73390
73566
  constructor(args) {
73391
73567
  this.config = args.config;
73392
73568
  this.fragmentDefinitions = args.fragmentDefinitions;
73393
- this.applyFragments = args.applyFragments;
73394
73569
  this.ignoreMaskDisable = args.ignoreMaskDisable;
73570
+ this.keepFragmentSpreadNodes = args.keepFragmentSpreadNodes;
73395
73571
  this.fields = {};
73396
73572
  this.inlineFragments = {};
73397
73573
  this.fragmentSpreads = {};
73398
73574
  this.filepath = args.filepath;
73399
- for (const selection2 of args.selections) {
73400
- this.add(selection2);
73575
+ for (const selection of args.selections) {
73576
+ this.add(selection);
73401
73577
  }
73402
73578
  }
73403
73579
  get size() {
73404
73580
  return Object.keys(this.fields).length + Object.keys(this.inlineFragments).length + Object.keys(this.fragmentSpreads).length;
73405
73581
  }
73406
- add(selection2) {
73407
- if (selection2.kind === "Field") {
73408
- const key = selection2.alias?.value || selection2.name.value;
73582
+ add(selection) {
73583
+ if (selection.kind === "Field") {
73584
+ const key = selection.alias?.value || selection.name.value;
73409
73585
  if (!this.fields[key]) {
73410
73586
  this.fields[key] = {
73411
- astNode: selection2,
73587
+ astNode: selection,
73412
73588
  selection: this.empty()
73413
73589
  };
73414
73590
  }
73415
- for (const subselect of selection2.selectionSet?.selections || []) {
73591
+ for (const subselect of selection.selectionSet?.selections || []) {
73416
73592
  this.fields[key].selection.add(subselect);
73417
73593
  }
73594
+ this.fields[key].selection.fragmentSpreads = this.collectFragmentSpreads(
73595
+ selection.selectionSet?.selections ?? []
73596
+ );
73418
73597
  return;
73419
73598
  }
73420
- if (selection2.kind === "InlineFragment" && !selection2.typeCondition) {
73421
- for (const subselect of selection2.selectionSet.selections) {
73599
+ if (selection.kind === "InlineFragment" && !selection.typeCondition) {
73600
+ for (const subselect of selection.selectionSet.selections) {
73422
73601
  this.add(subselect);
73423
73602
  }
73424
73603
  }
73425
- if (selection2.kind === "InlineFragment" && selection2.typeCondition) {
73426
- this.walkInlineFragment(selection2);
73604
+ if (selection.kind === "InlineFragment" && selection.typeCondition) {
73605
+ this.walkInlineFragment(selection);
73427
73606
  return;
73428
73607
  }
73429
- if (selection2.kind === "FragmentSpread") {
73430
- this.fragmentSpreads[selection2.name.value] = selection2;
73608
+ if (selection.kind === "FragmentSpread") {
73431
73609
  let includeFragments = this.config.defaultFragmentMasking === "disable";
73432
- const maskEnableDirective = selection2.directives?.find(
73610
+ const maskEnableDirective = selection.directives?.find(
73433
73611
  ({ name }) => name.value === this.config.maskEnableDirective
73434
73612
  );
73435
73613
  if (maskEnableDirective) {
73436
73614
  includeFragments = false;
73437
73615
  }
73438
- const maskDisableDirective = selection2.directives?.find(
73616
+ const maskDisableDirective = selection.directives?.find(
73439
73617
  ({ name }) => name.value === this.config.maskDisableDirective
73440
73618
  );
73441
73619
  if (maskDisableDirective) {
@@ -73444,14 +73622,17 @@ var FieldCollection = class {
73444
73622
  if (this.ignoreMaskDisable) {
73445
73623
  includeFragments = true;
73446
73624
  }
73447
- if (!includeFragments || !this.applyFragments) {
73625
+ if (this.keepFragmentSpreadNodes) {
73626
+ this.fragmentSpreads[selection.name.value] = selection;
73627
+ }
73628
+ if (!includeFragments) {
73448
73629
  return;
73449
73630
  }
73450
- const definition = this.fragmentDefinitions[selection2.name.value];
73631
+ const definition = this.fragmentDefinitions[selection.name.value];
73451
73632
  if (!definition) {
73452
73633
  throw new HoudiniError({
73453
73634
  filepath: this.filepath,
73454
- message: "Could not find referenced fragment definition: " + selection2.name.value
73635
+ message: "Could not find referenced fragment definition: " + selection.name.value + "\n" + JSON.stringify(Object.keys(this.fragmentDefinitions), null, 4)
73455
73636
  });
73456
73637
  }
73457
73638
  this.add({
@@ -73470,19 +73651,35 @@ var FieldCollection = class {
73470
73651
  });
73471
73652
  }
73472
73653
  }
73654
+ collectFragmentSpreads(selections, result = {}) {
73655
+ for (const selection of selections) {
73656
+ if (selection.kind === "Field") {
73657
+ continue;
73658
+ }
73659
+ if (selection.kind === "InlineFragment") {
73660
+ this.collectFragmentSpreads(selection.selectionSet.selections, result);
73661
+ continue;
73662
+ }
73663
+ if (selection.kind === "FragmentSpread") {
73664
+ result[selection.name.value] = selection;
73665
+ continue;
73666
+ }
73667
+ }
73668
+ return result;
73669
+ }
73473
73670
  toSelectionSet() {
73474
- return Object.values(this.inlineFragments).flatMap((fragment) => {
73475
- if (fragment.selection.size === 0) {
73671
+ return Object.values(this.inlineFragments).flatMap((fragment2) => {
73672
+ if (fragment2.selection.size === 0) {
73476
73673
  return [];
73477
73674
  }
73478
- fragment.astNode = {
73479
- ...fragment.astNode,
73675
+ fragment2.astNode = {
73676
+ ...fragment2.astNode,
73480
73677
  selectionSet: {
73481
- ...fragment.astNode.selectionSet,
73482
- selections: fragment.selection.toSelectionSet()
73678
+ ...fragment2.astNode.selectionSet,
73679
+ selections: fragment2.selection.toSelectionSet()
73483
73680
  }
73484
73681
  };
73485
- return [fragment.astNode];
73682
+ return [fragment2.astNode];
73486
73683
  }).concat(
73487
73684
  Object.values(this.fields).map((field) => {
73488
73685
  if (field.astNode.selectionSet) {
@@ -73492,15 +73689,15 @@ var FieldCollection = class {
73492
73689
  })
73493
73690
  ).concat(Object.values(this.fragmentSpreads));
73494
73691
  }
73495
- walkInlineFragment(selection2) {
73496
- const key = selection2.typeCondition.name.value;
73692
+ walkInlineFragment(selection) {
73693
+ const key = selection.typeCondition.name.value;
73497
73694
  if (!this.inlineFragments[key]) {
73498
73695
  this.inlineFragments[key] = {
73499
- astNode: selection2,
73696
+ astNode: selection,
73500
73697
  selection: this.empty()
73501
73698
  };
73502
73699
  }
73503
- for (const subselect of selection2.selectionSet.selections || []) {
73700
+ for (const subselect of selection.selectionSet.selections || []) {
73504
73701
  if (subselect.kind !== "InlineFragment" || !subselect.typeCondition) {
73505
73702
  this.inlineFragments[key].selection.add(subselect);
73506
73703
  continue;
@@ -73514,8 +73711,8 @@ var FieldCollection = class {
73514
73711
  fragmentDefinitions: this.fragmentDefinitions,
73515
73712
  selections: [],
73516
73713
  filepath: this.filepath,
73517
- applyFragments: this.applyFragments,
73518
- ignoreMaskDisable: this.ignoreMaskDisable
73714
+ ignoreMaskDisable: this.ignoreMaskDisable,
73715
+ keepFragmentSpreadNodes: this.keepFragmentSpreadNodes
73519
73716
  });
73520
73717
  }
73521
73718
  };
@@ -73593,13 +73790,13 @@ function murmurHash(str) {
73593
73790
  // src/codegen/transforms/fragmentVariables.ts
73594
73791
  var graphql5 = __toESM(require_graphql2(), 1);
73595
73792
 
73596
- // src/codegen/transforms/composeQueries.ts
73793
+ // src/codegen/transforms/collectDefinitions.ts
73597
73794
  var import_graphql30 = __toESM(require_graphql2(), 1);
73598
73795
  async function includeFragmentDefinitions(config2, documents) {
73599
- const fragments = collectFragments(config2, documents);
73796
+ const fragments = collectDefinitions(config2, documents);
73600
73797
  for (const [index, { name, document, filename }] of documents.entries()) {
73601
73798
  const operation = document.definitions.find(
73602
- ({ kind }) => kind === import_graphql30.Kind.OPERATION_DEFINITION
73799
+ (def) => def.kind === import_graphql30.Kind.OPERATION_DEFINITION || def.kind === "FragmentDefinition"
73603
73800
  );
73604
73801
  if (!operation) {
73605
73802
  continue;
@@ -73618,7 +73815,7 @@ async function includeFragmentDefinitions(config2, documents) {
73618
73815
  };
73619
73816
  }
73620
73817
  }
73621
- function collectFragments(config2, docs) {
73818
+ function collectDefinitions(config2, docs) {
73622
73819
  return docs.reduce((acc, doc) => {
73623
73820
  const definitions = doc.document.definitions.reduce(
73624
73821
  (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
@@ -73642,11 +73839,11 @@ function findRequiredFragments(selectionSet) {
73642
73839
  return [];
73643
73840
  }
73644
73841
  const referencedFragments = [];
73645
- for (const selection2 of selectionSet.selections) {
73646
- if (selection2.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
73647
- referencedFragments.push(selection2.name.value);
73648
- } else if (selection2.selectionSet) {
73649
- referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
73842
+ for (const selection of selectionSet.selections) {
73843
+ if (selection.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
73844
+ referencedFragments.push(selection.name.value);
73845
+ } else if (selection.selectionSet) {
73846
+ referencedFragments.push(...findRequiredFragments(selection.selectionSet));
73650
73847
  }
73651
73848
  }
73652
73849
  return referencedFragments;
@@ -73679,7 +73876,7 @@ function flattenFragments(filepath, operation, fragments) {
73679
73876
  // src/codegen/transforms/fragmentVariables.ts
73680
73877
  var GraphqlKinds2 = graphql5.Kind;
73681
73878
  async function fragmentVariables(config2, documents) {
73682
- const fragments = collectFragments(config2, documents);
73879
+ const fragments = collectDefinitions(config2, documents);
73683
73880
  const generatedFragments = {};
73684
73881
  const visitedFragments = /* @__PURE__ */ new Set();
73685
73882
  for (const doc2 of documents) {
@@ -73739,9 +73936,17 @@ function inlineFragmentArgs({
73739
73936
  ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
73740
73937
  const result = graphql5.visit(document, {
73741
73938
  FragmentSpread(node) {
73939
+ if (!fragmentDefinitions[node.name.value]) {
73940
+ throw new Error("Could not find definition for fragment" + node.name.value);
73941
+ }
73742
73942
  const { definition } = fragmentDefinitions[node.name.value];
73743
73943
  let { args, hash } = collectWithArguments(config2, filepath, node, scope);
73744
73944
  const newFragmentName = `${node.name.value}${hash}`;
73945
+ config2.registerFragmentVariablesHash({
73946
+ hash: newFragmentName,
73947
+ fragment: node.name.value,
73948
+ args
73949
+ });
73745
73950
  if (!visitedFragments.has(newFragmentName)) {
73746
73951
  visitedFragments.add(newFragmentName);
73747
73952
  const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
@@ -74140,7 +74345,7 @@ function operationObject({
74140
74345
  listName,
74141
74346
  operationKind,
74142
74347
  type,
74143
- selection: selection2,
74348
+ selection,
74144
74349
  filepath
74145
74350
  }) {
74146
74351
  let parentID;
@@ -74148,7 +74353,7 @@ function operationObject({
74148
74353
  let position = config2.internalListPosition;
74149
74354
  let allLists = config2.defaultListTarget ?? void 0;
74150
74355
  let operationWhen;
74151
- const internalDirectives = selection2.directives?.filter(
74356
+ const internalDirectives = selection.directives?.filter(
74152
74357
  (directive) => config2.isInternalDirective(directive.name.value)
74153
74358
  );
74154
74359
  if (internalDirectives && internalDirectives.length > 0) {
@@ -74384,7 +74589,7 @@ async function paginate(config2, documents) {
74384
74589
  let fragmentName = "";
74385
74590
  let refetchQueryName = "";
74386
74591
  let nodeQuery = false;
74387
- let fragment = "";
74592
+ let fragment2 = "";
74388
74593
  let paginateMode = config2.defaultPaginateMode;
74389
74594
  doc.document = graphql10.visit(doc.document, {
74390
74595
  OperationDefinition(node) {
@@ -74427,7 +74632,7 @@ async function paginate(config2, documents) {
74427
74632
  };
74428
74633
  },
74429
74634
  FragmentDefinition(node) {
74430
- fragment = node.typeCondition.name.value;
74635
+ fragment2 = node.typeCondition.name.value;
74431
74636
  fragmentName = node.name.value;
74432
74637
  refetchQueryName = config2.paginationQueryName(fragmentName);
74433
74638
  nodeQuery = node.typeCondition.name.value !== config2.schema.getQueryType()?.name;
@@ -74474,17 +74679,17 @@ async function paginate(config2, documents) {
74474
74679
  }
74475
74680
  });
74476
74681
  let targetType = config2.schema.getQueryType()?.name || "";
74477
- if (fragment) {
74682
+ if (fragment2) {
74478
74683
  const nodeInterface = config2.schema.getType("Node");
74479
74684
  if (nodeInterface) {
74480
74685
  const { objects, interfaces } = config2.schema.getImplementations(nodeInterface);
74481
- if (objects.find((obj) => obj.name === fragment) || interfaces.find((int) => int.name === fragment)) {
74686
+ if (objects.find((obj) => obj.name === fragment2) || interfaces.find((int) => int.name === fragment2)) {
74482
74687
  targetType = "Node";
74483
74688
  } else {
74484
- targetType = fragment;
74689
+ targetType = fragment2;
74485
74690
  }
74486
74691
  } else {
74487
- targetType = fragment;
74692
+ targetType = fragment2;
74488
74693
  }
74489
74694
  }
74490
74695
  const pageSize = flags.first.defaultValue ?? flags.last.defaultValue ?? flags.limit.defaultValue;
@@ -74506,7 +74711,7 @@ async function paginate(config2, documents) {
74506
74711
  start,
74507
74712
  mode: paginateMode
74508
74713
  };
74509
- if (!fragment) {
74714
+ if (!fragment2) {
74510
74715
  continue;
74511
74716
  }
74512
74717
  const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
@@ -74527,15 +74732,22 @@ async function paginate(config2, documents) {
74527
74732
  ["arguments"]: paginationArgs.map(
74528
74733
  ({ name }) => variableAsArgument(name)
74529
74734
  )
74735
+ },
74736
+ {
74737
+ kind: graphql10.Kind.DIRECTIVE,
74738
+ name: {
74739
+ kind: "Name",
74740
+ value: config2.maskDisableDirective
74741
+ }
74530
74742
  }
74531
74743
  ]
74532
74744
  }
74533
74745
  ];
74534
- const keys = config2.keyFieldsForType(!nodeQuery ? config2.schema.getQueryType()?.name || "" : fragment).flatMap((key) => {
74535
- if (fragment === config2.schema.getQueryType()?.name) {
74746
+ const keys = config2.keyFieldsForType(!nodeQuery ? config2.schema.getQueryType()?.name || "" : fragment2).flatMap((key) => {
74747
+ if (fragment2 === config2.schema.getQueryType()?.name) {
74536
74748
  return [];
74537
74749
  }
74538
- const fragmentType = config2.schema.getType(fragment);
74750
+ const fragmentType = config2.schema.getType(fragment2);
74539
74751
  const { type, wrappers } = unwrapType(
74540
74752
  config2,
74541
74753
  fragmentType.getFields()[key].type
@@ -74547,7 +74759,7 @@ async function paginate(config2, documents) {
74547
74759
  }
74548
74760
  ];
74549
74761
  });
74550
- const typeConfig = config2.typeConfig?.[fragment];
74762
+ const typeConfig = config2.typeConfig?.[fragment2];
74551
74763
  const queryDoc = {
74552
74764
  kind: graphql10.Kind.DOCUMENT,
74553
74765
  definitions: [
@@ -74889,7 +75101,7 @@ async function addListFragments(config2, documents) {
74889
75101
  );
74890
75102
  const targetField = ancestors[ancestors.length - 1];
74891
75103
  const targetFieldDefinition = parentType.getFields()[targetField.name.value];
74892
- const { selection: selection2, type, connection } = connectionSelection(
75104
+ const { selection, type, connection } = connectionSelection(
74893
75105
  config2,
74894
75106
  targetFieldDefinition,
74895
75107
  parentTypeFromAncestors(
@@ -74900,7 +75112,7 @@ async function addListFragments(config2, documents) {
74900
75112
  ancestors[ancestors.length - 1].selectionSet
74901
75113
  );
74902
75114
  lists[nameArg.value.value] = {
74903
- selection: selection2,
75115
+ selection,
74904
75116
  type,
74905
75117
  filename: doc.filename
74906
75118
  };
@@ -74978,14 +75190,14 @@ async function addListFragments(config2, documents) {
74978
75190
  const generatedDoc = {
74979
75191
  kind: graphql11.Kind.DOCUMENT,
74980
75192
  definitions: Object.entries(lists).flatMap(
74981
- ([name, { selection: selection2, type }]) => {
75193
+ ([name, { selection, type }]) => {
74982
75194
  const schemaType = config2.schema.getType(type.name);
74983
- if (!selection2) {
75195
+ if (!selection) {
74984
75196
  throw new HoudiniError({ message: "Lists must have a selection" });
74985
75197
  }
74986
75198
  const fragmentSelection = {
74987
75199
  kind: graphql11.Kind.SELECTION_SET,
74988
- selections: [...selection2.selections]
75200
+ selections: [...selection.selections]
74989
75201
  };
74990
75202
  if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
74991
75203
  (field) => field.kind === "Field" && config2.keyFieldsForType(type.name).includes(field.name.value)
@@ -75077,7 +75289,7 @@ async function addListFragments(config2, documents) {
75077
75289
  artifact: null
75078
75290
  });
75079
75291
  }
75080
- function connectionSelection(config2, field, type, selection2) {
75292
+ function connectionSelection(config2, field, type, selection) {
75081
75293
  const fieldArgs = field.args.reduce(
75082
75294
  (args, arg) => ({
75083
75295
  ...args,
@@ -75086,34 +75298,34 @@ function connectionSelection(config2, field, type, selection2) {
75086
75298
  {}
75087
75299
  );
75088
75300
  if (fieldArgs["limit"]) {
75089
- return { selection: selection2, type, connection: false, error: null };
75301
+ return { selection, type, connection: false, error: null };
75090
75302
  }
75091
75303
  const forwardPagination = fieldArgs["first"] === "Int" && ["Cursor", "String"].includes(fieldArgs["after"]);
75092
75304
  const backwardsPagination = fieldArgs["last"] === "Int" && ["Cursor", "String"].includes(fieldArgs["before"]);
75093
75305
  if (!forwardPagination && !backwardsPagination) {
75094
- return { selection: selection2, type, connection: false, error: missingPaginationArgMessage(config2) };
75306
+ return { selection, type, connection: false, error: missingPaginationArgMessage(config2) };
75095
75307
  }
75096
- const edgesField = selection2?.selections.find(
75097
- (selection3) => selection3.kind === "Field" && selection3.name.value === "edges"
75308
+ const edgesField = selection?.selections.find(
75309
+ (selection2) => selection2.kind === "Field" && selection2.name.value === "edges"
75098
75310
  );
75099
75311
  if (!edgesField) {
75100
- return { selection: selection2, type, connection: false, error: missingEdgeSelectionMessage(config2) };
75312
+ return { selection, type, connection: false, error: missingEdgeSelectionMessage(config2) };
75101
75313
  }
75102
75314
  const nodeSelection = edgesField.selectionSet?.selections.find(
75103
- (selection3) => selection3.kind === "Field" && selection3.name.value === "node"
75315
+ (selection2) => selection2.kind === "Field" && selection2.name.value === "node"
75104
75316
  );
75105
75317
  if (!nodeSelection.selectionSet) {
75106
- return { selection: selection2, type, connection: false, error: missingNodeSelectionMessage(config2) };
75318
+ return { selection, type, connection: false, error: missingNodeSelectionMessage(config2) };
75107
75319
  }
75108
75320
  const edgeField = unwrapType(config2, field.type).type.getFields()["edges"];
75109
75321
  const { wrappers, type: edgeFieldType } = unwrapType(config2, edgeField.type);
75110
75322
  const list = wrappers[wrappers.length - 2] === "List" /* List */;
75111
75323
  if (!list) {
75112
- return { selection: selection2, type, connection: false, error: edgeInvalidTypeMessage(config2) };
75324
+ return { selection, type, connection: false, error: edgeInvalidTypeMessage(config2) };
75113
75325
  }
75114
75326
  const nodeField = edgeFieldType.getFields()["node"];
75115
75327
  if (!nodeField) {
75116
- return { selection: selection2, type, connection: false, error: nodeNotDefinedMessage(config2) };
75328
+ return { selection, type, connection: false, error: nodeNotDefinedMessage(config2) };
75117
75329
  }
75118
75330
  return {
75119
75331
  selection: nodeSelection.selectionSet,
@@ -75192,59 +75404,45 @@ function fieldKey(config2, field) {
75192
75404
  }
75193
75405
 
75194
75406
  // src/codegen/generators/artifacts/selection.ts
75195
- function selection({
75407
+ function selection_default(args) {
75408
+ const typeMap = {};
75409
+ const abstractTypes = [];
75410
+ return mergeSelection({
75411
+ object: prepareSelection({ ...args, typeMap, abstractTypes }),
75412
+ filepath: args.filepath,
75413
+ typeMap,
75414
+ abstractTypes
75415
+ });
75416
+ }
75417
+ function prepareSelection({
75196
75418
  config: config2,
75197
75419
  filepath,
75198
75420
  rootType,
75199
75421
  selections,
75200
75422
  operations,
75201
75423
  path: path2 = [],
75202
- includeFragments,
75203
75424
  document,
75204
- inConnection
75425
+ inConnection,
75426
+ typeMap,
75427
+ abstractTypes
75205
75428
  }) {
75206
75429
  let object = {};
75207
- const typeMap = {};
75208
- const abstractTypes = [];
75209
75430
  for (const field of selections) {
75210
- if (field.kind === "FragmentSpread" && includeFragments) {
75211
- const fragmentDefinition = document.document.definitions.find(
75212
- (defn) => defn.kind === "FragmentDefinition" && defn.name.value === field.name.value
75213
- );
75214
- if (!fragmentDefinition) {
75215
- throw new HoudiniError({
75216
- filepath,
75217
- message: "selection: could not find definition for fragment " + field.name.value
75218
- });
75219
- }
75220
- object = deepMerge(
75221
- filepath,
75222
- object,
75223
- selection({
75224
- config: config2,
75225
- filepath,
75226
- rootType: fragmentDefinition.typeCondition.name.value,
75227
- operations,
75228
- selections: fragmentDefinition.selectionSet.selections,
75229
- path: path2,
75230
- includeFragments,
75231
- document
75232
- })
75233
- );
75234
- } else if (field.kind === "InlineFragment") {
75431
+ if (field.kind === "InlineFragment") {
75235
75432
  if (!field.typeCondition || field.typeCondition.name.value === rootType) {
75236
75433
  object.fields = deepMerge(
75237
75434
  filepath,
75238
75435
  object.fields || {},
75239
- selection({
75436
+ prepareSelection({
75240
75437
  config: config2,
75241
75438
  filepath,
75242
75439
  rootType: field.typeCondition?.name.value || rootType,
75243
75440
  operations,
75244
75441
  selections: field.selectionSet.selections,
75245
75442
  path: path2,
75246
- includeFragments,
75247
- document
75443
+ document,
75444
+ typeMap,
75445
+ abstractTypes
75248
75446
  }).fields || {}
75249
75447
  );
75250
75448
  } else {
@@ -75282,15 +75480,16 @@ function selection({
75282
75480
  }
75283
75481
  object.abstractFields.fields = {
75284
75482
  ...object.abstractFields.fields,
75285
- [field.typeCondition.name.value]: selection({
75483
+ [field.typeCondition.name.value]: prepareSelection({
75286
75484
  config: config2,
75287
75485
  filepath,
75288
75486
  rootType: field.typeCondition?.name.value || rootType,
75289
75487
  operations,
75290
75488
  selections: field.selectionSet.selections,
75291
75489
  path: path2,
75292
- includeFragments,
75293
- document
75490
+ document,
75491
+ typeMap,
75492
+ abstractTypes
75294
75493
  }).fields
75295
75494
  };
75296
75495
  }
@@ -75311,10 +75510,14 @@ function selection({
75311
75510
  }
75312
75511
  const typeName = fieldType.toString();
75313
75512
  const pathSoFar = path2.concat(attributeName);
75314
- const fieldObj = {
75513
+ const keys = config2.keyFieldsForType(rootType);
75514
+ let fieldObj = {
75315
75515
  type: typeName,
75316
75516
  keyRaw: fieldKey(config2, field)
75317
75517
  };
75518
+ if (keys.includes(field.name.value)) {
75519
+ fieldObj.visible = true;
75520
+ }
75318
75521
  if (nullable) {
75319
75522
  fieldObj.nullable = true;
75320
75523
  }
@@ -75362,16 +75565,17 @@ function selection({
75362
75565
  }
75363
75566
  if (field.selectionSet) {
75364
75567
  const connectionState = paginated && document.refetch?.method === "cursor" || continueConnection;
75365
- fieldObj.selection = selection({
75568
+ fieldObj.selection = prepareSelection({
75366
75569
  config: config2,
75367
75570
  filepath,
75368
75571
  rootType: typeName,
75369
75572
  selections: field.selectionSet.selections,
75370
75573
  operations,
75371
75574
  path: pathSoFar,
75372
- includeFragments,
75373
75575
  document,
75374
- inConnection: connectionState
75576
+ inConnection: connectionState,
75577
+ typeMap,
75578
+ abstractTypes
75375
75579
  });
75376
75580
  }
75377
75581
  if (field.arguments?.length && fieldObj.list) {
@@ -75386,12 +75590,29 @@ function selection({
75386
75590
  if (graphql13.isInterfaceType(fieldType) || graphql13.isUnionType(fieldType)) {
75387
75591
  fieldObj.abstract = true;
75388
75592
  }
75593
+ if (object.fields?.[attributeName]) {
75594
+ fieldObj = deepMerge(filepath, object.fields[attributeName], fieldObj);
75595
+ }
75389
75596
  object.fields = {
75390
75597
  ...object.fields,
75391
75598
  [attributeName]: fieldObj
75392
75599
  };
75600
+ } else if (field.kind === "FragmentSpread") {
75601
+ const { fragment: fragment2, args } = config2.getFragmentVariablesHash(field.name.value);
75602
+ object.fragments = {
75603
+ ...object.fragments,
75604
+ [fragment2]: args ?? {}
75605
+ };
75393
75606
  }
75394
75607
  }
75608
+ return object;
75609
+ }
75610
+ function mergeSelection({
75611
+ filepath,
75612
+ object,
75613
+ typeMap,
75614
+ abstractTypes
75615
+ }) {
75395
75616
  if (Object.keys(object.fields || {}).length > 0 && object.abstractFields && Object.keys(object.abstractFields.fields).length > 0) {
75396
75617
  for (const [typeName, possibles] of Object.entries(typeMap)) {
75397
75618
  let overlap = false;
@@ -75399,8 +75620,8 @@ function selection({
75399
75620
  if (object.abstractFields.fields[typeName]) {
75400
75621
  object.abstractFields.fields[typeName] = deepMerge(
75401
75622
  filepath,
75402
- object.abstractFields.fields[typeName] || {},
75403
- object.abstractFields.fields[possible]
75623
+ object.abstractFields.fields[typeName] ?? {},
75624
+ object.abstractFields.fields[possible] ?? {}
75404
75625
  );
75405
75626
  overlap = true;
75406
75627
  }
@@ -75431,6 +75652,30 @@ function selection({
75431
75652
  }
75432
75653
  }
75433
75654
  }
75655
+ for (const [key, value] of Object.entries(object.fields ?? {})) {
75656
+ const selection = value.selection;
75657
+ if (selection) {
75658
+ mergeSelection({
75659
+ filepath,
75660
+ typeMap,
75661
+ abstractTypes,
75662
+ object: selection
75663
+ });
75664
+ }
75665
+ }
75666
+ for (const [type, selection] of Object.entries(object.abstractFields?.fields ?? {})) {
75667
+ for (const [key, value] of Object.entries(selection ?? {})) {
75668
+ const selection2 = value.selection;
75669
+ if (selection2) {
75670
+ mergeSelection({
75671
+ filepath,
75672
+ typeMap,
75673
+ abstractTypes,
75674
+ object: selection2
75675
+ });
75676
+ }
75677
+ }
75678
+ }
75434
75679
  return object;
75435
75680
  }
75436
75681
 
@@ -75495,7 +75740,12 @@ function artifactGenerator(stats) {
75495
75740
  writeIndexFile(config2, docs)
75496
75741
  ].concat(
75497
75742
  docs.map(async (doc) => {
75498
- const { document, name, generateArtifact } = doc;
75743
+ const {
75744
+ document,
75745
+ name,
75746
+ generateArtifact,
75747
+ originalParsed
75748
+ } = doc;
75499
75749
  if (!generateArtifact) {
75500
75750
  return;
75501
75751
  }
@@ -75534,6 +75784,16 @@ function artifactGenerator(stats) {
75534
75784
  );
75535
75785
  let rootType = "";
75536
75786
  let selectionSet;
75787
+ let originalSelectionSet = null;
75788
+ const fragmentDefinitions = doc.document.definitions.filter(
75789
+ (definition) => definition.kind === "FragmentDefinition"
75790
+ ).reduce(
75791
+ (prev, definition) => ({
75792
+ ...prev,
75793
+ [definition.name.value]: definition
75794
+ }),
75795
+ {}
75796
+ );
75537
75797
  if (docKind !== ArtifactKind.Fragment) {
75538
75798
  const operation = operations[0];
75539
75799
  if (operation.operation === "query") {
@@ -75550,9 +75810,12 @@ function artifactGenerator(stats) {
75550
75810
  });
75551
75811
  }
75552
75812
  selectionSet = operation.selectionSet;
75813
+ if (originalParsed.definitions[0].kind === "OperationDefinition") {
75814
+ originalSelectionSet = originalParsed.definitions[0].selectionSet;
75815
+ }
75553
75816
  } else {
75554
75817
  const matchingFragment = fragments.find(
75555
- (fragment) => fragment.name.value === name
75818
+ (fragment2) => fragment2.name.value === name
75556
75819
  );
75557
75820
  if (!matchingFragment) {
75558
75821
  throw new HoudiniError({
@@ -75562,6 +75825,12 @@ function artifactGenerator(stats) {
75562
75825
  }
75563
75826
  rootType = matchingFragment.typeCondition.name.value;
75564
75827
  selectionSet = matchingFragment.selectionSet;
75828
+ if (originalParsed.definitions[0].kind === "FragmentDefinition") {
75829
+ originalSelectionSet = originalParsed.definitions[0].selectionSet;
75830
+ }
75831
+ }
75832
+ if (!originalSelectionSet) {
75833
+ throw new Error("Not original selection set!");
75565
75834
  }
75566
75835
  let inputs = operations[0]?.variableDefinitions;
75567
75836
  let directive = fragments[0]?.directives?.find(
@@ -75570,21 +75839,18 @@ function artifactGenerator(stats) {
75570
75839
  if (docKind === ArtifactKind.Fragment && directive) {
75571
75840
  inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
75572
75841
  }
75573
- const mergedSelection = flattenSelections({
75842
+ const mask = selection_default({
75574
75843
  config: config2,
75575
75844
  filepath: doc.filename,
75576
- selections: selectionSet.selections,
75577
- fragmentDefinitions: doc.document.definitions.filter(
75578
- (definition) => definition.kind === "FragmentDefinition"
75579
- ).reduce(
75580
- (prev, definition) => ({
75581
- ...prev,
75582
- [definition.name.value]: definition
75583
- }),
75584
- {}
75585
- ),
75586
- ignoreMaskDisable: docKind === "HoudiniQuery",
75587
- applyFragments: docKind !== "HoudiniFragment"
75845
+ rootType,
75846
+ operations: {},
75847
+ document: doc,
75848
+ selections: flattenSelections({
75849
+ config: config2,
75850
+ filepath: doc.filename,
75851
+ selections: selectionSet.selections,
75852
+ fragmentDefinitions
75853
+ })
75588
75854
  });
75589
75855
  let artifact = {
75590
75856
  name,
@@ -75593,21 +75859,29 @@ function artifactGenerator(stats) {
75593
75859
  refetch: doc.refetch,
75594
75860
  raw: rawString,
75595
75861
  rootType,
75596
- selection: selection({
75862
+ selection: selection_default({
75597
75863
  config: config2,
75598
75864
  filepath: doc.filename,
75599
75865
  rootType,
75600
- selections: mergedSelection,
75866
+ selections: flattenSelections({
75867
+ config: config2,
75868
+ filepath: doc.filename,
75869
+ selections: selectionSet.selections,
75870
+ fragmentDefinitions,
75871
+ ignoreMaskDisable: docKind !== "HoudiniFragment",
75872
+ keepFragmentSpreadNodes: true
75873
+ }),
75601
75874
  operations: operationsByPath(
75602
75875
  config2,
75603
75876
  doc.filename,
75604
75877
  operations[0],
75605
75878
  filterTypes
75606
75879
  ),
75607
- includeFragments: docKind !== "HoudiniFragment",
75608
75880
  document: doc
75609
- })
75881
+ }),
75882
+ pluginData: {}
75610
75883
  };
75884
+ applyMask(config2, artifact.selection, mask);
75611
75885
  artifact.pluginData = {};
75612
75886
  for (const plugin2 of config2.plugins) {
75613
75887
  if (!plugin2.artifactData) {
@@ -75684,6 +75958,49 @@ function artifactGenerator(stats) {
75684
75958
  stats.deleted = await cleanupFiles(config2.artifactDirectory, listOfArtifacts);
75685
75959
  };
75686
75960
  }
75961
+ function applyMask(config2, target, mask) {
75962
+ for (const [fieldName, value] of Object.entries(mask.fields ?? {})) {
75963
+ const targetSelection = target.fields?.[fieldName];
75964
+ if (!targetSelection || !mask.fields) {
75965
+ continue;
75966
+ }
75967
+ targetSelection.visible = true;
75968
+ if (targetSelection.selection && value.selection) {
75969
+ applyMask(config2, targetSelection.selection, value.selection);
75970
+ }
75971
+ }
75972
+ for (const [type, selection] of Object.entries(mask.abstractFields?.fields ?? {})) {
75973
+ if (!selection) {
75974
+ continue;
75975
+ }
75976
+ if (target.abstractFields?.fields[type]) {
75977
+ applyMask(config2, { fields: target.abstractFields.fields[type] }, { fields: selection });
75978
+ }
75979
+ const targetType = config2.schema.getType(type);
75980
+ if (!targetType) {
75981
+ continue;
75982
+ }
75983
+ if (graphql14.isAbstractType(targetType)) {
75984
+ for (const possible of config2.schema.getPossibleTypes(targetType)) {
75985
+ if (target.abstractFields?.fields[possible.name]) {
75986
+ applyMask(
75987
+ config2,
75988
+ { fields: target.abstractFields.fields[possible.name] },
75989
+ { fields: selection }
75990
+ );
75991
+ }
75992
+ }
75993
+ }
75994
+ const mappedType = target.abstractFields?.typeMap[type];
75995
+ if (target.abstractFields && mappedType && target.abstractFields.fields[mappedType]) {
75996
+ applyMask(
75997
+ config2,
75998
+ { fields: target.abstractFields.fields[mappedType] },
75999
+ { fields: selection }
76000
+ );
76001
+ }
76002
+ }
76003
+ }
75687
76004
 
75688
76005
  // src/codegen/generators/runtime/graphqlFunction.ts
75689
76006
  var recast6 = __toESM(require_main2(), 1);
@@ -76009,7 +76326,7 @@ function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingS
76009
76326
  var graphql18 = __toESM(require_graphql2(), 1);
76010
76327
  var recast10 = __toESM(require_main2(), 1);
76011
76328
  var AST10 = recast10.types.builders;
76012
- var fragmentKey = "$fragments";
76329
+ var fragmentKey2 = " $fragments";
76013
76330
  function inlineType({
76014
76331
  config: config2,
76015
76332
  filepath,
@@ -76049,24 +76366,24 @@ function inlineType({
76049
76366
  const rootObj = type;
76050
76367
  const inlineFragments = {};
76051
76368
  const selectedFields = [];
76052
- for (const selection2 of selections) {
76053
- if (selection2.kind === "InlineFragment" && selection2.typeCondition) {
76054
- const fragmentType = config2.schema.getType(selection2.typeCondition.name.value);
76369
+ for (const selection of selections) {
76370
+ if (selection.kind === "InlineFragment" && selection.typeCondition) {
76371
+ const fragmentType = config2.schema.getType(selection.typeCondition.name.value);
76055
76372
  if (!graphql18.isInterfaceType(type) && !graphql18.isUnionType(type)) {
76056
- selectedFields.push(...selection2.selectionSet.selections);
76373
+ selectedFields.push(...selection.selectionSet.selections);
76057
76374
  continue;
76058
76375
  }
76059
76376
  if (!graphql18.isInterfaceType(fragmentType) && !graphql18.isUnionType(fragmentType)) {
76060
76377
  if (!inlineFragments[fragmentType.name]) {
76061
76378
  inlineFragments[fragmentType.name] = [];
76062
76379
  }
76063
- inlineFragments[fragmentType.name].push(...selection2.selectionSet.selections);
76380
+ inlineFragments[fragmentType.name].push(...selection.selectionSet.selections);
76064
76381
  continue;
76065
76382
  }
76066
76383
  const possibleParents = config2.schema.getPossibleTypes(type).map((t2) => t2.name);
76067
76384
  const freeSelections = [];
76068
76385
  const typeSpecificSelections = {};
76069
- for (const node of selection2.selectionSet.selections) {
76386
+ for (const node of selection.selectionSet.selections) {
76070
76387
  if (node.kind !== "InlineFragment") {
76071
76388
  freeSelections.push(node);
76072
76389
  } else if (node.typeCondition) {
@@ -76089,23 +76406,30 @@ function inlineType({
76089
76406
  );
76090
76407
  }
76091
76408
  }
76092
- } else if (selection2.kind === "InlineFragment" && !selection2.typeCondition) {
76093
- selectedFields.push(...selection2.selectionSet.selections);
76409
+ } else if (selection.kind === "InlineFragment" && !selection.typeCondition) {
76410
+ selectedFields.push(...selection.selectionSet.selections);
76094
76411
  } else {
76095
- selectedFields.push(selection2);
76412
+ selectedFields.push(selection);
76096
76413
  }
76097
76414
  }
76415
+ const fields = Object.values(
76416
+ selectedFields.filter((field) => field.kind === "Field").reduce(
76417
+ (sel, field) => ({
76418
+ ...sel,
76419
+ [field.alias?.value ?? field.name.value]: field
76420
+ }),
76421
+ {}
76422
+ )
76423
+ );
76098
76424
  result = AST10.tsTypeLiteral([
76099
- ...(selectedFields || []).filter(
76100
- (field) => field.kind === "Field"
76101
- ).map((selection2) => {
76102
- const { field } = selectionTypeInfo(config2.schema, filepath, rootObj, selection2);
76103
- const attributeName = selection2.alias?.value || selection2.name.value;
76425
+ ...fields.map((selection) => {
76426
+ const { field } = selectionTypeInfo(config2.schema, filepath, rootObj, selection);
76427
+ const attributeName = selection.alias?.value || selection.name.value;
76104
76428
  let attributeType = inlineType({
76105
76429
  config: config2,
76106
76430
  filepath,
76107
76431
  rootType: field.type,
76108
- selections: selection2.selectionSet?.selections,
76432
+ selections: selection.selectionSet?.selections,
76109
76433
  root: false,
76110
76434
  allowReadonly,
76111
76435
  visitedTypes,
@@ -76114,7 +76438,7 @@ function inlineType({
76114
76438
  includeFragments,
76115
76439
  allOptional
76116
76440
  });
76117
- const hasIncludeOrSkipDirective = selection2.directives && selection2.directives.filter(
76441
+ const hasIncludeOrSkipDirective = selection.directives && selection.directives.filter(
76118
76442
  (directive) => directive.name.value === "include" || directive.name.value === "skip"
76119
76443
  ).length > 0;
76120
76444
  if (hasIncludeOrSkipDirective) {
@@ -76138,15 +76462,13 @@ function inlineType({
76138
76462
  result.members.push(
76139
76463
  readonlyProperty(
76140
76464
  AST10.tsPropertySignature(
76141
- AST10.identifier(fragmentKey),
76465
+ AST10.stringLiteral(fragmentKey2),
76142
76466
  AST10.tsTypeAnnotation(
76143
76467
  AST10.tsTypeLiteral(
76144
76468
  (fragmentSpreads || []).map(
76145
76469
  (fragmentSpread) => AST10.tsPropertySignature(
76146
76470
  AST10.identifier(fragmentSpread.name.value),
76147
- AST10.tsTypeAnnotation(
76148
- AST10.tsLiteralType(AST10.booleanLiteral(true))
76149
- )
76471
+ AST10.tsTypeAnnotation(AST10.tsTypeLiteral([]))
76150
76472
  )
76151
76473
  )
76152
76474
  )
@@ -76156,7 +76478,7 @@ function inlineType({
76156
76478
  )
76157
76479
  );
76158
76480
  }
76159
- const inlineFragmentSelections = Object.entries(inlineFragments).flatMap(([typeName, fragment]) => {
76481
+ const inlineFragmentSelections = Object.entries(inlineFragments).flatMap(([typeName, fragment2]) => {
76160
76482
  const fragmentRootType = config2.schema.getType(typeName);
76161
76483
  if (!fragmentRootType) {
76162
76484
  return [];
@@ -76165,7 +76487,7 @@ function inlineType({
76165
76487
  config: config2,
76166
76488
  filepath,
76167
76489
  rootType: fragmentRootType,
76168
- selections: fragment,
76490
+ selections: fragment2,
76169
76491
  allowReadonly,
76170
76492
  visitedTypes,
76171
76493
  root,
@@ -76237,10 +76559,10 @@ function inlineType({
76237
76559
  }
76238
76560
  return result;
76239
76561
  }
76240
- function selectionTypeInfo(schema, filepath, rootType, selection2) {
76241
- const selectionName = selection2.name.value;
76562
+ function selectionTypeInfo(schema, filepath, rootType, selection) {
76563
+ const selectionName = selection.name.value;
76242
76564
  let fields = {};
76243
- if (selection2.kind === "Field" && selection2.name.value === "__typename") {
76565
+ if (selection.kind === "Field" && selection.name.value === "__typename") {
76244
76566
  return {
76245
76567
  field: {
76246
76568
  name: "__typename",
@@ -76311,7 +76633,7 @@ async function generateDocumentTypes(config2, docs) {
76311
76633
  filepath: filename,
76312
76634
  selections: definition.selectionSet.selections,
76313
76635
  fragmentDefinitions,
76314
- applyFragments: definition.kind === "OperationDefinition"
76636
+ keepFragmentSpreadNodes: true
76315
76637
  });
76316
76638
  if (definition?.kind === "OperationDefinition") {
76317
76639
  await generateOperationTypeDefs(
@@ -76535,39 +76857,26 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
76535
76857
  if (!type) {
76536
76858
  throw new Error("Should not get here");
76537
76859
  }
76538
- let extraExports = [];
76539
76860
  let directive = definition.directives?.find(
76540
76861
  (directive2) => directive2.name.value === config2.argumentsDirective
76541
76862
  );
76542
- if (directive) {
76543
- extraExports.push(
76544
- AST11.exportNamedDeclaration(
76545
- AST11.tsTypeAliasDeclaration(
76546
- AST11.identifier(inputTypeName),
76547
- AST11.tsTypeLiteral(
76548
- (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
76549
- (definition2) => {
76550
- return AST11.tsPropertySignature(
76551
- AST11.identifier(definition2.variable.name.value),
76552
- AST11.tsTypeAnnotation(
76553
- tsTypeReference(
76554
- config2,
76555
- missingScalars,
76556
- definition2,
76557
- body
76558
- )
76559
- ),
76560
- definition2.type.kind !== "NonNullType"
76561
- );
76562
- }
76563
- )
76564
- )
76565
- )
76566
- )
76567
- );
76568
- }
76863
+ let inputValue = !directive ? AST11.tsTypeLiteral([]) : AST11.tsTypeLiteral(
76864
+ (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
76865
+ (definition2) => {
76866
+ return AST11.tsPropertySignature(
76867
+ AST11.identifier(definition2.variable.name.value),
76868
+ AST11.tsTypeAnnotation(
76869
+ tsTypeReference(config2, missingScalars, definition2, body)
76870
+ ),
76871
+ definition2.type.kind !== "NonNullType"
76872
+ );
76873
+ }
76874
+ )
76875
+ );
76569
76876
  body.push(
76570
- ...extraExports,
76877
+ AST11.exportNamedDeclaration(
76878
+ AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), inputValue)
76879
+ ),
76571
76880
  AST11.exportNamedDeclaration(
76572
76881
  AST11.tsTypeAliasDeclaration(
76573
76882
  AST11.identifier(propTypeName),
@@ -76583,14 +76892,12 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
76583
76892
  ),
76584
76893
  readonlyProperty(
76585
76894
  AST11.tsPropertySignature(
76586
- AST11.stringLiteral(fragmentKey),
76895
+ AST11.stringLiteral(fragmentKey2),
76587
76896
  AST11.tsTypeAnnotation(
76588
76897
  AST11.tsTypeLiteral([
76589
76898
  AST11.tsPropertySignature(
76590
76899
  AST11.stringLiteral(propTypeName),
76591
- AST11.tsTypeAnnotation(
76592
- AST11.tsLiteralType(AST11.booleanLiteral(true))
76593
- )
76900
+ AST11.tsTypeAnnotation(AST11.tsAnyKeyword())
76594
76901
  )
76595
76902
  ])
76596
76903
  )
@@ -77302,6 +77609,13 @@ async function addID(config2, documents) {
77302
77609
  return;
77303
77610
  }
77304
77611
  return addKeysToSelection(config2, node, fragmentType);
77612
+ },
77613
+ FragmentDefinition(node) {
77614
+ const fragmentType = config2.schema.getType(node.typeCondition.name.value);
77615
+ if (!fragmentType) {
77616
+ return;
77617
+ }
77618
+ return addKeysToSelection(config2, node, fragmentType);
77305
77619
  }
77306
77620
  });
77307
77621
  }
@@ -77320,7 +77634,7 @@ function addKeysToSelection(config2, node, fieldType) {
77320
77634
  const selections = [...node.selectionSet.selections];
77321
77635
  for (const keyField of keyFields) {
77322
77636
  if (node.selectionSet.selections.find(
77323
- (selection2) => selection2.kind === "Field" && !selection2.alias && selection2.name.value === keyField
77637
+ (selection) => selection.kind === "Field" && !selection.alias && selection.name.value === keyField
77324
77638
  )) {
77325
77639
  continue;
77326
77640
  }
@@ -78910,8 +79224,8 @@ async function updatePackageJSON(targetPath) {
78910
79224
  }
78911
79225
  packageJSON.devDependencies = {
78912
79226
  ...packageJSON.devDependencies,
78913
- houdini: "^1.0.10",
78914
- "houdini-svelte": "^1.0.10"
79227
+ houdini: "^1.1.0",
79228
+ "houdini-svelte": "^1.1.0"
78915
79229
  };
78916
79230
  await fs_exports.writeFile(packagePath, JSON.stringify(packageJSON, null, 4));
78917
79231
  }