houdini 1.0.11 → 1.1.1-next.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 +659 -330
  2. package/build/cmd-esm/index.js +659 -330
  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 +604 -326
  10. package/build/codegen-esm/index.js +604 -326
  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 +658 -329
  64. package/build/test-esm/index.js +658 -329
  65. package/build/vite-cjs/index.js +657 -328
  66. package/build/vite-esm/index.js +657 -328
  67. package/package.json +2 -2
@@ -3368,7 +3368,7 @@ var require_definition = __commonJS({
3368
3368
  exports.assertLeafType = assertLeafType;
3369
3369
  exports.isCompositeType = isCompositeType;
3370
3370
  exports.assertCompositeType = assertCompositeType;
3371
- exports.isAbstractType = isAbstractType3;
3371
+ exports.isAbstractType = isAbstractType4;
3372
3372
  exports.assertAbstractType = assertAbstractType;
3373
3373
  exports.GraphQLList = GraphQLList2;
3374
3374
  exports.GraphQLNonNull = GraphQLNonNull2;
@@ -3539,11 +3539,11 @@ var require_definition = __commonJS({
3539
3539
  }
3540
3540
  return type;
3541
3541
  }
3542
- function isAbstractType3(type) {
3542
+ function isAbstractType4(type) {
3543
3543
  return isInterfaceType6(type) || isUnionType7(type);
3544
3544
  }
3545
3545
  function assertAbstractType(type) {
3546
- if (!isAbstractType3(type)) {
3546
+ if (!isAbstractType4(type)) {
3547
3547
  throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL abstract type."));
3548
3548
  }
3549
3549
  return type;
@@ -6807,8 +6807,8 @@ var require_KnownFragmentNamesRule = __commonJS({
6807
6807
  return {
6808
6808
  FragmentSpread: function FragmentSpread(node) {
6809
6809
  var fragmentName = node.name.value;
6810
- var fragment = context.getFragment(fragmentName);
6811
- if (!fragment) {
6810
+ var fragment2 = context.getFragment(fragmentName);
6811
+ if (!fragment2) {
6812
6812
  context.reportError(new _GraphQLError.GraphQLError('Unknown fragment "'.concat(fragmentName, '".'), node.name));
6813
6813
  }
6814
6814
  }
@@ -6844,8 +6844,8 @@ var require_NoUnusedFragmentsRule = __commonJS({
6844
6844
  for (var _i2 = 0; _i2 < operationDefs.length; _i2++) {
6845
6845
  var operation = operationDefs[_i2];
6846
6846
  for (var _i4 = 0, _context$getRecursive2 = context.getRecursivelyReferencedFragments(operation); _i4 < _context$getRecursive2.length; _i4++) {
6847
- var fragment = _context$getRecursive2[_i4];
6848
- fragmentNameUsed[fragment.name.value] = true;
6847
+ var fragment2 = _context$getRecursive2[_i4];
6848
+ fragmentNameUsed[fragment2.name.value] = true;
6849
6849
  }
6850
6850
  }
6851
6851
  for (var _i6 = 0; _i6 < fragmentDefs.length; _i6++) {
@@ -6935,13 +6935,13 @@ var require_NoFragmentCyclesRule = __commonJS({
6935
6935
  return false;
6936
6936
  }
6937
6937
  };
6938
- function detectCycleRecursive(fragment) {
6939
- if (visitedFrags[fragment.name.value]) {
6938
+ function detectCycleRecursive(fragment2) {
6939
+ if (visitedFrags[fragment2.name.value]) {
6940
6940
  return;
6941
6941
  }
6942
- var fragmentName = fragment.name.value;
6942
+ var fragmentName = fragment2.name.value;
6943
6943
  visitedFrags[fragmentName] = true;
6944
- var spreadNodes = context.getFragmentSpreads(fragment.selectionSet);
6944
+ var spreadNodes = context.getFragmentSpreads(fragment2.selectionSet);
6945
6945
  if (spreadNodes.length === 0) {
6946
6946
  return;
6947
6947
  }
@@ -7762,11 +7762,11 @@ var require_OverlappingFieldsCanBeMergedRule = __commonJS({
7762
7762
  return conflicts;
7763
7763
  }
7764
7764
  function collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap, fragmentName) {
7765
- var fragment = context.getFragment(fragmentName);
7766
- if (!fragment) {
7765
+ var fragment2 = context.getFragment(fragmentName);
7766
+ if (!fragment2) {
7767
7767
  return;
7768
7768
  }
7769
- var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment), fieldMap2 = _getReferencedFieldsA[0], fragmentNames2 = _getReferencedFieldsA[1];
7769
+ var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2), fieldMap2 = _getReferencedFieldsA[0], fragmentNames2 = _getReferencedFieldsA[1];
7770
7770
  if (fieldMap === fieldMap2) {
7771
7771
  return;
7772
7772
  }
@@ -7937,38 +7937,38 @@ var require_OverlappingFieldsCanBeMergedRule = __commonJS({
7937
7937
  }
7938
7938
  return cached;
7939
7939
  }
7940
- function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment) {
7941
- var cached = cachedFieldsAndFragmentNames.get(fragment.selectionSet);
7940
+ function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2) {
7941
+ var cached = cachedFieldsAndFragmentNames.get(fragment2.selectionSet);
7942
7942
  if (cached) {
7943
7943
  return cached;
7944
7944
  }
7945
- var fragmentType = (0, _typeFromAST.typeFromAST)(context.getSchema(), fragment.typeCondition);
7946
- return getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragmentType, fragment.selectionSet);
7945
+ var fragmentType = (0, _typeFromAST.typeFromAST)(context.getSchema(), fragment2.typeCondition);
7946
+ return getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragmentType, fragment2.selectionSet);
7947
7947
  }
7948
7948
  function _collectFieldsAndFragmentNames(context, parentType, selectionSet, nodeAndDefs, fragmentNames) {
7949
7949
  for (var _i9 = 0, _selectionSet$selecti2 = selectionSet.selections; _i9 < _selectionSet$selecti2.length; _i9++) {
7950
- var selection2 = _selectionSet$selecti2[_i9];
7951
- switch (selection2.kind) {
7950
+ var selection = _selectionSet$selecti2[_i9];
7951
+ switch (selection.kind) {
7952
7952
  case _kinds.Kind.FIELD: {
7953
- var fieldName = selection2.name.value;
7953
+ var fieldName = selection.name.value;
7954
7954
  var fieldDef = void 0;
7955
7955
  if ((0, _definition.isObjectType)(parentType) || (0, _definition.isInterfaceType)(parentType)) {
7956
7956
  fieldDef = parentType.getFields()[fieldName];
7957
7957
  }
7958
- var responseName = selection2.alias ? selection2.alias.value : fieldName;
7958
+ var responseName = selection.alias ? selection.alias.value : fieldName;
7959
7959
  if (!nodeAndDefs[responseName]) {
7960
7960
  nodeAndDefs[responseName] = [];
7961
7961
  }
7962
- nodeAndDefs[responseName].push([parentType, selection2, fieldDef]);
7962
+ nodeAndDefs[responseName].push([parentType, selection, fieldDef]);
7963
7963
  break;
7964
7964
  }
7965
7965
  case _kinds.Kind.FRAGMENT_SPREAD:
7966
- fragmentNames[selection2.name.value] = true;
7966
+ fragmentNames[selection.name.value] = true;
7967
7967
  break;
7968
7968
  case _kinds.Kind.INLINE_FRAGMENT: {
7969
- var typeCondition = selection2.typeCondition;
7969
+ var typeCondition = selection.typeCondition;
7970
7970
  var inlineFragmentType = typeCondition ? (0, _typeFromAST.typeFromAST)(context.getSchema(), typeCondition) : parentType;
7971
- _collectFieldsAndFragmentNames(context, inlineFragmentType, selection2.selectionSet, nodeAndDefs, fragmentNames);
7971
+ _collectFieldsAndFragmentNames(context, inlineFragmentType, selection.selectionSet, nodeAndDefs, fragmentNames);
7972
7972
  break;
7973
7973
  }
7974
7974
  }
@@ -8504,11 +8504,11 @@ var require_ValidationContext = __commonJS({
8504
8504
  while (setsToVisit.length !== 0) {
8505
8505
  var set = setsToVisit.pop();
8506
8506
  for (var _i2 = 0, _set$selections2 = set.selections; _i2 < _set$selections2.length; _i2++) {
8507
- var selection2 = _set$selections2[_i2];
8508
- if (selection2.kind === _kinds.Kind.FRAGMENT_SPREAD) {
8509
- spreads.push(selection2);
8510
- } else if (selection2.selectionSet) {
8511
- setsToVisit.push(selection2.selectionSet);
8507
+ var selection = _set$selections2[_i2];
8508
+ if (selection.kind === _kinds.Kind.FRAGMENT_SPREAD) {
8509
+ spreads.push(selection);
8510
+ } else if (selection.selectionSet) {
8511
+ setsToVisit.push(selection.selectionSet);
8512
8512
  }
8513
8513
  }
8514
8514
  }
@@ -8529,10 +8529,10 @@ var require_ValidationContext = __commonJS({
8529
8529
  var fragName = spread.name.value;
8530
8530
  if (collectedNames[fragName] !== true) {
8531
8531
  collectedNames[fragName] = true;
8532
- var fragment = this.getFragment(fragName);
8533
- if (fragment) {
8534
- fragments.push(fragment);
8535
- nodesToVisit.push(fragment.selectionSet);
8532
+ var fragment2 = this.getFragment(fragName);
8533
+ if (fragment2) {
8534
+ fragments.push(fragment2);
8535
+ nodesToVisit.push(fragment2.selectionSet);
8536
8536
  }
8537
8537
  }
8538
8538
  }
@@ -9445,37 +9445,37 @@ var require_execute = __commonJS({
9445
9445
  }
9446
9446
  function collectFields(exeContext, runtimeType, selectionSet, fields, visitedFragmentNames) {
9447
9447
  for (var _i6 = 0, _selectionSet$selecti2 = selectionSet.selections; _i6 < _selectionSet$selecti2.length; _i6++) {
9448
- var selection2 = _selectionSet$selecti2[_i6];
9449
- switch (selection2.kind) {
9448
+ var selection = _selectionSet$selecti2[_i6];
9449
+ switch (selection.kind) {
9450
9450
  case _kinds.Kind.FIELD: {
9451
- if (!shouldIncludeNode(exeContext, selection2)) {
9451
+ if (!shouldIncludeNode(exeContext, selection)) {
9452
9452
  continue;
9453
9453
  }
9454
- var name = getFieldEntryKey(selection2);
9454
+ var name = getFieldEntryKey(selection);
9455
9455
  if (!fields[name]) {
9456
9456
  fields[name] = [];
9457
9457
  }
9458
- fields[name].push(selection2);
9458
+ fields[name].push(selection);
9459
9459
  break;
9460
9460
  }
9461
9461
  case _kinds.Kind.INLINE_FRAGMENT: {
9462
- if (!shouldIncludeNode(exeContext, selection2) || !doesFragmentConditionMatch(exeContext, selection2, runtimeType)) {
9462
+ if (!shouldIncludeNode(exeContext, selection) || !doesFragmentConditionMatch(exeContext, selection, runtimeType)) {
9463
9463
  continue;
9464
9464
  }
9465
- collectFields(exeContext, runtimeType, selection2.selectionSet, fields, visitedFragmentNames);
9465
+ collectFields(exeContext, runtimeType, selection.selectionSet, fields, visitedFragmentNames);
9466
9466
  break;
9467
9467
  }
9468
9468
  case _kinds.Kind.FRAGMENT_SPREAD: {
9469
- var fragName = selection2.name.value;
9470
- if (visitedFragmentNames[fragName] || !shouldIncludeNode(exeContext, selection2)) {
9469
+ var fragName = selection.name.value;
9470
+ if (visitedFragmentNames[fragName] || !shouldIncludeNode(exeContext, selection)) {
9471
9471
  continue;
9472
9472
  }
9473
9473
  visitedFragmentNames[fragName] = true;
9474
- var fragment = exeContext.fragments[fragName];
9475
- if (!fragment || !doesFragmentConditionMatch(exeContext, fragment, runtimeType)) {
9474
+ var fragment2 = exeContext.fragments[fragName];
9475
+ if (!fragment2 || !doesFragmentConditionMatch(exeContext, fragment2, runtimeType)) {
9476
9476
  continue;
9477
9477
  }
9478
- collectFields(exeContext, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
9478
+ collectFields(exeContext, runtimeType, fragment2.selectionSet, fields, visitedFragmentNames);
9479
9479
  break;
9480
9480
  }
9481
9481
  }
@@ -9493,8 +9493,8 @@ var require_execute = __commonJS({
9493
9493
  }
9494
9494
  return true;
9495
9495
  }
9496
- function doesFragmentConditionMatch(exeContext, fragment, type) {
9497
- var typeConditionNode = fragment.typeCondition;
9496
+ function doesFragmentConditionMatch(exeContext, fragment2, type) {
9497
+ var typeConditionNode = fragment2.typeCondition;
9498
9498
  if (!typeConditionNode) {
9499
9499
  return true;
9500
9500
  }
@@ -54208,14 +54208,14 @@ function deepEquals(objA, objB, map = /* @__PURE__ */ new WeakMap()) {
54208
54208
  }
54209
54209
 
54210
54210
  // src/runtime/lib/selection.ts
54211
- function getFieldsForType(selection2, __typename) {
54212
- let targetSelection = selection2.fields || {};
54213
- if (selection2.abstractFields && __typename) {
54214
- const mappedType = selection2.abstractFields.typeMap[__typename];
54211
+ function getFieldsForType(selection, __typename) {
54212
+ let targetSelection = selection.fields || {};
54213
+ if (selection.abstractFields && __typename) {
54214
+ const mappedType = selection.abstractFields.typeMap[__typename];
54215
54215
  if (mappedType) {
54216
- targetSelection = selection2.abstractFields.fields[mappedType];
54217
- } else if (selection2.abstractFields.fields[__typename]) {
54218
- targetSelection = selection2.abstractFields.fields[__typename];
54216
+ targetSelection = selection.abstractFields.fields[mappedType];
54217
+ } else if (selection.abstractFields.fields[__typename]) {
54218
+ targetSelection = selection.abstractFields.fields[__typename];
54219
54219
  }
54220
54220
  }
54221
54221
  return targetSelection;
@@ -54223,7 +54223,7 @@ function getFieldsForType(selection2, __typename) {
54223
54223
 
54224
54224
  // src/runtime/lib/scalars.ts
54225
54225
  async function marshalSelection({
54226
- selection: selection2,
54226
+ selection,
54227
54227
  data
54228
54228
  }) {
54229
54229
  const config2 = getCurrentConfig();
@@ -54231,18 +54231,18 @@ async function marshalSelection({
54231
54231
  return data;
54232
54232
  }
54233
54233
  if (Array.isArray(data)) {
54234
- return await Promise.all(data.map((val) => marshalSelection({ selection: selection2, data: val })));
54234
+ return await Promise.all(data.map((val) => marshalSelection({ selection, data: val })));
54235
54235
  }
54236
- const targetSelection = getFieldsForType(selection2, data["__typename"]);
54236
+ const targetSelection = getFieldsForType(selection, data["__typename"]);
54237
54237
  return Object.fromEntries(
54238
54238
  await Promise.all(
54239
54239
  Object.entries(data).map(async ([fieldName, value]) => {
54240
- const { type, selection: selection3 } = targetSelection[fieldName];
54240
+ const { type, selection: selection2 } = targetSelection[fieldName];
54241
54241
  if (!type) {
54242
54242
  return [fieldName, value];
54243
54243
  }
54244
- if (selection3) {
54245
- return [fieldName, await marshalSelection({ selection: selection3, data: value })];
54244
+ if (selection2) {
54245
+ return [fieldName, await marshalSelection({ selection: selection2, data: value })];
54246
54246
  }
54247
54247
  if (config2.scalars?.[type]) {
54248
54248
  const marshalFn = config2.scalars[type].marshal;
@@ -54293,6 +54293,7 @@ var DataSource = {
54293
54293
  Network: "network",
54294
54294
  Ssr: "ssr"
54295
54295
  };
54296
+ var fragmentKey = " $fragments";
54296
54297
 
54297
54298
  // src/runtime/lib/key.ts
54298
54299
  var computeKey = ({ field, args }) => {
@@ -54779,7 +54780,7 @@ var List = class {
54779
54780
  recordType,
54780
54781
  key,
54781
54782
  listType,
54782
- selection: selection2,
54783
+ selection,
54783
54784
  when,
54784
54785
  filters,
54785
54786
  connection,
@@ -54791,7 +54792,7 @@ var List = class {
54791
54792
  this.key = key;
54792
54793
  this.type = listType;
54793
54794
  this.cache = manager.cache;
54794
- this.selection = selection2;
54795
+ this.selection = selection;
54795
54796
  this._when = when;
54796
54797
  this.filters = filters;
54797
54798
  this.name = name;
@@ -54802,19 +54803,19 @@ var List = class {
54802
54803
  when(when) {
54803
54804
  return this.manager.lists.get(this.name).get(this.recordID).when(when);
54804
54805
  }
54805
- append(selection2, data, variables = {}) {
54806
- return this.addToList(selection2, data, variables, "last");
54806
+ append(selection, data, variables = {}) {
54807
+ return this.addToList(selection, data, variables, "last");
54807
54808
  }
54808
- prepend(selection2, data, variables = {}) {
54809
- return this.addToList(selection2, data, variables, "first");
54809
+ prepend(selection, data, variables = {}) {
54810
+ return this.addToList(selection, data, variables, "first");
54810
54811
  }
54811
- addToList(selection2, data, variables = {}, where) {
54812
+ addToList(selection, data, variables = {}, where) {
54812
54813
  const listType = this.listType(data);
54813
54814
  const dataID = this.cache._internal_unstable.id(listType, data);
54814
54815
  if (!this.validateWhen() || !dataID) {
54815
54816
  return;
54816
54817
  }
54817
- let insertSelection = selection2;
54818
+ let insertSelection = selection;
54818
54819
  let insertData = data;
54819
54820
  if (this.connection) {
54820
54821
  insertSelection = {
@@ -54834,9 +54835,9 @@ var List = class {
54834
54835
  type: listType,
54835
54836
  keyRaw: "node",
54836
54837
  selection: {
54837
- ...selection2,
54838
+ ...selection,
54838
54839
  fields: {
54839
- ...selection2.fields,
54840
+ ...selection.fields,
54840
54841
  __typename: {
54841
54842
  keyRaw: "__typename",
54842
54843
  type: "String"
@@ -54865,9 +54866,9 @@ var List = class {
54865
54866
  type: listType,
54866
54867
  updates: ["append", "prepend"],
54867
54868
  selection: {
54868
- ...selection2,
54869
+ ...selection,
54869
54870
  fields: {
54870
- ...selection2.fields,
54871
+ ...selection.fields,
54871
54872
  __typename: {
54872
54873
  keyRaw: "__typename",
54873
54874
  type: "String"
@@ -54942,7 +54943,8 @@ var List = class {
54942
54943
  this.cache._internal_unstable.getSelection({
54943
54944
  parent: spec.parentID || this.manager.rootID,
54944
54945
  selection: spec.selection,
54945
- variables: spec.variables?.() || {}
54946
+ variables: spec.variables?.() || {},
54947
+ ignoreMasking: false
54946
54948
  }).data
54947
54949
  );
54948
54950
  }
@@ -54978,9 +54980,9 @@ var List = class {
54978
54980
  }
54979
54981
  return ok;
54980
54982
  }
54981
- toggleElement(selection2, data, variables = {}, where) {
54983
+ toggleElement(selection, data, variables = {}, where) {
54982
54984
  if (!this.remove(data, variables)) {
54983
- this.addToList(selection2, data, variables, where);
54985
+ this.addToList(selection, data, variables, where);
54984
54986
  }
54985
54987
  }
54986
54988
  *[Symbol.iterator]() {
@@ -55555,14 +55557,24 @@ var InMemorySubscriptions = class {
55555
55557
  add({
55556
55558
  parent,
55557
55559
  spec,
55558
- selection: selection2,
55560
+ selection,
55559
55561
  variables,
55560
55562
  parentType
55561
55563
  }) {
55562
55564
  const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
55563
- let targetSelection = getFieldsForType(selection2, __typename);
55565
+ let targetSelection = getFieldsForType(selection, __typename);
55564
55566
  for (const fieldSelection of Object.values(targetSelection || {})) {
55565
- const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
55567
+ const {
55568
+ keyRaw,
55569
+ selection: innerSelection,
55570
+ type,
55571
+ list,
55572
+ filters,
55573
+ visible
55574
+ } = fieldSelection;
55575
+ if (!visible) {
55576
+ continue;
55577
+ }
55566
55578
  const key = evaluateKey(keyRaw, variables);
55567
55579
  let targetSelection2;
55568
55580
  if (innerSelection) {
@@ -55610,10 +55622,10 @@ var InMemorySubscriptions = class {
55610
55622
  addFieldSubscription({
55611
55623
  id,
55612
55624
  key,
55613
- selection: selection2,
55625
+ selection,
55614
55626
  type
55615
55627
  }) {
55616
- const spec = selection2[0];
55628
+ const spec = selection[0];
55617
55629
  if (!this.subscribers[id]) {
55618
55630
  this.subscribers[id] = {};
55619
55631
  }
@@ -55625,7 +55637,7 @@ var InMemorySubscriptions = class {
55625
55637
  }
55626
55638
  this.keyVersions[key].add(key);
55627
55639
  if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
55628
- this.subscribers[id][key].push([spec, selection2[1]]);
55640
+ this.subscribers[id][key].push([spec, selection[1]]);
55629
55641
  }
55630
55642
  if (!this.referenceCounts[id]) {
55631
55643
  this.referenceCounts[id] = {};
@@ -55636,14 +55648,13 @@ var InMemorySubscriptions = class {
55636
55648
  const counts = this.referenceCounts[id][key];
55637
55649
  counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
55638
55650
  this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
55639
- const { selection: innerSelection } = selection2[1]?.[key] ?? {};
55640
55651
  }
55641
55652
  registerList({
55642
55653
  list,
55643
55654
  id,
55644
55655
  key,
55645
55656
  parentType,
55646
- selection: selection2,
55657
+ selection,
55647
55658
  filters,
55648
55659
  variables
55649
55660
  }) {
@@ -55654,7 +55665,7 @@ var InMemorySubscriptions = class {
55654
55665
  recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
55655
55666
  listType: list.type,
55656
55667
  key,
55657
- selection: selection2,
55668
+ selection,
55658
55669
  filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
55659
55670
  return {
55660
55671
  ...acc,
@@ -55670,14 +55681,14 @@ var InMemorySubscriptions = class {
55670
55681
  parentType
55671
55682
  }) {
55672
55683
  for (const [spec, targetSelection] of subscribers) {
55673
- for (const selection2 of Object.values(targetSelection ?? {})) {
55684
+ for (const selection of Object.values(targetSelection ?? {})) {
55674
55685
  const {
55675
55686
  type: linkedType,
55676
55687
  keyRaw,
55677
55688
  selection: innerSelection,
55678
55689
  list,
55679
55690
  filters
55680
- } = selection2;
55691
+ } = selection;
55681
55692
  const key = evaluateKey(keyRaw, variables);
55682
55693
  const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
55683
55694
  this.addFieldSubscription({
@@ -55697,7 +55708,7 @@ var InMemorySubscriptions = class {
55697
55708
  parentType: parentType || spec.rootType
55698
55709
  });
55699
55710
  }
55700
- const childSelection = selection2.selection;
55711
+ const childSelection = selection.selection;
55701
55712
  if (childSelection) {
55702
55713
  const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
55703
55714
  const children = !Array.isArray(link) ? [link] : flatten(link);
@@ -55724,11 +55735,11 @@ var InMemorySubscriptions = class {
55724
55735
  get(id, field) {
55725
55736
  return this.subscribers[id]?.[field] || [];
55726
55737
  }
55727
- remove(id, selection2, targets, variables, visited = []) {
55738
+ remove(id, selection, targets, variables, visited = []) {
55728
55739
  visited.push(id);
55729
55740
  const linkedIDs = [];
55730
55741
  const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
55731
- let targetSelection = getFieldsForType(selection2, __typename);
55742
+ let targetSelection = getFieldsForType(selection, __typename);
55732
55743
  for (const fieldSelection of Object.values(targetSelection || {})) {
55733
55744
  const key = evaluateKey(fieldSelection.keyRaw, variables);
55734
55745
  this.removeSubscribers(id, key, targets);
@@ -55790,7 +55801,7 @@ var InMemorySubscriptions = class {
55790
55801
  // src/runtime/cache/cache.ts
55791
55802
  var Cache = class {
55792
55803
  _internal_unstable;
55793
- constructor(config2) {
55804
+ constructor({ disabled, ...config2 } = {}) {
55794
55805
  this._internal_unstable = new CacheInternal({
55795
55806
  cache: this,
55796
55807
  storage: new InMemoryStorage(),
@@ -55798,9 +55809,10 @@ var Cache = class {
55798
55809
  lists: new ListManager(this, rootID),
55799
55810
  lifetimes: new GarbageCollector(this),
55800
55811
  staleManager: new StaleManager(this),
55801
- schema: new SchemaManager(this)
55812
+ schema: new SchemaManager(this),
55813
+ disabled: disabled ?? typeof globalThis.window === "undefined"
55802
55814
  });
55803
- if (config2) {
55815
+ if (Object.keys(config2).length > 0) {
55804
55816
  this.setConfig(defaultConfigValues(config2));
55805
55817
  }
55806
55818
  }
@@ -55819,7 +55831,8 @@ var Cache = class {
55819
55831
  this._internal_unstable.getSelection({
55820
55832
  parent: spec.parentID || rootID,
55821
55833
  selection: spec.selection,
55822
- variables: spec.variables?.() || {}
55834
+ variables: spec.variables?.() || {},
55835
+ ignoreMasking: false
55823
55836
  }).data
55824
55837
  );
55825
55838
  }
@@ -55894,16 +55907,13 @@ var Cache = class {
55894
55907
  getFieldTime(id, field) {
55895
55908
  return this._internal_unstable.staleManager.getFieldTime(id, field);
55896
55909
  }
55910
+ config() {
55911
+ return this._internal_unstable.config;
55912
+ }
55897
55913
  };
55898
55914
  var CacheInternal = class {
55899
55915
  _disabled = false;
55900
- config = defaultConfigValues({
55901
- plugins: {
55902
- "houdini-svelte": {
55903
- client: ""
55904
- }
55905
- }
55906
- });
55916
+ _config;
55907
55917
  storage;
55908
55918
  subscriptions;
55909
55919
  lists;
@@ -55918,7 +55928,9 @@ var CacheInternal = class {
55918
55928
  cache,
55919
55929
  lifetimes,
55920
55930
  staleManager,
55921
- schema
55931
+ schema,
55932
+ disabled,
55933
+ config: config2
55922
55934
  }) {
55923
55935
  this.storage = storage;
55924
55936
  this.subscriptions = subscriptions;
@@ -55927,7 +55939,8 @@ var CacheInternal = class {
55927
55939
  this.lifetimes = lifetimes;
55928
55940
  this.staleManager = staleManager;
55929
55941
  this.schema = schema;
55930
- this._disabled = typeof globalThis.window === "undefined";
55942
+ this._config = config2;
55943
+ this._disabled = disabled;
55931
55944
  try {
55932
55945
  if (process.env.HOUDINI_TEST === "true") {
55933
55946
  this._disabled = false;
@@ -55935,12 +55948,15 @@ var CacheInternal = class {
55935
55948
  } catch {
55936
55949
  }
55937
55950
  }
55951
+ get config() {
55952
+ return this._config ?? getCurrentConfig();
55953
+ }
55938
55954
  setConfig(config2) {
55939
- this.config = config2;
55955
+ this._config = config2;
55940
55956
  }
55941
55957
  writeSelection({
55942
55958
  data,
55943
- selection: selection2,
55959
+ selection,
55944
55960
  variables = {},
55945
55961
  parent = rootID,
55946
55962
  applyUpdates,
@@ -55952,9 +55968,9 @@ var CacheInternal = class {
55952
55968
  if (this._disabled) {
55953
55969
  return [];
55954
55970
  }
55955
- let targetSelection = getFieldsForType(selection2, data["__typename"]);
55971
+ let targetSelection = getFieldsForType(selection, data["__typename"]);
55956
55972
  for (const [field, value] of Object.entries(data)) {
55957
- if (!selection2 || !targetSelection[field]) {
55973
+ if (!selection || !targetSelection[field]) {
55958
55974
  continue;
55959
55975
  }
55960
55976
  let {
@@ -56210,25 +56226,40 @@ var CacheInternal = class {
56210
56226
  return toNotify;
56211
56227
  }
56212
56228
  getSelection({
56213
- selection: selection2,
56229
+ selection,
56214
56230
  parent = rootID,
56215
56231
  variables,
56216
- stepsFromConnection = null
56232
+ stepsFromConnection = null,
56233
+ ignoreMasking
56217
56234
  }) {
56218
56235
  if (parent === null) {
56219
56236
  return { data: null, partial: false, stale: false, hasData: true };
56220
56237
  }
56221
56238
  const target = {};
56239
+ if (selection.fragments) {
56240
+ target[fragmentKey] = Object.fromEntries(
56241
+ Object.entries(selection.fragments).map(([key, value]) => [
56242
+ key,
56243
+ {
56244
+ parent,
56245
+ variables: evaluateFragmentVariables(value, variables ?? {})
56246
+ }
56247
+ ])
56248
+ );
56249
+ }
56222
56250
  let hasData = false;
56223
56251
  let partial = false;
56224
56252
  let cascadeNull = false;
56225
56253
  let stale = false;
56226
56254
  const typename = this.storage.get(parent, "__typename").value;
56227
- let targetSelection = getFieldsForType(selection2, typename);
56255
+ let targetSelection = getFieldsForType(selection, typename);
56228
56256
  for (const [
56229
56257
  attributeName,
56230
- { type, keyRaw, selection: fieldSelection, nullable, list }
56258
+ { type, keyRaw, selection: fieldSelection, nullable, list, visible }
56231
56259
  ] of Object.entries(targetSelection)) {
56260
+ if (!visible && !ignoreMasking) {
56261
+ continue;
56262
+ }
56232
56263
  const key = evaluateKey(keyRaw, variables);
56233
56264
  const { value } = this.storage.get(parent, key);
56234
56265
  const dt_field = this.staleManager.getFieldTime(parent, key);
@@ -56268,7 +56299,8 @@ var CacheInternal = class {
56268
56299
  fields: fieldSelection,
56269
56300
  variables,
56270
56301
  linkedList: value,
56271
- stepsFromConnection: nextStep
56302
+ stepsFromConnection: nextStep,
56303
+ ignoreMasking: !!ignoreMasking
56272
56304
  });
56273
56305
  target[attributeName] = listValue.data;
56274
56306
  if (listValue.partial) {
@@ -56285,7 +56317,8 @@ var CacheInternal = class {
56285
56317
  parent: value,
56286
56318
  selection: fieldSelection,
56287
56319
  variables,
56288
- stepsFromConnection: nextStep
56320
+ stepsFromConnection: nextStep,
56321
+ ignoreMasking
56289
56322
  });
56290
56323
  target[attributeName] = objectFields.data;
56291
56324
  if (objectFields.partial) {
@@ -56329,7 +56362,8 @@ var CacheInternal = class {
56329
56362
  fields,
56330
56363
  variables,
56331
56364
  linkedList,
56332
- stepsFromConnection
56365
+ stepsFromConnection,
56366
+ ignoreMasking
56333
56367
  }) {
56334
56368
  const result = [];
56335
56369
  let partialData = false;
@@ -56341,7 +56375,8 @@ var CacheInternal = class {
56341
56375
  fields,
56342
56376
  variables,
56343
56377
  linkedList: entry,
56344
- stepsFromConnection
56378
+ stepsFromConnection,
56379
+ ignoreMasking
56345
56380
  });
56346
56381
  result.push(nestedValue.data);
56347
56382
  if (nestedValue.partial) {
@@ -56362,7 +56397,8 @@ var CacheInternal = class {
56362
56397
  parent: entry,
56363
56398
  selection: fields,
56364
56399
  variables,
56365
- stepsFromConnection
56400
+ stepsFromConnection,
56401
+ ignoreMasking
56366
56402
  });
56367
56403
  result.push(data);
56368
56404
  if (partial) {
@@ -56465,11 +56501,54 @@ var CacheInternal = class {
56465
56501
  }
56466
56502
  }
56467
56503
  };
56504
+ function evaluateFragmentVariables(variables, args) {
56505
+ return Object.fromEntries(
56506
+ Object.entries(variables).map(([key, value]) => [key, fragmentVariableValue(value, args)])
56507
+ );
56508
+ }
56509
+ function fragmentVariableValue(value, args) {
56510
+ if (value.kind === "StringValue") {
56511
+ return value.value;
56512
+ }
56513
+ if (value.kind === "BooleanValue") {
56514
+ return value.value;
56515
+ }
56516
+ if (value.kind === "EnumValue") {
56517
+ return value.value;
56518
+ }
56519
+ if (value.kind === "FloatValue") {
56520
+ return parseFloat(value.value);
56521
+ }
56522
+ if (value.kind === "IntValue") {
56523
+ return parseInt(value.value, 10);
56524
+ }
56525
+ if (value.kind === "NullValue") {
56526
+ return null;
56527
+ }
56528
+ if (value.kind === "Variable") {
56529
+ return args[value.name.value];
56530
+ }
56531
+ if (value.kind === "ListValue") {
56532
+ return value.values.map((value2) => fragmentVariableValue(value2, args));
56533
+ }
56534
+ if (value.kind === "ObjectValue") {
56535
+ return value.fields.reduce(
56536
+ (obj, field) => ({
56537
+ ...obj,
56538
+ [field.name.value]: fragmentVariableValue(field.value, args)
56539
+ }),
56540
+ {}
56541
+ );
56542
+ }
56543
+ }
56468
56544
  var rootID = "_ROOT_";
56469
56545
 
56470
56546
  // src/runtime/cache/index.ts
56471
56547
  var cache_default = new Cache();
56472
56548
 
56549
+ // src/runtime/client/plugins/cache.ts
56550
+ var serverSide = typeof globalThis.window === "undefined";
56551
+
56473
56552
  // src/runtime/client/utils/documentPlugins.ts
56474
56553
  var documentPlugin = (kind, source) => {
56475
56554
  return () => {
@@ -56505,7 +56584,6 @@ var documentPlugin = (kind, source) => {
56505
56584
  var query = documentPlugin(ArtifactKind.Query, function() {
56506
56585
  let subscriptionSpec = null;
56507
56586
  let lastVariables = null;
56508
- let artifactName = "";
56509
56587
  return {
56510
56588
  start(ctx, { next }) {
56511
56589
  ctx.variables = {
@@ -56515,8 +56593,7 @@ var query = documentPlugin(ArtifactKind.Query, function() {
56515
56593
  next(ctx);
56516
56594
  },
56517
56595
  end(ctx, { resolve: resolve2, marshalVariables, variablesChanged }) {
56518
- if (variablesChanged(ctx)) {
56519
- artifactName = ctx.artifact.name;
56596
+ if (variablesChanged(ctx) && !ctx.cacheParams?.disableSubscriptions) {
56520
56597
  if (subscriptionSpec) {
56521
56598
  cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
56522
56599
  }
@@ -56537,19 +56614,61 @@ var query = documentPlugin(ArtifactKind.Query, function() {
56537
56614
  });
56538
56615
  }
56539
56616
  };
56540
- cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
56617
+ cache_default.subscribe(subscriptionSpec, lastVariables);
56541
56618
  }
56542
56619
  resolve2(ctx);
56543
56620
  },
56544
56621
  cleanup() {
56545
56622
  if (subscriptionSpec) {
56546
- cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
56623
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.());
56547
56624
  lastVariables = null;
56548
56625
  }
56549
56626
  }
56550
56627
  };
56551
56628
  });
56552
56629
 
56630
+ // src/runtime/client/plugins/fragment.ts
56631
+ var fragment = documentPlugin(ArtifactKind.Fragment, function() {
56632
+ let subscriptionSpec = null;
56633
+ return {
56634
+ start(ctx, { next, resolve: resolve2, variablesChanged, marshalVariables }) {
56635
+ if (!ctx.stuff.parentID) {
56636
+ return next(ctx);
56637
+ }
56638
+ if (variablesChanged(ctx) && !ctx.cacheParams?.disableSubscriptions) {
56639
+ if (subscriptionSpec) {
56640
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
56641
+ }
56642
+ const variables = marshalVariables(ctx);
56643
+ subscriptionSpec = {
56644
+ rootType: ctx.artifact.rootType,
56645
+ selection: ctx.artifact.selection,
56646
+ variables: () => variables,
56647
+ parentID: ctx.stuff.parentID,
56648
+ set: (newValue) => {
56649
+ resolve2(ctx, {
56650
+ data: newValue,
56651
+ errors: null,
56652
+ fetching: false,
56653
+ partial: false,
56654
+ stale: false,
56655
+ source: DataSource.Cache,
56656
+ variables
56657
+ });
56658
+ }
56659
+ };
56660
+ cache_default.subscribe(subscriptionSpec, variables);
56661
+ }
56662
+ next(ctx);
56663
+ },
56664
+ cleanup() {
56665
+ if (subscriptionSpec) {
56666
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.());
56667
+ }
56668
+ }
56669
+ };
56670
+ });
56671
+
56553
56672
  // src/runtime/client/plugins/mutation.ts
56554
56673
  var mutation = documentPlugin(ArtifactKind.Mutation, () => {
56555
56674
  return {
@@ -56825,11 +56944,17 @@ function deepMerge(filepath, ...targets) {
56825
56944
  if (targets.length === 1) {
56826
56945
  return targets[0];
56827
56946
  } else if (targets.length === 2) {
56828
- return (0, import_deepmerge.default)(targets[0], targets[1]);
56947
+ return (0, import_deepmerge.default)(targets[0], targets[1], {
56948
+ arrayMerge: (source, update) => [...new Set(source.concat(update))]
56949
+ });
56829
56950
  }
56830
56951
  return deepMerge(filepath, targets[0], deepMerge(filepath, ...targets.slice(1)));
56831
56952
  } catch (e) {
56832
- throw new HoudiniError({ filepath, message: "could not merge: " + targets });
56953
+ throw new HoudiniError({
56954
+ filepath,
56955
+ message: "could not merge: " + targets,
56956
+ description: e.message
56957
+ });
56833
56958
  }
56834
56959
  }
56835
56960
 
@@ -57057,16 +57182,16 @@ function flattenSelections({
57057
57182
  filepath,
57058
57183
  selections,
57059
57184
  fragmentDefinitions,
57060
- applyFragments,
57061
- ignoreMaskDisable
57185
+ ignoreMaskDisable,
57186
+ keepFragmentSpreadNodes
57062
57187
  }) {
57063
57188
  const fields = new FieldCollection({
57064
57189
  config: config2,
57065
57190
  filepath,
57066
57191
  selections,
57067
57192
  fragmentDefinitions,
57068
- applyFragments,
57069
- ignoreMaskDisable: !!ignoreMaskDisable
57193
+ ignoreMaskDisable: !!ignoreMaskDisable,
57194
+ keepFragmentSpreadNodes: !!keepFragmentSpreadNodes
57070
57195
  });
57071
57196
  return fields.toSelectionSet();
57072
57197
  }
@@ -57077,57 +57202,60 @@ var FieldCollection = class {
57077
57202
  fields;
57078
57203
  inlineFragments;
57079
57204
  fragmentSpreads;
57080
- applyFragments;
57081
57205
  ignoreMaskDisable;
57206
+ keepFragmentSpreadNodes;
57082
57207
  constructor(args) {
57083
57208
  this.config = args.config;
57084
57209
  this.fragmentDefinitions = args.fragmentDefinitions;
57085
- this.applyFragments = args.applyFragments;
57086
57210
  this.ignoreMaskDisable = args.ignoreMaskDisable;
57211
+ this.keepFragmentSpreadNodes = args.keepFragmentSpreadNodes;
57087
57212
  this.fields = {};
57088
57213
  this.inlineFragments = {};
57089
57214
  this.fragmentSpreads = {};
57090
57215
  this.filepath = args.filepath;
57091
- for (const selection2 of args.selections) {
57092
- this.add(selection2);
57216
+ for (const selection of args.selections) {
57217
+ this.add(selection);
57093
57218
  }
57094
57219
  }
57095
57220
  get size() {
57096
57221
  return Object.keys(this.fields).length + Object.keys(this.inlineFragments).length + Object.keys(this.fragmentSpreads).length;
57097
57222
  }
57098
- add(selection2) {
57099
- if (selection2.kind === "Field") {
57100
- const key = selection2.alias?.value || selection2.name.value;
57223
+ add(selection) {
57224
+ if (selection.kind === "Field") {
57225
+ const key = selection.alias?.value || selection.name.value;
57101
57226
  if (!this.fields[key]) {
57102
57227
  this.fields[key] = {
57103
- astNode: selection2,
57228
+ astNode: selection,
57104
57229
  selection: this.empty()
57105
57230
  };
57106
57231
  }
57107
- for (const subselect of selection2.selectionSet?.selections || []) {
57232
+ for (const subselect of selection.selectionSet?.selections || []) {
57108
57233
  this.fields[key].selection.add(subselect);
57109
57234
  }
57235
+ this.fields[key].selection.fragmentSpreads = {
57236
+ ...this.collectFragmentSpreads(selection.selectionSet?.selections ?? []),
57237
+ ...this.fields[key].selection.fragmentSpreads
57238
+ };
57110
57239
  return;
57111
57240
  }
57112
- if (selection2.kind === "InlineFragment" && !selection2.typeCondition) {
57113
- for (const subselect of selection2.selectionSet.selections) {
57241
+ if (selection.kind === "InlineFragment" && !selection.typeCondition) {
57242
+ for (const subselect of selection.selectionSet.selections) {
57114
57243
  this.add(subselect);
57115
57244
  }
57116
57245
  }
57117
- if (selection2.kind === "InlineFragment" && selection2.typeCondition) {
57118
- this.walkInlineFragment(selection2);
57246
+ if (selection.kind === "InlineFragment" && selection.typeCondition) {
57247
+ this.walkInlineFragment(selection);
57119
57248
  return;
57120
57249
  }
57121
- if (selection2.kind === "FragmentSpread") {
57122
- this.fragmentSpreads[selection2.name.value] = selection2;
57250
+ if (selection.kind === "FragmentSpread") {
57123
57251
  let includeFragments = this.config.defaultFragmentMasking === "disable";
57124
- const maskEnableDirective = selection2.directives?.find(
57252
+ const maskEnableDirective = selection.directives?.find(
57125
57253
  ({ name }) => name.value === this.config.maskEnableDirective
57126
57254
  );
57127
57255
  if (maskEnableDirective) {
57128
57256
  includeFragments = false;
57129
57257
  }
57130
- const maskDisableDirective = selection2.directives?.find(
57258
+ const maskDisableDirective = selection.directives?.find(
57131
57259
  ({ name }) => name.value === this.config.maskDisableDirective
57132
57260
  );
57133
57261
  if (maskDisableDirective) {
@@ -57136,14 +57264,17 @@ var FieldCollection = class {
57136
57264
  if (this.ignoreMaskDisable) {
57137
57265
  includeFragments = true;
57138
57266
  }
57139
- if (!includeFragments || !this.applyFragments) {
57267
+ if (this.keepFragmentSpreadNodes) {
57268
+ this.fragmentSpreads[selection.name.value] = selection;
57269
+ }
57270
+ if (!includeFragments) {
57140
57271
  return;
57141
57272
  }
57142
- const definition = this.fragmentDefinitions[selection2.name.value];
57273
+ const definition = this.fragmentDefinitions[selection.name.value];
57143
57274
  if (!definition) {
57144
57275
  throw new HoudiniError({
57145
57276
  filepath: this.filepath,
57146
- message: "Could not find referenced fragment definition: " + selection2.name.value
57277
+ message: "Could not find referenced fragment definition: " + selection.name.value + "\n" + JSON.stringify(Object.keys(this.fragmentDefinitions), null, 4)
57147
57278
  });
57148
57279
  }
57149
57280
  this.add({
@@ -57162,37 +57293,67 @@ var FieldCollection = class {
57162
57293
  });
57163
57294
  }
57164
57295
  }
57296
+ collectFragmentSpreads(selections, result = {}) {
57297
+ for (const selection of selections) {
57298
+ if (selection.kind === "Field") {
57299
+ continue;
57300
+ }
57301
+ if (selection.kind === "InlineFragment") {
57302
+ this.collectFragmentSpreads(selection.selectionSet.selections, result);
57303
+ continue;
57304
+ }
57305
+ if (selection.kind === "FragmentSpread") {
57306
+ result[selection.name.value] = selection;
57307
+ continue;
57308
+ }
57309
+ }
57310
+ return result;
57311
+ }
57165
57312
  toSelectionSet() {
57166
- return Object.values(this.inlineFragments).flatMap((fragment) => {
57167
- if (fragment.selection.size === 0) {
57313
+ return Object.values(this.inlineFragments).flatMap((fragment2) => {
57314
+ if (fragment2.selection.size === 0) {
57168
57315
  return [];
57169
57316
  }
57170
- fragment.astNode = {
57171
- ...fragment.astNode,
57317
+ fragment2.astNode = {
57318
+ ...fragment2.astNode,
57172
57319
  selectionSet: {
57173
- ...fragment.astNode.selectionSet,
57174
- selections: fragment.selection.toSelectionSet()
57320
+ ...fragment2.astNode.selectionSet,
57321
+ selections: fragment2.selection.toSelectionSet()
57175
57322
  }
57176
57323
  };
57177
- return [fragment.astNode];
57324
+ return [fragment2.astNode];
57178
57325
  }).concat(
57179
57326
  Object.values(this.fields).map((field) => {
57180
- if (field.astNode.selectionSet) {
57181
- field.astNode.selectionSet.selections = field.selection.toSelectionSet();
57182
- }
57183
- return field.astNode;
57327
+ return {
57328
+ ...field.astNode,
57329
+ selectionSet: field.astNode.selectionSet ? {
57330
+ kind: "SelectionSet",
57331
+ selections: field.selection.toSelectionSet()
57332
+ } : void 0
57333
+ };
57334
+ })
57335
+ ).concat(
57336
+ Object.values(this.fragmentSpreads).map((spread) => {
57337
+ return {
57338
+ kind: "FragmentSpread",
57339
+ name: {
57340
+ kind: "Name",
57341
+ value: spread.name.value
57342
+ },
57343
+ directives: spread.directives
57344
+ };
57184
57345
  })
57185
- ).concat(Object.values(this.fragmentSpreads));
57346
+ );
57186
57347
  }
57187
- walkInlineFragment(selection2) {
57188
- const key = selection2.typeCondition.name.value;
57348
+ walkInlineFragment(selection) {
57349
+ const key = selection.typeCondition.name.value;
57189
57350
  if (!this.inlineFragments[key]) {
57190
57351
  this.inlineFragments[key] = {
57191
- astNode: selection2,
57352
+ astNode: selection,
57192
57353
  selection: this.empty()
57193
57354
  };
57194
57355
  }
57195
- for (const subselect of selection2.selectionSet.selections || []) {
57356
+ for (const subselect of selection.selectionSet.selections || []) {
57196
57357
  if (subselect.kind !== "InlineFragment" || !subselect.typeCondition) {
57197
57358
  this.inlineFragments[key].selection.add(subselect);
57198
57359
  continue;
@@ -57206,8 +57367,8 @@ var FieldCollection = class {
57206
57367
  fragmentDefinitions: this.fragmentDefinitions,
57207
57368
  selections: [],
57208
57369
  filepath: this.filepath,
57209
- applyFragments: this.applyFragments,
57210
- ignoreMaskDisable: this.ignoreMaskDisable
57370
+ ignoreMaskDisable: this.ignoreMaskDisable,
57371
+ keepFragmentSpreadNodes: this.keepFragmentSpreadNodes
57211
57372
  });
57212
57373
  }
57213
57374
  };
@@ -57285,13 +57446,13 @@ function murmurHash(str) {
57285
57446
  // src/codegen/transforms/fragmentVariables.ts
57286
57447
  var graphql4 = __toESM(require_graphql2(), 1);
57287
57448
 
57288
- // src/codegen/transforms/composeQueries.ts
57449
+ // src/codegen/transforms/collectDefinitions.ts
57289
57450
  var import_graphql = __toESM(require_graphql2(), 1);
57290
57451
  async function includeFragmentDefinitions(config2, documents) {
57291
- const fragments = collectFragments(config2, documents);
57452
+ const fragments = collectDefinitions(config2, documents);
57292
57453
  for (const [index, { name, document, filename }] of documents.entries()) {
57293
57454
  const operation = document.definitions.find(
57294
- ({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
57455
+ (def) => def.kind === import_graphql.Kind.OPERATION_DEFINITION || def.kind === "FragmentDefinition"
57295
57456
  );
57296
57457
  if (!operation) {
57297
57458
  continue;
@@ -57310,7 +57471,7 @@ async function includeFragmentDefinitions(config2, documents) {
57310
57471
  };
57311
57472
  }
57312
57473
  }
57313
- function collectFragments(config2, docs) {
57474
+ function collectDefinitions(config2, docs) {
57314
57475
  return docs.reduce((acc, doc) => {
57315
57476
  const definitions = doc.document.definitions.reduce(
57316
57477
  (prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
@@ -57334,11 +57495,11 @@ function findRequiredFragments(selectionSet) {
57334
57495
  return [];
57335
57496
  }
57336
57497
  const referencedFragments = [];
57337
- for (const selection2 of selectionSet.selections) {
57338
- if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
57339
- referencedFragments.push(selection2.name.value);
57340
- } else if (selection2.selectionSet) {
57341
- referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
57498
+ for (const selection of selectionSet.selections) {
57499
+ if (selection.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
57500
+ referencedFragments.push(selection.name.value);
57501
+ } else if (selection.selectionSet) {
57502
+ referencedFragments.push(...findRequiredFragments(selection.selectionSet));
57342
57503
  }
57343
57504
  }
57344
57505
  return referencedFragments;
@@ -57371,7 +57532,7 @@ function flattenFragments(filepath, operation, fragments) {
57371
57532
  // src/codegen/transforms/fragmentVariables.ts
57372
57533
  var GraphqlKinds2 = graphql4.Kind;
57373
57534
  async function fragmentVariables(config2, documents) {
57374
- const fragments = collectFragments(config2, documents);
57535
+ const fragments = collectDefinitions(config2, documents);
57375
57536
  const generatedFragments = {};
57376
57537
  const visitedFragments = /* @__PURE__ */ new Set();
57377
57538
  for (const doc2 of documents) {
@@ -57431,9 +57592,17 @@ function inlineFragmentArgs({
57431
57592
  ).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
57432
57593
  const result = graphql4.visit(document, {
57433
57594
  FragmentSpread(node) {
57595
+ if (!fragmentDefinitions[node.name.value]) {
57596
+ throw new Error("Could not find definition for fragment" + node.name.value);
57597
+ }
57434
57598
  const { definition } = fragmentDefinitions[node.name.value];
57435
57599
  let { args, hash } = collectWithArguments(config2, filepath, node, scope);
57436
57600
  const newFragmentName = `${node.name.value}${hash}`;
57601
+ config2.registerFragmentVariablesHash({
57602
+ hash: newFragmentName,
57603
+ fragment: node.name.value,
57604
+ args
57605
+ });
57437
57606
  if (!visitedFragments.has(newFragmentName)) {
57438
57607
  visitedFragments.add(newFragmentName);
57439
57608
  const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
@@ -57832,7 +58001,7 @@ function operationObject({
57832
58001
  listName,
57833
58002
  operationKind,
57834
58003
  type,
57835
- selection: selection2,
58004
+ selection,
57836
58005
  filepath
57837
58006
  }) {
57838
58007
  let parentID;
@@ -57840,7 +58009,7 @@ function operationObject({
57840
58009
  let position = config2.internalListPosition;
57841
58010
  let allLists = config2.defaultListTarget ?? void 0;
57842
58011
  let operationWhen;
57843
- const internalDirectives = selection2.directives?.filter(
58012
+ const internalDirectives = selection.directives?.filter(
57844
58013
  (directive) => config2.isInternalDirective(directive.name.value)
57845
58014
  );
57846
58015
  if (internalDirectives && internalDirectives.length > 0) {
@@ -58076,7 +58245,7 @@ async function paginate(config2, documents) {
58076
58245
  let fragmentName = "";
58077
58246
  let refetchQueryName = "";
58078
58247
  let nodeQuery = false;
58079
- let fragment = "";
58248
+ let fragment2 = "";
58080
58249
  let paginateMode = config2.defaultPaginateMode;
58081
58250
  doc.document = graphql9.visit(doc.document, {
58082
58251
  OperationDefinition(node) {
@@ -58119,7 +58288,7 @@ async function paginate(config2, documents) {
58119
58288
  };
58120
58289
  },
58121
58290
  FragmentDefinition(node) {
58122
- fragment = node.typeCondition.name.value;
58291
+ fragment2 = node.typeCondition.name.value;
58123
58292
  fragmentName = node.name.value;
58124
58293
  refetchQueryName = config2.paginationQueryName(fragmentName);
58125
58294
  nodeQuery = node.typeCondition.name.value !== config2.schema.getQueryType()?.name;
@@ -58166,17 +58335,17 @@ async function paginate(config2, documents) {
58166
58335
  }
58167
58336
  });
58168
58337
  let targetType = config2.schema.getQueryType()?.name || "";
58169
- if (fragment) {
58338
+ if (fragment2) {
58170
58339
  const nodeInterface = config2.schema.getType("Node");
58171
58340
  if (nodeInterface) {
58172
58341
  const { objects, interfaces } = config2.schema.getImplementations(nodeInterface);
58173
- if (objects.find((obj) => obj.name === fragment) || interfaces.find((int) => int.name === fragment)) {
58342
+ if (objects.find((obj) => obj.name === fragment2) || interfaces.find((int) => int.name === fragment2)) {
58174
58343
  targetType = "Node";
58175
58344
  } else {
58176
- targetType = fragment;
58345
+ targetType = fragment2;
58177
58346
  }
58178
58347
  } else {
58179
- targetType = fragment;
58348
+ targetType = fragment2;
58180
58349
  }
58181
58350
  }
58182
58351
  const pageSize = flags.first.defaultValue ?? flags.last.defaultValue ?? flags.limit.defaultValue;
@@ -58198,7 +58367,7 @@ async function paginate(config2, documents) {
58198
58367
  start,
58199
58368
  mode: paginateMode
58200
58369
  };
58201
- if (!fragment) {
58370
+ if (!fragment2) {
58202
58371
  continue;
58203
58372
  }
58204
58373
  const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
@@ -58219,15 +58388,22 @@ async function paginate(config2, documents) {
58219
58388
  ["arguments"]: paginationArgs.map(
58220
58389
  ({ name }) => variableAsArgument(name)
58221
58390
  )
58391
+ },
58392
+ {
58393
+ kind: graphql9.Kind.DIRECTIVE,
58394
+ name: {
58395
+ kind: "Name",
58396
+ value: config2.maskDisableDirective
58397
+ }
58222
58398
  }
58223
58399
  ]
58224
58400
  }
58225
58401
  ];
58226
- const keys = config2.keyFieldsForType(!nodeQuery ? config2.schema.getQueryType()?.name || "" : fragment).flatMap((key) => {
58227
- if (fragment === config2.schema.getQueryType()?.name) {
58402
+ const keys = config2.keyFieldsForType(!nodeQuery ? config2.schema.getQueryType()?.name || "" : fragment2).flatMap((key) => {
58403
+ if (fragment2 === config2.schema.getQueryType()?.name) {
58228
58404
  return [];
58229
58405
  }
58230
- const fragmentType = config2.schema.getType(fragment);
58406
+ const fragmentType = config2.schema.getType(fragment2);
58231
58407
  const { type, wrappers } = unwrapType(
58232
58408
  config2,
58233
58409
  fragmentType.getFields()[key].type
@@ -58239,7 +58415,7 @@ async function paginate(config2, documents) {
58239
58415
  }
58240
58416
  ];
58241
58417
  });
58242
- const typeConfig = config2.typeConfig?.[fragment];
58418
+ const typeConfig = config2.typeConfig?.[fragment2];
58243
58419
  const queryDoc = {
58244
58420
  kind: graphql9.Kind.DOCUMENT,
58245
58421
  definitions: [
@@ -58581,7 +58757,7 @@ async function addListFragments(config2, documents) {
58581
58757
  );
58582
58758
  const targetField = ancestors[ancestors.length - 1];
58583
58759
  const targetFieldDefinition = parentType.getFields()[targetField.name.value];
58584
- const { selection: selection2, type, connection } = connectionSelection(
58760
+ const { selection, type, connection } = connectionSelection(
58585
58761
  config2,
58586
58762
  targetFieldDefinition,
58587
58763
  parentTypeFromAncestors(
@@ -58592,7 +58768,7 @@ async function addListFragments(config2, documents) {
58592
58768
  ancestors[ancestors.length - 1].selectionSet
58593
58769
  );
58594
58770
  lists[nameArg.value.value] = {
58595
- selection: selection2,
58771
+ selection,
58596
58772
  type,
58597
58773
  filename: doc.filename
58598
58774
  };
@@ -58670,14 +58846,14 @@ async function addListFragments(config2, documents) {
58670
58846
  const generatedDoc = {
58671
58847
  kind: graphql10.Kind.DOCUMENT,
58672
58848
  definitions: Object.entries(lists).flatMap(
58673
- ([name, { selection: selection2, type }]) => {
58849
+ ([name, { selection, type }]) => {
58674
58850
  const schemaType = config2.schema.getType(type.name);
58675
- if (!selection2) {
58851
+ if (!selection) {
58676
58852
  throw new HoudiniError({ message: "Lists must have a selection" });
58677
58853
  }
58678
58854
  const fragmentSelection = {
58679
58855
  kind: graphql10.Kind.SELECTION_SET,
58680
- selections: [...selection2.selections]
58856
+ selections: [...selection.selections]
58681
58857
  };
58682
58858
  if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
58683
58859
  (field) => field.kind === "Field" && config2.keyFieldsForType(type.name).includes(field.name.value)
@@ -58769,7 +58945,7 @@ async function addListFragments(config2, documents) {
58769
58945
  artifact: null
58770
58946
  });
58771
58947
  }
58772
- function connectionSelection(config2, field, type, selection2) {
58948
+ function connectionSelection(config2, field, type, selection) {
58773
58949
  const fieldArgs = field.args.reduce(
58774
58950
  (args, arg) => ({
58775
58951
  ...args,
@@ -58778,34 +58954,34 @@ function connectionSelection(config2, field, type, selection2) {
58778
58954
  {}
58779
58955
  );
58780
58956
  if (fieldArgs["limit"]) {
58781
- return { selection: selection2, type, connection: false, error: null };
58957
+ return { selection, type, connection: false, error: null };
58782
58958
  }
58783
58959
  const forwardPagination = fieldArgs["first"] === "Int" && ["Cursor", "String"].includes(fieldArgs["after"]);
58784
58960
  const backwardsPagination = fieldArgs["last"] === "Int" && ["Cursor", "String"].includes(fieldArgs["before"]);
58785
58961
  if (!forwardPagination && !backwardsPagination) {
58786
- return { selection: selection2, type, connection: false, error: missingPaginationArgMessage(config2) };
58962
+ return { selection, type, connection: false, error: missingPaginationArgMessage(config2) };
58787
58963
  }
58788
- const edgesField = selection2?.selections.find(
58789
- (selection3) => selection3.kind === "Field" && selection3.name.value === "edges"
58964
+ const edgesField = selection?.selections.find(
58965
+ (selection2) => selection2.kind === "Field" && selection2.name.value === "edges"
58790
58966
  );
58791
58967
  if (!edgesField) {
58792
- return { selection: selection2, type, connection: false, error: missingEdgeSelectionMessage(config2) };
58968
+ return { selection, type, connection: false, error: missingEdgeSelectionMessage(config2) };
58793
58969
  }
58794
58970
  const nodeSelection = edgesField.selectionSet?.selections.find(
58795
- (selection3) => selection3.kind === "Field" && selection3.name.value === "node"
58971
+ (selection2) => selection2.kind === "Field" && selection2.name.value === "node"
58796
58972
  );
58797
58973
  if (!nodeSelection.selectionSet) {
58798
- return { selection: selection2, type, connection: false, error: missingNodeSelectionMessage(config2) };
58974
+ return { selection, type, connection: false, error: missingNodeSelectionMessage(config2) };
58799
58975
  }
58800
58976
  const edgeField = unwrapType(config2, field.type).type.getFields()["edges"];
58801
58977
  const { wrappers, type: edgeFieldType } = unwrapType(config2, edgeField.type);
58802
58978
  const list = wrappers[wrappers.length - 2] === "List" /* List */;
58803
58979
  if (!list) {
58804
- return { selection: selection2, type, connection: false, error: edgeInvalidTypeMessage(config2) };
58980
+ return { selection, type, connection: false, error: edgeInvalidTypeMessage(config2) };
58805
58981
  }
58806
58982
  const nodeField = edgeFieldType.getFields()["node"];
58807
58983
  if (!nodeField) {
58808
- return { selection: selection2, type, connection: false, error: nodeNotDefinedMessage(config2) };
58984
+ return { selection, type, connection: false, error: nodeNotDefinedMessage(config2) };
58809
58985
  }
58810
58986
  return {
58811
58987
  selection: nodeSelection.selectionSet,
@@ -58884,59 +59060,45 @@ function fieldKey(config2, field) {
58884
59060
  }
58885
59061
 
58886
59062
  // src/codegen/generators/artifacts/selection.ts
58887
- function selection({
59063
+ function selection_default(args) {
59064
+ const typeMap = {};
59065
+ const abstractTypes = [];
59066
+ return mergeSelection({
59067
+ object: prepareSelection({ ...args, typeMap, abstractTypes }),
59068
+ filepath: args.filepath,
59069
+ typeMap,
59070
+ abstractTypes
59071
+ });
59072
+ }
59073
+ function prepareSelection({
58888
59074
  config: config2,
58889
59075
  filepath,
58890
59076
  rootType,
58891
59077
  selections,
58892
59078
  operations,
58893
59079
  path: path2 = [],
58894
- includeFragments,
58895
59080
  document,
58896
- inConnection
59081
+ inConnection,
59082
+ typeMap,
59083
+ abstractTypes
58897
59084
  }) {
58898
59085
  let object = {};
58899
- const typeMap = {};
58900
- const abstractTypes = [];
58901
59086
  for (const field of selections) {
58902
- if (field.kind === "FragmentSpread" && includeFragments) {
58903
- const fragmentDefinition = document.document.definitions.find(
58904
- (defn) => defn.kind === "FragmentDefinition" && defn.name.value === field.name.value
58905
- );
58906
- if (!fragmentDefinition) {
58907
- throw new HoudiniError({
58908
- filepath,
58909
- message: "selection: could not find definition for fragment " + field.name.value
58910
- });
58911
- }
58912
- object = deepMerge(
58913
- filepath,
58914
- object,
58915
- selection({
58916
- config: config2,
58917
- filepath,
58918
- rootType: fragmentDefinition.typeCondition.name.value,
58919
- operations,
58920
- selections: fragmentDefinition.selectionSet.selections,
58921
- path: path2,
58922
- includeFragments,
58923
- document
58924
- })
58925
- );
58926
- } else if (field.kind === "InlineFragment") {
59087
+ if (field.kind === "InlineFragment") {
58927
59088
  if (!field.typeCondition || field.typeCondition.name.value === rootType) {
58928
59089
  object.fields = deepMerge(
58929
59090
  filepath,
58930
59091
  object.fields || {},
58931
- selection({
59092
+ prepareSelection({
58932
59093
  config: config2,
58933
59094
  filepath,
58934
59095
  rootType: field.typeCondition?.name.value || rootType,
58935
59096
  operations,
58936
59097
  selections: field.selectionSet.selections,
58937
59098
  path: path2,
58938
- includeFragments,
58939
- document
59099
+ document,
59100
+ typeMap,
59101
+ abstractTypes
58940
59102
  }).fields || {}
58941
59103
  );
58942
59104
  } else {
@@ -58974,15 +59136,16 @@ function selection({
58974
59136
  }
58975
59137
  object.abstractFields.fields = {
58976
59138
  ...object.abstractFields.fields,
58977
- [field.typeCondition.name.value]: selection({
59139
+ [field.typeCondition.name.value]: prepareSelection({
58978
59140
  config: config2,
58979
59141
  filepath,
58980
59142
  rootType: field.typeCondition?.name.value || rootType,
58981
59143
  operations,
58982
59144
  selections: field.selectionSet.selections,
58983
59145
  path: path2,
58984
- includeFragments,
58985
- document
59146
+ document,
59147
+ typeMap,
59148
+ abstractTypes
58986
59149
  }).fields
58987
59150
  };
58988
59151
  }
@@ -59003,10 +59166,14 @@ function selection({
59003
59166
  }
59004
59167
  const typeName = fieldType.toString();
59005
59168
  const pathSoFar = path2.concat(attributeName);
59006
- const fieldObj = {
59169
+ const keys = config2.keyFieldsForType(rootType);
59170
+ let fieldObj = {
59007
59171
  type: typeName,
59008
59172
  keyRaw: fieldKey(config2, field)
59009
59173
  };
59174
+ if (keys.includes(field.name.value)) {
59175
+ fieldObj.visible = true;
59176
+ }
59010
59177
  if (nullable) {
59011
59178
  fieldObj.nullable = true;
59012
59179
  }
@@ -59054,16 +59221,17 @@ function selection({
59054
59221
  }
59055
59222
  if (field.selectionSet) {
59056
59223
  const connectionState = paginated && document.refetch?.method === "cursor" || continueConnection;
59057
- fieldObj.selection = selection({
59224
+ fieldObj.selection = prepareSelection({
59058
59225
  config: config2,
59059
59226
  filepath,
59060
59227
  rootType: typeName,
59061
59228
  selections: field.selectionSet.selections,
59062
59229
  operations,
59063
59230
  path: pathSoFar,
59064
- includeFragments,
59065
59231
  document,
59066
- inConnection: connectionState
59232
+ inConnection: connectionState,
59233
+ typeMap,
59234
+ abstractTypes
59067
59235
  });
59068
59236
  }
59069
59237
  if (field.arguments?.length && fieldObj.list) {
@@ -59078,12 +59246,29 @@ function selection({
59078
59246
  if (graphql12.isInterfaceType(fieldType) || graphql12.isUnionType(fieldType)) {
59079
59247
  fieldObj.abstract = true;
59080
59248
  }
59249
+ if (object.fields?.[attributeName]) {
59250
+ fieldObj = deepMerge(filepath, object.fields[attributeName], fieldObj);
59251
+ }
59081
59252
  object.fields = {
59082
59253
  ...object.fields,
59083
59254
  [attributeName]: fieldObj
59084
59255
  };
59256
+ } else if (field.kind === "FragmentSpread") {
59257
+ const { fragment: fragment2, args } = config2.getFragmentVariablesHash(field.name.value);
59258
+ object.fragments = {
59259
+ ...object.fragments,
59260
+ [fragment2]: args ?? {}
59261
+ };
59085
59262
  }
59086
59263
  }
59264
+ return object;
59265
+ }
59266
+ function mergeSelection({
59267
+ filepath,
59268
+ object,
59269
+ typeMap,
59270
+ abstractTypes
59271
+ }) {
59087
59272
  if (Object.keys(object.fields || {}).length > 0 && object.abstractFields && Object.keys(object.abstractFields.fields).length > 0) {
59088
59273
  for (const [typeName, possibles] of Object.entries(typeMap)) {
59089
59274
  let overlap = false;
@@ -59091,8 +59276,8 @@ function selection({
59091
59276
  if (object.abstractFields.fields[typeName]) {
59092
59277
  object.abstractFields.fields[typeName] = deepMerge(
59093
59278
  filepath,
59094
- object.abstractFields.fields[typeName] || {},
59095
- object.abstractFields.fields[possible]
59279
+ object.abstractFields.fields[typeName] ?? {},
59280
+ object.abstractFields.fields[possible] ?? {}
59096
59281
  );
59097
59282
  overlap = true;
59098
59283
  }
@@ -59123,6 +59308,30 @@ function selection({
59123
59308
  }
59124
59309
  }
59125
59310
  }
59311
+ for (const [key, value] of Object.entries(object.fields ?? {})) {
59312
+ const selection = value.selection;
59313
+ if (selection) {
59314
+ mergeSelection({
59315
+ filepath,
59316
+ typeMap,
59317
+ abstractTypes,
59318
+ object: selection
59319
+ });
59320
+ }
59321
+ }
59322
+ for (const [type, selection] of Object.entries(object.abstractFields?.fields ?? {})) {
59323
+ for (const [key, value] of Object.entries(selection ?? {})) {
59324
+ const selection2 = value.selection;
59325
+ if (selection2) {
59326
+ mergeSelection({
59327
+ filepath,
59328
+ typeMap,
59329
+ abstractTypes,
59330
+ object: selection2
59331
+ });
59332
+ }
59333
+ }
59334
+ }
59126
59335
  return object;
59127
59336
  }
59128
59337
 
@@ -59187,7 +59396,12 @@ function artifactGenerator(stats) {
59187
59396
  writeIndexFile(config2, docs)
59188
59397
  ].concat(
59189
59398
  docs.map(async (doc) => {
59190
- const { document, name, generateArtifact } = doc;
59399
+ const {
59400
+ document,
59401
+ name,
59402
+ generateArtifact,
59403
+ originalParsed
59404
+ } = doc;
59191
59405
  if (!generateArtifact) {
59192
59406
  return;
59193
59407
  }
@@ -59226,6 +59440,16 @@ function artifactGenerator(stats) {
59226
59440
  );
59227
59441
  let rootType = "";
59228
59442
  let selectionSet;
59443
+ let originalSelectionSet = null;
59444
+ const fragmentDefinitions = doc.document.definitions.filter(
59445
+ (definition) => definition.kind === "FragmentDefinition"
59446
+ ).reduce(
59447
+ (prev, definition) => ({
59448
+ ...prev,
59449
+ [definition.name.value]: definition
59450
+ }),
59451
+ {}
59452
+ );
59229
59453
  if (docKind !== ArtifactKind.Fragment) {
59230
59454
  const operation = operations[0];
59231
59455
  if (operation.operation === "query") {
@@ -59242,9 +59466,12 @@ function artifactGenerator(stats) {
59242
59466
  });
59243
59467
  }
59244
59468
  selectionSet = operation.selectionSet;
59469
+ if (originalParsed.definitions[0].kind === "OperationDefinition") {
59470
+ originalSelectionSet = originalParsed.definitions[0].selectionSet;
59471
+ }
59245
59472
  } else {
59246
59473
  const matchingFragment = fragments.find(
59247
- (fragment) => fragment.name.value === name
59474
+ (fragment2) => fragment2.name.value === name
59248
59475
  );
59249
59476
  if (!matchingFragment) {
59250
59477
  throw new HoudiniError({
@@ -59254,6 +59481,12 @@ function artifactGenerator(stats) {
59254
59481
  }
59255
59482
  rootType = matchingFragment.typeCondition.name.value;
59256
59483
  selectionSet = matchingFragment.selectionSet;
59484
+ if (originalParsed.definitions[0].kind === "FragmentDefinition") {
59485
+ originalSelectionSet = originalParsed.definitions[0].selectionSet;
59486
+ }
59487
+ }
59488
+ if (!originalSelectionSet) {
59489
+ throw new Error("Not original selection set!");
59257
59490
  }
59258
59491
  let inputs = operations[0]?.variableDefinitions;
59259
59492
  let directive = fragments[0]?.directives?.find(
@@ -59262,21 +59495,18 @@ function artifactGenerator(stats) {
59262
59495
  if (docKind === ArtifactKind.Fragment && directive) {
59263
59496
  inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
59264
59497
  }
59265
- const mergedSelection = flattenSelections({
59498
+ const mask = selection_default({
59266
59499
  config: config2,
59267
59500
  filepath: doc.filename,
59268
- selections: selectionSet.selections,
59269
- fragmentDefinitions: doc.document.definitions.filter(
59270
- (definition) => definition.kind === "FragmentDefinition"
59271
- ).reduce(
59272
- (prev, definition) => ({
59273
- ...prev,
59274
- [definition.name.value]: definition
59275
- }),
59276
- {}
59277
- ),
59278
- ignoreMaskDisable: docKind === "HoudiniQuery",
59279
- applyFragments: docKind !== "HoudiniFragment"
59501
+ rootType,
59502
+ operations: {},
59503
+ document: doc,
59504
+ selections: flattenSelections({
59505
+ config: config2,
59506
+ filepath: doc.filename,
59507
+ selections: selectionSet.selections,
59508
+ fragmentDefinitions
59509
+ })
59280
59510
  });
59281
59511
  let artifact = {
59282
59512
  name,
@@ -59285,21 +59515,29 @@ function artifactGenerator(stats) {
59285
59515
  refetch: doc.refetch,
59286
59516
  raw: rawString,
59287
59517
  rootType,
59288
- selection: selection({
59518
+ selection: selection_default({
59289
59519
  config: config2,
59290
59520
  filepath: doc.filename,
59291
59521
  rootType,
59292
- selections: mergedSelection,
59522
+ selections: flattenSelections({
59523
+ config: config2,
59524
+ filepath: doc.filename,
59525
+ selections: selectionSet.selections,
59526
+ fragmentDefinitions,
59527
+ ignoreMaskDisable: docKind !== "HoudiniFragment",
59528
+ keepFragmentSpreadNodes: true
59529
+ }),
59293
59530
  operations: operationsByPath(
59294
59531
  config2,
59295
59532
  doc.filename,
59296
59533
  operations[0],
59297
59534
  filterTypes
59298
59535
  ),
59299
- includeFragments: docKind !== "HoudiniFragment",
59300
59536
  document: doc
59301
- })
59537
+ }),
59538
+ pluginData: {}
59302
59539
  };
59540
+ applyMask(config2, artifact.selection, mask);
59303
59541
  artifact.pluginData = {};
59304
59542
  for (const plugin2 of config2.plugins) {
59305
59543
  if (!plugin2.artifactData) {
@@ -59376,6 +59614,49 @@ function artifactGenerator(stats) {
59376
59614
  stats.deleted = await cleanupFiles(config2.artifactDirectory, listOfArtifacts);
59377
59615
  };
59378
59616
  }
59617
+ function applyMask(config2, target, mask) {
59618
+ for (const [fieldName, value] of Object.entries(mask.fields ?? {})) {
59619
+ const targetSelection = target.fields?.[fieldName];
59620
+ if (!targetSelection || !mask.fields) {
59621
+ continue;
59622
+ }
59623
+ targetSelection.visible = true;
59624
+ if (targetSelection.selection && value.selection) {
59625
+ applyMask(config2, targetSelection.selection, value.selection);
59626
+ }
59627
+ }
59628
+ for (const [type, selection] of Object.entries(mask.abstractFields?.fields ?? {})) {
59629
+ if (!selection) {
59630
+ continue;
59631
+ }
59632
+ if (target.abstractFields?.fields[type]) {
59633
+ applyMask(config2, { fields: target.abstractFields.fields[type] }, { fields: selection });
59634
+ }
59635
+ const targetType = config2.schema.getType(type);
59636
+ if (!targetType) {
59637
+ continue;
59638
+ }
59639
+ if (graphql13.isAbstractType(targetType)) {
59640
+ for (const possible of config2.schema.getPossibleTypes(targetType)) {
59641
+ if (target.abstractFields?.fields[possible.name]) {
59642
+ applyMask(
59643
+ config2,
59644
+ { fields: target.abstractFields.fields[possible.name] },
59645
+ { fields: selection }
59646
+ );
59647
+ }
59648
+ }
59649
+ }
59650
+ const mappedType = target.abstractFields?.typeMap[type];
59651
+ if (target.abstractFields && mappedType && target.abstractFields.fields[mappedType]) {
59652
+ applyMask(
59653
+ config2,
59654
+ { fields: target.abstractFields.fields[mappedType] },
59655
+ { fields: selection }
59656
+ );
59657
+ }
59658
+ }
59659
+ }
59379
59660
 
59380
59661
  // src/codegen/generators/runtime/graphqlFunction.ts
59381
59662
  var recast6 = __toESM(require_main2(), 1);
@@ -59701,7 +59982,7 @@ function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingS
59701
59982
  var graphql17 = __toESM(require_graphql2(), 1);
59702
59983
  var recast10 = __toESM(require_main2(), 1);
59703
59984
  var AST10 = recast10.types.builders;
59704
- var fragmentKey = "$fragments";
59985
+ var fragmentKey2 = " $fragments";
59705
59986
  function inlineType({
59706
59987
  config: config2,
59707
59988
  filepath,
@@ -59741,24 +60022,24 @@ function inlineType({
59741
60022
  const rootObj = type;
59742
60023
  const inlineFragments = {};
59743
60024
  const selectedFields = [];
59744
- for (const selection2 of selections) {
59745
- if (selection2.kind === "InlineFragment" && selection2.typeCondition) {
59746
- const fragmentType = config2.schema.getType(selection2.typeCondition.name.value);
60025
+ for (const selection of selections) {
60026
+ if (selection.kind === "InlineFragment" && selection.typeCondition) {
60027
+ const fragmentType = config2.schema.getType(selection.typeCondition.name.value);
59747
60028
  if (!graphql17.isInterfaceType(type) && !graphql17.isUnionType(type)) {
59748
- selectedFields.push(...selection2.selectionSet.selections);
60029
+ selectedFields.push(...selection.selectionSet.selections);
59749
60030
  continue;
59750
60031
  }
59751
60032
  if (!graphql17.isInterfaceType(fragmentType) && !graphql17.isUnionType(fragmentType)) {
59752
60033
  if (!inlineFragments[fragmentType.name]) {
59753
60034
  inlineFragments[fragmentType.name] = [];
59754
60035
  }
59755
- inlineFragments[fragmentType.name].push(...selection2.selectionSet.selections);
60036
+ inlineFragments[fragmentType.name].push(...selection.selectionSet.selections);
59756
60037
  continue;
59757
60038
  }
59758
60039
  const possibleParents = config2.schema.getPossibleTypes(type).map((t) => t.name);
59759
60040
  const freeSelections = [];
59760
60041
  const typeSpecificSelections = {};
59761
- for (const node of selection2.selectionSet.selections) {
60042
+ for (const node of selection.selectionSet.selections) {
59762
60043
  if (node.kind !== "InlineFragment") {
59763
60044
  freeSelections.push(node);
59764
60045
  } else if (node.typeCondition) {
@@ -59781,23 +60062,30 @@ function inlineType({
59781
60062
  );
59782
60063
  }
59783
60064
  }
59784
- } else if (selection2.kind === "InlineFragment" && !selection2.typeCondition) {
59785
- selectedFields.push(...selection2.selectionSet.selections);
60065
+ } else if (selection.kind === "InlineFragment" && !selection.typeCondition) {
60066
+ selectedFields.push(...selection.selectionSet.selections);
59786
60067
  } else {
59787
- selectedFields.push(selection2);
60068
+ selectedFields.push(selection);
59788
60069
  }
59789
60070
  }
60071
+ const fields = Object.values(
60072
+ selectedFields.filter((field) => field.kind === "Field").reduce(
60073
+ (sel, field) => ({
60074
+ ...sel,
60075
+ [field.alias?.value ?? field.name.value]: field
60076
+ }),
60077
+ {}
60078
+ )
60079
+ );
59790
60080
  result = AST10.tsTypeLiteral([
59791
- ...(selectedFields || []).filter(
59792
- (field) => field.kind === "Field"
59793
- ).map((selection2) => {
59794
- const { field } = selectionTypeInfo(config2.schema, filepath, rootObj, selection2);
59795
- const attributeName = selection2.alias?.value || selection2.name.value;
60081
+ ...fields.map((selection) => {
60082
+ const { field } = selectionTypeInfo(config2.schema, filepath, rootObj, selection);
60083
+ const attributeName = selection.alias?.value || selection.name.value;
59796
60084
  let attributeType = inlineType({
59797
60085
  config: config2,
59798
60086
  filepath,
59799
60087
  rootType: field.type,
59800
- selections: selection2.selectionSet?.selections,
60088
+ selections: selection.selectionSet?.selections,
59801
60089
  root: false,
59802
60090
  allowReadonly,
59803
60091
  visitedTypes,
@@ -59806,7 +60094,7 @@ function inlineType({
59806
60094
  includeFragments,
59807
60095
  allOptional
59808
60096
  });
59809
- const hasIncludeOrSkipDirective = selection2.directives && selection2.directives.filter(
60097
+ const hasIncludeOrSkipDirective = selection.directives && selection.directives.filter(
59810
60098
  (directive) => directive.name.value === "include" || directive.name.value === "skip"
59811
60099
  ).length > 0;
59812
60100
  if (hasIncludeOrSkipDirective) {
@@ -59830,15 +60118,13 @@ function inlineType({
59830
60118
  result.members.push(
59831
60119
  readonlyProperty(
59832
60120
  AST10.tsPropertySignature(
59833
- AST10.identifier(fragmentKey),
60121
+ AST10.stringLiteral(fragmentKey2),
59834
60122
  AST10.tsTypeAnnotation(
59835
60123
  AST10.tsTypeLiteral(
59836
60124
  (fragmentSpreads || []).map(
59837
60125
  (fragmentSpread) => AST10.tsPropertySignature(
59838
60126
  AST10.identifier(fragmentSpread.name.value),
59839
- AST10.tsTypeAnnotation(
59840
- AST10.tsLiteralType(AST10.booleanLiteral(true))
59841
- )
60127
+ AST10.tsTypeAnnotation(AST10.tsTypeLiteral([]))
59842
60128
  )
59843
60129
  )
59844
60130
  )
@@ -59848,7 +60134,7 @@ function inlineType({
59848
60134
  )
59849
60135
  );
59850
60136
  }
59851
- const inlineFragmentSelections = Object.entries(inlineFragments).flatMap(([typeName, fragment]) => {
60137
+ const inlineFragmentSelections = Object.entries(inlineFragments).flatMap(([typeName, fragment2]) => {
59852
60138
  const fragmentRootType = config2.schema.getType(typeName);
59853
60139
  if (!fragmentRootType) {
59854
60140
  return [];
@@ -59857,7 +60143,7 @@ function inlineType({
59857
60143
  config: config2,
59858
60144
  filepath,
59859
60145
  rootType: fragmentRootType,
59860
- selections: fragment,
60146
+ selections: fragment2,
59861
60147
  allowReadonly,
59862
60148
  visitedTypes,
59863
60149
  root,
@@ -59929,10 +60215,10 @@ function inlineType({
59929
60215
  }
59930
60216
  return result;
59931
60217
  }
59932
- function selectionTypeInfo(schema, filepath, rootType, selection2) {
59933
- const selectionName = selection2.name.value;
60218
+ function selectionTypeInfo(schema, filepath, rootType, selection) {
60219
+ const selectionName = selection.name.value;
59934
60220
  let fields = {};
59935
- if (selection2.kind === "Field" && selection2.name.value === "__typename") {
60221
+ if (selection.kind === "Field" && selection.name.value === "__typename") {
59936
60222
  return {
59937
60223
  field: {
59938
60224
  name: "__typename",
@@ -60003,7 +60289,7 @@ async function generateDocumentTypes(config2, docs) {
60003
60289
  filepath: filename,
60004
60290
  selections: definition.selectionSet.selections,
60005
60291
  fragmentDefinitions,
60006
- applyFragments: definition.kind === "OperationDefinition"
60292
+ keepFragmentSpreadNodes: true
60007
60293
  });
60008
60294
  if (definition?.kind === "OperationDefinition") {
60009
60295
  await generateOperationTypeDefs(
@@ -60227,39 +60513,26 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
60227
60513
  if (!type) {
60228
60514
  throw new Error("Should not get here");
60229
60515
  }
60230
- let extraExports = [];
60231
60516
  let directive = definition.directives?.find(
60232
60517
  (directive2) => directive2.name.value === config2.argumentsDirective
60233
60518
  );
60234
- if (directive) {
60235
- extraExports.push(
60236
- AST11.exportNamedDeclaration(
60237
- AST11.tsTypeAliasDeclaration(
60238
- AST11.identifier(inputTypeName),
60239
- AST11.tsTypeLiteral(
60240
- (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
60241
- (definition2) => {
60242
- return AST11.tsPropertySignature(
60243
- AST11.identifier(definition2.variable.name.value),
60244
- AST11.tsTypeAnnotation(
60245
- tsTypeReference(
60246
- config2,
60247
- missingScalars,
60248
- definition2,
60249
- body
60250
- )
60251
- ),
60252
- definition2.type.kind !== "NonNullType"
60253
- );
60254
- }
60255
- )
60256
- )
60257
- )
60258
- )
60259
- );
60260
- }
60519
+ let inputValue = !directive ? AST11.tsTypeLiteral([]) : AST11.tsTypeLiteral(
60520
+ (fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
60521
+ (definition2) => {
60522
+ return AST11.tsPropertySignature(
60523
+ AST11.identifier(definition2.variable.name.value),
60524
+ AST11.tsTypeAnnotation(
60525
+ tsTypeReference(config2, missingScalars, definition2, body)
60526
+ ),
60527
+ definition2.type.kind !== "NonNullType"
60528
+ );
60529
+ }
60530
+ )
60531
+ );
60261
60532
  body.push(
60262
- ...extraExports,
60533
+ AST11.exportNamedDeclaration(
60534
+ AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), inputValue)
60535
+ ),
60263
60536
  AST11.exportNamedDeclaration(
60264
60537
  AST11.tsTypeAliasDeclaration(
60265
60538
  AST11.identifier(propTypeName),
@@ -60275,14 +60548,12 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
60275
60548
  ),
60276
60549
  readonlyProperty(
60277
60550
  AST11.tsPropertySignature(
60278
- AST11.stringLiteral(fragmentKey),
60551
+ AST11.stringLiteral(fragmentKey2),
60279
60552
  AST11.tsTypeAnnotation(
60280
60553
  AST11.tsTypeLiteral([
60281
60554
  AST11.tsPropertySignature(
60282
60555
  AST11.stringLiteral(propTypeName),
60283
- AST11.tsTypeAnnotation(
60284
- AST11.tsLiteralType(AST11.booleanLiteral(true))
60285
- )
60556
+ AST11.tsTypeAnnotation(AST11.tsAnyKeyword())
60286
60557
  )
60287
60558
  ])
60288
60559
  )
@@ -60994,6 +61265,13 @@ async function addID(config2, documents) {
60994
61265
  return;
60995
61266
  }
60996
61267
  return addKeysToSelection(config2, node, fragmentType);
61268
+ },
61269
+ FragmentDefinition(node) {
61270
+ const fragmentType = config2.schema.getType(node.typeCondition.name.value);
61271
+ if (!fragmentType) {
61272
+ return;
61273
+ }
61274
+ return addKeysToSelection(config2, node, fragmentType);
60997
61275
  }
60998
61276
  });
60999
61277
  }
@@ -61012,7 +61290,7 @@ function addKeysToSelection(config2, node, fieldType) {
61012
61290
  const selections = [...node.selectionSet.selections];
61013
61291
  for (const keyField of keyFields) {
61014
61292
  if (node.selectionSet.selections.find(
61015
- (selection2) => selection2.kind === "Field" && !selection2.alias && selection2.name.value === keyField
61293
+ (selection) => selection.kind === "Field" && !selection.alias && selection.name.value === keyField
61016
61294
  )) {
61017
61295
  continue;
61018
61296
  }