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
@@ -6805,8 +6805,8 @@ var require_KnownFragmentNamesRule = __commonJS({
6805
6805
  return {
6806
6806
  FragmentSpread: function FragmentSpread(node) {
6807
6807
  var fragmentName = node.name.value;
6808
- var fragment = context.getFragment(fragmentName);
6809
- if (!fragment) {
6808
+ var fragment2 = context.getFragment(fragmentName);
6809
+ if (!fragment2) {
6810
6810
  context.reportError(new _GraphQLError.GraphQLError('Unknown fragment "'.concat(fragmentName, '".'), node.name));
6811
6811
  }
6812
6812
  }
@@ -6842,8 +6842,8 @@ var require_NoUnusedFragmentsRule = __commonJS({
6842
6842
  for (var _i2 = 0; _i2 < operationDefs.length; _i2++) {
6843
6843
  var operation = operationDefs[_i2];
6844
6844
  for (var _i4 = 0, _context$getRecursive2 = context.getRecursivelyReferencedFragments(operation); _i4 < _context$getRecursive2.length; _i4++) {
6845
- var fragment = _context$getRecursive2[_i4];
6846
- fragmentNameUsed[fragment.name.value] = true;
6845
+ var fragment2 = _context$getRecursive2[_i4];
6846
+ fragmentNameUsed[fragment2.name.value] = true;
6847
6847
  }
6848
6848
  }
6849
6849
  for (var _i6 = 0; _i6 < fragmentDefs.length; _i6++) {
@@ -6933,13 +6933,13 @@ var require_NoFragmentCyclesRule = __commonJS({
6933
6933
  return false;
6934
6934
  }
6935
6935
  };
6936
- function detectCycleRecursive(fragment) {
6937
- if (visitedFrags[fragment.name.value]) {
6936
+ function detectCycleRecursive(fragment2) {
6937
+ if (visitedFrags[fragment2.name.value]) {
6938
6938
  return;
6939
6939
  }
6940
- var fragmentName = fragment.name.value;
6940
+ var fragmentName = fragment2.name.value;
6941
6941
  visitedFrags[fragmentName] = true;
6942
- var spreadNodes = context.getFragmentSpreads(fragment.selectionSet);
6942
+ var spreadNodes = context.getFragmentSpreads(fragment2.selectionSet);
6943
6943
  if (spreadNodes.length === 0) {
6944
6944
  return;
6945
6945
  }
@@ -7760,11 +7760,11 @@ var require_OverlappingFieldsCanBeMergedRule = __commonJS({
7760
7760
  return conflicts;
7761
7761
  }
7762
7762
  function collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap, fragmentName) {
7763
- var fragment = context.getFragment(fragmentName);
7764
- if (!fragment) {
7763
+ var fragment2 = context.getFragment(fragmentName);
7764
+ if (!fragment2) {
7765
7765
  return;
7766
7766
  }
7767
- var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment), fieldMap2 = _getReferencedFieldsA[0], fragmentNames2 = _getReferencedFieldsA[1];
7767
+ var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2), fieldMap2 = _getReferencedFieldsA[0], fragmentNames2 = _getReferencedFieldsA[1];
7768
7768
  if (fieldMap === fieldMap2) {
7769
7769
  return;
7770
7770
  }
@@ -7935,13 +7935,13 @@ var require_OverlappingFieldsCanBeMergedRule = __commonJS({
7935
7935
  }
7936
7936
  return cached;
7937
7937
  }
7938
- function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment) {
7939
- var cached = cachedFieldsAndFragmentNames.get(fragment.selectionSet);
7938
+ function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2) {
7939
+ var cached = cachedFieldsAndFragmentNames.get(fragment2.selectionSet);
7940
7940
  if (cached) {
7941
7941
  return cached;
7942
7942
  }
7943
- var fragmentType = (0, _typeFromAST.typeFromAST)(context.getSchema(), fragment.typeCondition);
7944
- return getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragmentType, fragment.selectionSet);
7943
+ var fragmentType = (0, _typeFromAST.typeFromAST)(context.getSchema(), fragment2.typeCondition);
7944
+ return getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragmentType, fragment2.selectionSet);
7945
7945
  }
7946
7946
  function _collectFieldsAndFragmentNames(context, parentType, selectionSet, nodeAndDefs, fragmentNames) {
7947
7947
  for (var _i9 = 0, _selectionSet$selecti2 = selectionSet.selections; _i9 < _selectionSet$selecti2.length; _i9++) {
@@ -8527,10 +8527,10 @@ var require_ValidationContext = __commonJS({
8527
8527
  var fragName = spread.name.value;
8528
8528
  if (collectedNames[fragName] !== true) {
8529
8529
  collectedNames[fragName] = true;
8530
- var fragment = this.getFragment(fragName);
8531
- if (fragment) {
8532
- fragments.push(fragment);
8533
- nodesToVisit.push(fragment.selectionSet);
8530
+ var fragment2 = this.getFragment(fragName);
8531
+ if (fragment2) {
8532
+ fragments.push(fragment2);
8533
+ nodesToVisit.push(fragment2.selectionSet);
8534
8534
  }
8535
8535
  }
8536
8536
  }
@@ -9469,11 +9469,11 @@ var require_execute = __commonJS({
9469
9469
  continue;
9470
9470
  }
9471
9471
  visitedFragmentNames[fragName] = true;
9472
- var fragment = exeContext.fragments[fragName];
9473
- if (!fragment || !doesFragmentConditionMatch(exeContext, fragment, runtimeType)) {
9472
+ var fragment2 = exeContext.fragments[fragName];
9473
+ if (!fragment2 || !doesFragmentConditionMatch(exeContext, fragment2, runtimeType)) {
9474
9474
  continue;
9475
9475
  }
9476
- collectFields(exeContext, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
9476
+ collectFields(exeContext, runtimeType, fragment2.selectionSet, fields, visitedFragmentNames);
9477
9477
  break;
9478
9478
  }
9479
9479
  }
@@ -9491,8 +9491,8 @@ var require_execute = __commonJS({
9491
9491
  }
9492
9492
  return true;
9493
9493
  }
9494
- function doesFragmentConditionMatch(exeContext, fragment, type) {
9495
- var typeConditionNode = fragment.typeCondition;
9494
+ function doesFragmentConditionMatch(exeContext, fragment2, type) {
9495
+ var typeConditionNode = fragment2.typeCondition;
9496
9496
  if (!typeConditionNode) {
9497
9497
  return true;
9498
9498
  }
@@ -58485,6 +58485,7 @@ __export(lib_exports, {
58485
58485
  fetch: () => fetch2,
58486
58486
  find_graphql: () => find_graphql,
58487
58487
  formatErrors: () => formatErrors,
58488
+ fragmentKey: () => fragmentKey,
58488
58489
  fs: () => fs_exports,
58489
58490
  getConfig: () => getConfig,
58490
58491
  getCurrentConfig: () => getCurrentConfig,
@@ -61819,45 +61820,6 @@ function marshalInputs({
61819
61820
  })
61820
61821
  );
61821
61822
  }
61822
- function unmarshalSelection(config, selection, data) {
61823
- if (data === null || typeof data === "undefined") {
61824
- return data;
61825
- }
61826
- if (Array.isArray(data)) {
61827
- return data.map((val) => unmarshalSelection(config, selection, val));
61828
- }
61829
- const targetSelection = getFieldsForType(selection, data["__typename"]);
61830
- return Object.fromEntries(
61831
- Object.entries(data).map(([fieldName, value]) => {
61832
- const { type, selection: selection2 } = targetSelection[fieldName];
61833
- if (!type) {
61834
- return [fieldName, value];
61835
- }
61836
- if (selection2) {
61837
- return [
61838
- fieldName,
61839
- unmarshalSelection(config, selection2, value)
61840
- ];
61841
- }
61842
- if (value === null) {
61843
- return [fieldName, value];
61844
- }
61845
- if (config.scalars?.[type]?.marshal) {
61846
- const unmarshalFn = config.scalars[type]?.unmarshal;
61847
- if (!unmarshalFn) {
61848
- throw new Error(
61849
- `scalar type ${type} is missing an \`unmarshal\` function. see https://github.com/AlecAivazis/houdini#%EF%B8%8Fcustom-scalars`
61850
- );
61851
- }
61852
- if (Array.isArray(value)) {
61853
- return [fieldName, value.map(unmarshalFn)];
61854
- }
61855
- return [fieldName, unmarshalFn(value)];
61856
- }
61857
- return [fieldName, value];
61858
- })
61859
- );
61860
- }
61861
61823
  function isScalar(config, type) {
61862
61824
  return ["String", "Boolean", "Float", "ID", "Int"].concat(Object.keys(config.scalars || {})).includes(type);
61863
61825
  }
@@ -61893,6 +61855,7 @@ var DataSource = {
61893
61855
  Network: "network",
61894
61856
  Ssr: "ssr"
61895
61857
  };
61858
+ var fragmentKey = " $fragments";
61896
61859
 
61897
61860
  // src/runtime/lib/store.ts
61898
61861
  var subscriber_queue = [];
@@ -63546,7 +63509,10 @@ function flatten(source) {
63546
63509
  var fetch2 = (target) => {
63547
63510
  return () => {
63548
63511
  return {
63549
- async network(ctx, { client: client2, resolve: resolve2, marshalVariables: marshalVariables2 }) {
63512
+ async network(ctx, { client: client2, initialValue, resolve: resolve2, marshalVariables: marshalVariables2 }) {
63513
+ if (ctx.artifact.kind === ArtifactKind.Fragment) {
63514
+ return resolve2(ctx, initialValue);
63515
+ }
63550
63516
  const fetch3 = ctx.fetch ?? globalThis.fetch;
63551
63517
  const fetchParams2 = {
63552
63518
  text: ctx.text,
@@ -64002,7 +63968,8 @@ var List = class {
64002
63968
  this.cache._internal_unstable.getSelection({
64003
63969
  parent: spec.parentID || this.manager.rootID,
64004
63970
  selection: spec.selection,
64005
- variables: spec.variables?.() || {}
63971
+ variables: spec.variables?.() || {},
63972
+ ignoreMasking: false
64006
63973
  }).data
64007
63974
  );
64008
63975
  }
@@ -64622,7 +64589,17 @@ var InMemorySubscriptions = class {
64622
64589
  const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
64623
64590
  let targetSelection = getFieldsForType(selection, __typename);
64624
64591
  for (const fieldSelection of Object.values(targetSelection || {})) {
64625
- const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
64592
+ const {
64593
+ keyRaw,
64594
+ selection: innerSelection,
64595
+ type,
64596
+ list,
64597
+ filters,
64598
+ visible
64599
+ } = fieldSelection;
64600
+ if (!visible) {
64601
+ continue;
64602
+ }
64626
64603
  const key = evaluateKey(keyRaw, variables);
64627
64604
  let targetSelection2;
64628
64605
  if (innerSelection) {
@@ -64696,7 +64673,6 @@ var InMemorySubscriptions = class {
64696
64673
  const counts = this.referenceCounts[id][key];
64697
64674
  counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
64698
64675
  this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
64699
- const { selection: innerSelection } = selection[1]?.[key] ?? {};
64700
64676
  }
64701
64677
  registerList({
64702
64678
  list,
@@ -64850,7 +64826,7 @@ var InMemorySubscriptions = class {
64850
64826
  // src/runtime/cache/cache.ts
64851
64827
  var Cache = class {
64852
64828
  _internal_unstable;
64853
- constructor(config) {
64829
+ constructor({ disabled, ...config } = {}) {
64854
64830
  this._internal_unstable = new CacheInternal({
64855
64831
  cache: this,
64856
64832
  storage: new InMemoryStorage(),
@@ -64858,9 +64834,10 @@ var Cache = class {
64858
64834
  lists: new ListManager(this, rootID),
64859
64835
  lifetimes: new GarbageCollector(this),
64860
64836
  staleManager: new StaleManager(this),
64861
- schema: new SchemaManager(this)
64837
+ schema: new SchemaManager(this),
64838
+ disabled: disabled ?? typeof globalThis.window === "undefined"
64862
64839
  });
64863
- if (config) {
64840
+ if (Object.keys(config).length > 0) {
64864
64841
  this.setConfig(defaultConfigValues(config));
64865
64842
  }
64866
64843
  }
@@ -64879,7 +64856,8 @@ var Cache = class {
64879
64856
  this._internal_unstable.getSelection({
64880
64857
  parent: spec.parentID || rootID,
64881
64858
  selection: spec.selection,
64882
- variables: spec.variables?.() || {}
64859
+ variables: spec.variables?.() || {},
64860
+ ignoreMasking: false
64883
64861
  }).data
64884
64862
  );
64885
64863
  }
@@ -64954,16 +64932,13 @@ var Cache = class {
64954
64932
  getFieldTime(id, field) {
64955
64933
  return this._internal_unstable.staleManager.getFieldTime(id, field);
64956
64934
  }
64935
+ config() {
64936
+ return this._internal_unstable.config;
64937
+ }
64957
64938
  };
64958
64939
  var CacheInternal = class {
64959
64940
  _disabled = false;
64960
- config = defaultConfigValues({
64961
- plugins: {
64962
- "houdini-svelte": {
64963
- client: ""
64964
- }
64965
- }
64966
- });
64941
+ _config;
64967
64942
  storage;
64968
64943
  subscriptions;
64969
64944
  lists;
@@ -64978,7 +64953,9 @@ var CacheInternal = class {
64978
64953
  cache,
64979
64954
  lifetimes,
64980
64955
  staleManager,
64981
- schema
64956
+ schema,
64957
+ disabled,
64958
+ config
64982
64959
  }) {
64983
64960
  this.storage = storage;
64984
64961
  this.subscriptions = subscriptions;
@@ -64987,7 +64964,8 @@ var CacheInternal = class {
64987
64964
  this.lifetimes = lifetimes;
64988
64965
  this.staleManager = staleManager;
64989
64966
  this.schema = schema;
64990
- this._disabled = typeof globalThis.window === "undefined";
64967
+ this._config = config;
64968
+ this._disabled = disabled;
64991
64969
  try {
64992
64970
  if (process.env.HOUDINI_TEST === "true") {
64993
64971
  this._disabled = false;
@@ -64995,8 +64973,11 @@ var CacheInternal = class {
64995
64973
  } catch {
64996
64974
  }
64997
64975
  }
64976
+ get config() {
64977
+ return this._config ?? getCurrentConfig();
64978
+ }
64998
64979
  setConfig(config) {
64999
- this.config = config;
64980
+ this._config = config;
65000
64981
  }
65001
64982
  writeSelection({
65002
64983
  data,
@@ -65273,12 +65254,24 @@ var CacheInternal = class {
65273
65254
  selection,
65274
65255
  parent = rootID,
65275
65256
  variables,
65276
- stepsFromConnection = null
65257
+ stepsFromConnection = null,
65258
+ ignoreMasking
65277
65259
  }) {
65278
65260
  if (parent === null) {
65279
65261
  return { data: null, partial: false, stale: false, hasData: true };
65280
65262
  }
65281
65263
  const target = {};
65264
+ if (selection.fragments) {
65265
+ target[fragmentKey] = Object.fromEntries(
65266
+ Object.entries(selection.fragments).map(([key, value]) => [
65267
+ key,
65268
+ {
65269
+ parent,
65270
+ variables: evaluateFragmentVariables(value, variables ?? {})
65271
+ }
65272
+ ])
65273
+ );
65274
+ }
65282
65275
  let hasData = false;
65283
65276
  let partial = false;
65284
65277
  let cascadeNull = false;
@@ -65287,8 +65280,11 @@ var CacheInternal = class {
65287
65280
  let targetSelection = getFieldsForType(selection, typename);
65288
65281
  for (const [
65289
65282
  attributeName,
65290
- { type, keyRaw, selection: fieldSelection, nullable, list }
65283
+ { type, keyRaw, selection: fieldSelection, nullable, list, visible }
65291
65284
  ] of Object.entries(targetSelection)) {
65285
+ if (!visible && !ignoreMasking) {
65286
+ continue;
65287
+ }
65292
65288
  const key = evaluateKey(keyRaw, variables);
65293
65289
  const { value } = this.storage.get(parent, key);
65294
65290
  const dt_field = this.staleManager.getFieldTime(parent, key);
@@ -65328,7 +65324,8 @@ var CacheInternal = class {
65328
65324
  fields: fieldSelection,
65329
65325
  variables,
65330
65326
  linkedList: value,
65331
- stepsFromConnection: nextStep
65327
+ stepsFromConnection: nextStep,
65328
+ ignoreMasking: !!ignoreMasking
65332
65329
  });
65333
65330
  target[attributeName] = listValue.data;
65334
65331
  if (listValue.partial) {
@@ -65345,7 +65342,8 @@ var CacheInternal = class {
65345
65342
  parent: value,
65346
65343
  selection: fieldSelection,
65347
65344
  variables,
65348
- stepsFromConnection: nextStep
65345
+ stepsFromConnection: nextStep,
65346
+ ignoreMasking
65349
65347
  });
65350
65348
  target[attributeName] = objectFields.data;
65351
65349
  if (objectFields.partial) {
@@ -65389,7 +65387,8 @@ var CacheInternal = class {
65389
65387
  fields,
65390
65388
  variables,
65391
65389
  linkedList,
65392
- stepsFromConnection
65390
+ stepsFromConnection,
65391
+ ignoreMasking
65393
65392
  }) {
65394
65393
  const result = [];
65395
65394
  let partialData = false;
@@ -65401,7 +65400,8 @@ var CacheInternal = class {
65401
65400
  fields,
65402
65401
  variables,
65403
65402
  linkedList: entry,
65404
- stepsFromConnection
65403
+ stepsFromConnection,
65404
+ ignoreMasking
65405
65405
  });
65406
65406
  result.push(nestedValue.data);
65407
65407
  if (nestedValue.partial) {
@@ -65422,7 +65422,8 @@ var CacheInternal = class {
65422
65422
  parent: entry,
65423
65423
  selection: fields,
65424
65424
  variables,
65425
- stepsFromConnection
65425
+ stepsFromConnection,
65426
+ ignoreMasking
65426
65427
  });
65427
65428
  result.push(data);
65428
65429
  if (partial) {
@@ -65525,16 +65526,58 @@ var CacheInternal = class {
65525
65526
  }
65526
65527
  }
65527
65528
  };
65529
+ function evaluateFragmentVariables(variables, args) {
65530
+ return Object.fromEntries(
65531
+ Object.entries(variables).map(([key, value]) => [key, fragmentVariableValue(value, args)])
65532
+ );
65533
+ }
65534
+ function fragmentVariableValue(value, args) {
65535
+ if (value.kind === "StringValue") {
65536
+ return value.value;
65537
+ }
65538
+ if (value.kind === "BooleanValue") {
65539
+ return value.value;
65540
+ }
65541
+ if (value.kind === "EnumValue") {
65542
+ return value.value;
65543
+ }
65544
+ if (value.kind === "FloatValue") {
65545
+ return parseFloat(value.value);
65546
+ }
65547
+ if (value.kind === "IntValue") {
65548
+ return parseInt(value.value, 10);
65549
+ }
65550
+ if (value.kind === "NullValue") {
65551
+ return null;
65552
+ }
65553
+ if (value.kind === "Variable") {
65554
+ return args[value.name.value];
65555
+ }
65556
+ if (value.kind === "ListValue") {
65557
+ return value.values.map((value2) => fragmentVariableValue(value2, args));
65558
+ }
65559
+ if (value.kind === "ObjectValue") {
65560
+ return value.fields.reduce(
65561
+ (obj, field) => ({
65562
+ ...obj,
65563
+ [field.name.value]: fragmentVariableValue(field.value, args)
65564
+ }),
65565
+ {}
65566
+ );
65567
+ }
65568
+ }
65528
65569
  var rootID = "_ROOT_";
65529
65570
 
65530
65571
  // src/runtime/cache/index.ts
65531
65572
  var cache_default = new Cache();
65532
65573
 
65533
65574
  // src/runtime/client/plugins/cache.ts
65575
+ var serverSide = typeof globalThis.window === "undefined";
65534
65576
  var cachePolicy = ({
65535
65577
  enabled,
65536
65578
  setFetching,
65537
- cache: localCache = cache_default
65579
+ cache: localCache = cache_default,
65580
+ serverSideFallback = true
65538
65581
  }) => () => {
65539
65582
  return {
65540
65583
  network(ctx, { initialValue, next, resolve: resolve2, marshalVariables: marshalVariables2 }) {
@@ -65585,13 +65628,26 @@ var cachePolicy = ({
65585
65628
  },
65586
65629
  afterNetwork(ctx, { resolve: resolve2, value, marshalVariables: marshalVariables2 }) {
65587
65630
  if (value.source !== DataSource.Cache && enabled && value.data && !ctx.cacheParams?.disableWrite) {
65588
- localCache.write({
65631
+ const targetCache = serverSide && serverSideFallback ? new Cache({ disabled: false }) : localCache;
65632
+ let layer;
65633
+ if (!serverSide && ctx.cacheParams?.layer) {
65634
+ layer = ctx.cacheParams.layer.id;
65635
+ }
65636
+ targetCache.write({
65589
65637
  ...ctx.cacheParams,
65590
- layer: ctx.cacheParams?.layer?.id,
65638
+ layer,
65591
65639
  selection: ctx.artifact.selection,
65592
65640
  data: value.data,
65593
65641
  variables: marshalVariables2(ctx)
65594
65642
  });
65643
+ value = {
65644
+ ...value,
65645
+ data: targetCache.read({
65646
+ selection: ctx.artifact.selection,
65647
+ variables: marshalVariables2(ctx),
65648
+ ignoreMasking: serverSide
65649
+ }).data
65650
+ };
65595
65651
  }
65596
65652
  resolve2(ctx, value);
65597
65653
  }
@@ -65633,7 +65689,6 @@ var documentPlugin = (kind, source) => {
65633
65689
  var query = documentPlugin(ArtifactKind.Query, function() {
65634
65690
  let subscriptionSpec = null;
65635
65691
  let lastVariables = null;
65636
- let artifactName = "";
65637
65692
  return {
65638
65693
  start(ctx, { next }) {
65639
65694
  ctx.variables = {
@@ -65643,8 +65698,7 @@ var query = documentPlugin(ArtifactKind.Query, function() {
65643
65698
  next(ctx);
65644
65699
  },
65645
65700
  end(ctx, { resolve: resolve2, marshalVariables: marshalVariables2, variablesChanged: variablesChanged2 }) {
65646
- if (variablesChanged2(ctx)) {
65647
- artifactName = ctx.artifact.name;
65701
+ if (variablesChanged2(ctx) && !ctx.cacheParams?.disableSubscriptions) {
65648
65702
  if (subscriptionSpec) {
65649
65703
  cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
65650
65704
  }
@@ -65665,19 +65719,61 @@ var query = documentPlugin(ArtifactKind.Query, function() {
65665
65719
  });
65666
65720
  }
65667
65721
  };
65668
- cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
65722
+ cache_default.subscribe(subscriptionSpec, lastVariables);
65669
65723
  }
65670
65724
  resolve2(ctx);
65671
65725
  },
65672
65726
  cleanup() {
65673
65727
  if (subscriptionSpec) {
65674
- cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
65728
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.());
65675
65729
  lastVariables = null;
65676
65730
  }
65677
65731
  }
65678
65732
  };
65679
65733
  });
65680
65734
 
65735
+ // src/runtime/client/plugins/fragment.ts
65736
+ var fragment = documentPlugin(ArtifactKind.Fragment, function() {
65737
+ let subscriptionSpec = null;
65738
+ return {
65739
+ start(ctx, { next, resolve: resolve2, variablesChanged: variablesChanged2, marshalVariables: marshalVariables2 }) {
65740
+ if (!ctx.stuff.parentID) {
65741
+ return next(ctx);
65742
+ }
65743
+ if (variablesChanged2(ctx) && !ctx.cacheParams?.disableSubscriptions) {
65744
+ if (subscriptionSpec) {
65745
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
65746
+ }
65747
+ const variables = marshalVariables2(ctx);
65748
+ subscriptionSpec = {
65749
+ rootType: ctx.artifact.rootType,
65750
+ selection: ctx.artifact.selection,
65751
+ variables: () => variables,
65752
+ parentID: ctx.stuff.parentID,
65753
+ set: (newValue) => {
65754
+ resolve2(ctx, {
65755
+ data: newValue,
65756
+ errors: null,
65757
+ fetching: false,
65758
+ partial: false,
65759
+ stale: false,
65760
+ source: DataSource.Cache,
65761
+ variables
65762
+ });
65763
+ }
65764
+ };
65765
+ cache_default.subscribe(subscriptionSpec, variables);
65766
+ }
65767
+ next(ctx);
65768
+ },
65769
+ cleanup() {
65770
+ if (subscriptionSpec) {
65771
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.());
65772
+ }
65773
+ }
65774
+ };
65775
+ });
65776
+
65681
65777
  // src/runtime/client/plugins/mutation.ts
65682
65778
  var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65683
65779
  return {
@@ -66011,8 +66107,8 @@ var DocumentStore = class extends Writable {
66011
66107
  handlers = {
66012
66108
  ...common,
66013
66109
  value,
66014
- resolve: (ctx2, data2) => {
66015
- return common.resolve(ctx2, data2 ?? value);
66110
+ resolve: (ctx2, data) => {
66111
+ return common.resolve(ctx2, data ?? value);
66016
66112
  }
66017
66113
  };
66018
66114
  } else if (direction === "error") {
@@ -66072,25 +66168,16 @@ var DocumentStore = class extends Writable {
66072
66168
  value
66073
66169
  );
66074
66170
  }
66075
- let data = value.data;
66076
- try {
66077
- data = unmarshalSelection(this.#configFile, this.#artifact.selection, data) ?? null;
66078
- } catch {
66079
- }
66080
- const finalValue = {
66081
- ...value,
66082
- data
66083
- };
66084
66171
  if (!ctx.promise.resolved) {
66085
- ctx.promise.resolve(finalValue);
66172
+ ctx.promise.resolve(value);
66086
66173
  ctx.promise.resolved = true;
66087
66174
  }
66088
66175
  this.#lastContext = ctx.context.draft();
66089
66176
  this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
66090
- if (ctx.silenceEcho && finalValue.data === this.state.data) {
66177
+ if (ctx.silenceEcho && value.data === this.state.data) {
66091
66178
  return;
66092
66179
  }
66093
- this.set(finalValue);
66180
+ this.set(value);
66094
66181
  }
66095
66182
  };
66096
66183
  var ClientPluginContextWrapper = class {
@@ -66211,7 +66298,8 @@ var HoudiniClient = class {
66211
66298
  fetchParams(fetchParams2),
66212
66299
  pipeline2 ?? [
66213
66300
  query,
66214
- mutation
66301
+ mutation,
66302
+ fragment
66215
66303
  ].concat(
66216
66304
  plugins2 ?? [],
66217
66305
  injectedPlugins_default,
@@ -66367,6 +66455,7 @@ var Config = class {
66367
66455
  this.schemaPollInterval = watchSchema?.interval ?? 2e3;
66368
66456
  this.schemaPollHeaders = watchSchema?.headers ?? {};
66369
66457
  this.rootDir = join2(this.projectRoot, "$houdini");
66458
+ this.#fragmentVariableMaps = {};
66370
66459
  if (defaultKeys) {
66371
66460
  this.defaultKeys = defaultKeys;
66372
66461
  }
@@ -66516,7 +66605,7 @@ var Config = class {
66516
66605
  return `$houdini/${this.artifactDirectoryName}/${name}`;
66517
66606
  }
66518
66607
  keyFieldsForType(type) {
66519
- return keyFieldsForType(this.configFile, type);
66608
+ return this.schema.getQueryType()?.name === type ? [] : keyFieldsForType(this.configFile, type);
66520
66609
  }
66521
66610
  computeID(type, data) {
66522
66611
  return computeID(this.configFile, type, data);
@@ -66535,7 +66624,7 @@ var Config = class {
66535
66624
  ({ kind }) => kind === graphql2.Kind.FRAGMENT_DEFINITION
66536
66625
  );
66537
66626
  if (fragmentDefinitions.length) {
66538
- return fragmentDefinitions.map((fragment) => fragment.name.value).join("_");
66627
+ return fragmentDefinitions[0].name.value;
66539
66628
  }
66540
66629
  throw new Error("Could not generate artifact name for document: " + graphql2.print(document));
66541
66630
  }
@@ -66707,6 +66796,56 @@ var Config = class {
66707
66796
  }, []) ?? [];
66708
66797
  return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
66709
66798
  }
66799
+ #fragmentVariableMaps;
66800
+ registerFragmentVariablesHash({
66801
+ hash,
66802
+ args,
66803
+ fragment: fragment2
66804
+ }) {
66805
+ this.#fragmentVariableMaps[hash] = {
66806
+ args: this.#serializeValueMap(args),
66807
+ fragment: fragment2
66808
+ };
66809
+ }
66810
+ getFragmentVariablesHash(hash) {
66811
+ return this.#fragmentVariableMaps[hash] ?? {
66812
+ fragment: hash,
66813
+ args: {},
66814
+ hash
66815
+ };
66816
+ }
66817
+ #serializeValueMap(map) {
66818
+ if (!map) {
66819
+ return null;
66820
+ }
66821
+ return Object.fromEntries(
66822
+ Object.entries(map).map(([key, input]) => {
66823
+ const result = {
66824
+ kind: input.kind
66825
+ };
66826
+ if (typeof input === "object") {
66827
+ if ("value" in input) {
66828
+ result.value = input.value;
66829
+ }
66830
+ if ("values" in input) {
66831
+ result.values = input.values.map(
66832
+ (value) => this.#serializeValueMap({ foo: value }).foo
66833
+ );
66834
+ }
66835
+ if ("name" in input) {
66836
+ result.name = input.name;
66837
+ }
66838
+ if ("fields" in input) {
66839
+ result.fields = input.fields.map((field) => ({
66840
+ name: field.name,
66841
+ value: this.#serializeValueMap({ foo: field.value }).foo
66842
+ }));
66843
+ }
66844
+ }
66845
+ return [key, result];
66846
+ })
66847
+ );
66848
+ }
66710
66849
  isListFragment(name) {
66711
66850
  return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
66712
66851
  }
@@ -67233,11 +67372,17 @@ function deepMerge(filepath, ...targets) {
67233
67372
  if (targets.length === 1) {
67234
67373
  return targets[0];
67235
67374
  } else if (targets.length === 2) {
67236
- return (0, import_deepmerge.default)(targets[0], targets[1]);
67375
+ return (0, import_deepmerge.default)(targets[0], targets[1], {
67376
+ arrayMerge: (source, update) => [...new Set(source.concat(update))]
67377
+ });
67237
67378
  }
67238
67379
  return deepMerge(filepath, targets[0], deepMerge(filepath, ...targets.slice(1)));
67239
67380
  } catch (e2) {
67240
- throw new HoudiniError({ filepath, message: "could not merge: " + targets });
67381
+ throw new HoudiniError({
67382
+ filepath,
67383
+ message: "could not merge: " + targets,
67384
+ description: e2.message
67385
+ });
67241
67386
  }
67242
67387
  }
67243
67388
 
@@ -67505,6 +67650,7 @@ async function find_graphql(config, parsedScript, walker) {
67505
67650
  fetch,
67506
67651
  find_graphql,
67507
67652
  formatErrors,
67653
+ fragmentKey,
67508
67654
  fs,
67509
67655
  getConfig,
67510
67656
  getCurrentConfig,