houdini 1.0.0-next.2 → 1.0.0-next.20

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 (195) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +5366 -2772
  3. package/build/cmd-esm/index.js +5340 -2746
  4. package/build/codegen/generators/artifacts/index.d.ts +2 -2
  5. package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
  6. package/build/codegen/generators/artifacts/selection.d.ts +5 -5
  7. package/build/codegen/generators/artifacts/utils.d.ts +0 -1
  8. package/build/codegen/generators/indexFile/index.d.ts +2 -2
  9. package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
  10. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -2
  11. package/build/codegen/generators/runtime/index.d.ts +2 -2
  12. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  13. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  14. package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
  15. package/build/codegen/generators/typescript/index.d.ts +2 -2
  16. package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
  17. package/build/codegen/generators/typescript/types.d.ts +0 -1
  18. package/build/codegen/index.d.ts +2 -2
  19. package/build/codegen/transforms/addID.d.ts +2 -2
  20. package/build/codegen/transforms/composeQueries.d.ts +4 -4
  21. package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
  22. package/build/codegen/transforms/list.d.ts +2 -2
  23. package/build/codegen/transforms/paginate.d.ts +2 -2
  24. package/build/codegen/transforms/schema.d.ts +2 -2
  25. package/build/codegen/transforms/typename.d.ts +2 -2
  26. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  27. package/build/codegen/validators/noIDAlias.d.ts +2 -2
  28. package/build/codegen/validators/plugins.d.ts +2 -2
  29. package/build/codegen/validators/typeCheck.d.ts +2 -2
  30. package/build/codegen/validators/uniqueNames.d.ts +2 -2
  31. package/build/codegen-cjs/index.js +4694 -2137
  32. package/build/codegen-esm/index.js +4682 -2125
  33. package/build/lib/config.d.ts +15 -96
  34. package/build/lib/deepMerge.d.ts +1 -0
  35. package/build/lib/graphql.d.ts +5 -2
  36. package/build/lib/index.d.ts +2 -0
  37. package/build/lib/path.d.ts +1 -1
  38. package/build/lib/pipeline.d.ts +1 -1
  39. package/build/lib/plugin.d.ts +2 -0
  40. package/build/lib/types.d.ts +257 -6
  41. package/build/lib/walk.d.ts +4 -1
  42. package/build/lib-cjs/index.js +4108 -928
  43. package/build/lib-esm/index.js +4078 -907
  44. package/build/runtime/cache/cache.d.ts +28 -11
  45. package/build/runtime/cache/lists.d.ts +1 -0
  46. package/build/runtime/cache/staleManager.d.ts +30 -0
  47. package/build/runtime/cache/storage.d.ts +23 -20
  48. package/build/runtime/cache/stuff.d.ts +0 -2
  49. package/build/runtime/cache/subscription.d.ts +2 -1
  50. package/build/runtime/client/documentStore.d.ts +20 -17
  51. package/build/runtime/client/index.d.ts +13 -11
  52. package/build/runtime/client/plugins/cache.d.ts +1 -1
  53. package/build/runtime/client/plugins/fetch.d.ts +1 -1
  54. package/build/runtime/client/plugins/fetchParams.d.ts +2 -2
  55. package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
  56. package/build/runtime/client/plugins/mutation.d.ts +1 -1
  57. package/build/runtime/client/plugins/query.d.ts +1 -1
  58. package/build/runtime/client/plugins/subscription.d.ts +2 -3
  59. package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
  60. package/build/runtime/client/utils/documentPlugins.d.ts +3 -3
  61. package/build/runtime/generated.d.ts +1 -0
  62. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  63. package/build/runtime/index.d.ts +1 -1
  64. package/build/runtime/lib/config.d.ts +27 -24
  65. package/build/runtime/lib/flatten.d.ts +2 -0
  66. package/build/runtime/lib/index.d.ts +1 -0
  67. package/build/runtime/lib/key.d.ts +6 -0
  68. package/build/runtime/lib/scalars.d.ts +3 -3
  69. package/build/runtime/lib/types.d.ts +46 -46
  70. package/build/runtime/public/cache.d.ts +26 -6
  71. package/build/runtime/public/record.d.ts +26 -17
  72. package/build/runtime/public/tests/test.d.ts +52 -10
  73. package/build/runtime/public/types.d.ts +8 -0
  74. package/build/runtime-cjs/cache/cache.d.ts +28 -11
  75. package/build/runtime-cjs/cache/cache.js +97 -22
  76. package/build/runtime-cjs/cache/gc.js +9 -0
  77. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  78. package/build/runtime-cjs/cache/lists.js +9 -6
  79. package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
  80. package/build/runtime-cjs/cache/staleManager.js +95 -0
  81. package/build/runtime-cjs/cache/storage.d.ts +23 -20
  82. package/build/runtime-cjs/cache/storage.js +11 -13
  83. package/build/runtime-cjs/cache/stuff.d.ts +0 -2
  84. package/build/runtime-cjs/cache/stuff.js +2 -19
  85. package/build/runtime-cjs/cache/subscription.d.ts +2 -1
  86. package/build/runtime-cjs/cache/subscription.js +11 -7
  87. package/build/runtime-cjs/client/documentStore.d.ts +20 -17
  88. package/build/runtime-cjs/client/documentStore.js +12 -8
  89. package/build/runtime-cjs/client/index.d.ts +13 -11
  90. package/build/runtime-cjs/client/index.js +48 -19
  91. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  92. package/build/runtime-cjs/client/plugins/cache.js +10 -8
  93. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
  94. package/build/runtime-cjs/client/plugins/fetch.js +9 -8
  95. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +2 -2
  96. package/build/runtime-cjs/client/plugins/fetchParams.js +9 -4
  97. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
  98. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
  99. package/build/runtime-cjs/client/plugins/mutation.js +3 -3
  100. package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
  101. package/build/runtime-cjs/client/plugins/query.js +4 -4
  102. package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
  103. package/build/runtime-cjs/client/plugins/subscription.js +5 -3
  104. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
  105. package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
  106. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -3
  107. package/build/runtime-cjs/generated.d.ts +1 -0
  108. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  109. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  110. package/build/runtime-cjs/index.d.ts +1 -1
  111. package/build/runtime-cjs/lib/config.d.ts +27 -24
  112. package/build/runtime-cjs/lib/config.js +11 -1
  113. package/build/runtime-cjs/lib/flatten.d.ts +2 -0
  114. package/build/runtime-cjs/lib/flatten.js +41 -0
  115. package/build/runtime-cjs/lib/index.d.ts +1 -0
  116. package/build/runtime-cjs/lib/index.js +1 -0
  117. package/build/runtime-cjs/lib/key.d.ts +6 -0
  118. package/build/runtime-cjs/lib/key.js +41 -0
  119. package/build/runtime-cjs/lib/scalars.d.ts +3 -3
  120. package/build/runtime-cjs/lib/scalars.js +13 -2
  121. package/build/runtime-cjs/lib/types.d.ts +46 -46
  122. package/build/runtime-cjs/lib/types.js +26 -30
  123. package/build/runtime-cjs/public/cache.d.ts +26 -6
  124. package/build/runtime-cjs/public/cache.js +32 -32
  125. package/build/runtime-cjs/public/list.js +6 -28
  126. package/build/runtime-cjs/public/record.d.ts +26 -17
  127. package/build/runtime-cjs/public/record.js +27 -187
  128. package/build/runtime-cjs/public/tests/test.d.ts +52 -10
  129. package/build/runtime-cjs/public/tests/test.js +27 -2
  130. package/build/runtime-cjs/public/types.d.ts +8 -0
  131. package/build/runtime-esm/cache/cache.d.ts +28 -11
  132. package/build/runtime-esm/cache/cache.js +99 -24
  133. package/build/runtime-esm/cache/gc.js +9 -0
  134. package/build/runtime-esm/cache/lists.d.ts +1 -0
  135. package/build/runtime-esm/cache/lists.js +9 -6
  136. package/build/runtime-esm/cache/staleManager.d.ts +30 -0
  137. package/build/runtime-esm/cache/staleManager.js +71 -0
  138. package/build/runtime-esm/cache/storage.d.ts +23 -20
  139. package/build/runtime-esm/cache/storage.js +11 -13
  140. package/build/runtime-esm/cache/stuff.d.ts +0 -2
  141. package/build/runtime-esm/cache/stuff.js +1 -17
  142. package/build/runtime-esm/cache/subscription.d.ts +2 -1
  143. package/build/runtime-esm/cache/subscription.js +12 -8
  144. package/build/runtime-esm/client/documentStore.d.ts +20 -17
  145. package/build/runtime-esm/client/documentStore.js +13 -9
  146. package/build/runtime-esm/client/index.d.ts +13 -11
  147. package/build/runtime-esm/client/index.js +49 -21
  148. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  149. package/build/runtime-esm/client/plugins/cache.js +9 -7
  150. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
  151. package/build/runtime-esm/client/plugins/fetch.js +8 -7
  152. package/build/runtime-esm/client/plugins/fetchParams.d.ts +2 -2
  153. package/build/runtime-esm/client/plugins/fetchParams.js +8 -3
  154. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
  155. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
  156. package/build/runtime-esm/client/plugins/mutation.js +2 -2
  157. package/build/runtime-esm/client/plugins/query.d.ts +1 -1
  158. package/build/runtime-esm/client/plugins/query.js +3 -3
  159. package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
  160. package/build/runtime-esm/client/plugins/subscription.js +4 -2
  161. package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
  162. package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
  163. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -3
  164. package/build/runtime-esm/generated.d.ts +1 -0
  165. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  166. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  167. package/build/runtime-esm/index.d.ts +1 -1
  168. package/build/runtime-esm/lib/config.d.ts +27 -24
  169. package/build/runtime-esm/lib/config.js +11 -1
  170. package/build/runtime-esm/lib/flatten.d.ts +2 -0
  171. package/build/runtime-esm/lib/flatten.js +17 -0
  172. package/build/runtime-esm/lib/index.d.ts +1 -0
  173. package/build/runtime-esm/lib/index.js +1 -0
  174. package/build/runtime-esm/lib/key.d.ts +6 -0
  175. package/build/runtime-esm/lib/key.js +17 -0
  176. package/build/runtime-esm/lib/scalars.d.ts +3 -3
  177. package/build/runtime-esm/lib/scalars.js +13 -2
  178. package/build/runtime-esm/lib/types.d.ts +46 -46
  179. package/build/runtime-esm/lib/types.js +26 -30
  180. package/build/runtime-esm/public/cache.d.ts +26 -6
  181. package/build/runtime-esm/public/cache.js +31 -30
  182. package/build/runtime-esm/public/list.js +6 -28
  183. package/build/runtime-esm/public/record.d.ts +26 -17
  184. package/build/runtime-esm/public/record.js +26 -183
  185. package/build/runtime-esm/public/tests/test.d.ts +52 -10
  186. package/build/runtime-esm/public/tests/test.js +26 -1
  187. package/build/runtime-esm/public/types.d.ts +8 -0
  188. package/build/test/index.d.ts +3 -3
  189. package/build/test-cjs/index.js +5007 -2465
  190. package/build/test-esm/index.js +4995 -2453
  191. package/build/vite/houdini.d.ts +2 -0
  192. package/build/vite-cjs/index.js +5344 -2744
  193. package/build/vite-esm/index.js +5319 -2719
  194. package/package.json +6 -5
  195. package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
@@ -7,7 +7,7 @@ export declare class InMemoryStorage {
7
7
  get layerCount(): number;
8
8
  get nextRank(): number;
9
9
  createLayer(optimistic?: boolean): Layer;
10
- insert(id: string, field: string, location: OperationLocation, target: string): void;
10
+ insert(id: string, field: string, location: OperationLocations, target: string): void;
11
11
  remove(id: string, field: string, target: string): void;
12
12
  delete(id: string): void;
13
13
  deleteField(id: string, field: string): void;
@@ -21,7 +21,7 @@ export declare class InMemoryStorage {
21
21
  kind: 'link' | 'scalar' | 'unknown';
22
22
  displayLayers: number[];
23
23
  };
24
- writeLink(id: string, field: string, value: string | LinkedList): number;
24
+ writeLink(id: string, field: string, value: string | NestedList): number;
25
25
  writeField(id: string, field: string, value: GraphQLValue): number;
26
26
  resolveLayer(id: number): void;
27
27
  get topLayer(): Layer;
@@ -37,7 +37,7 @@ export declare class Layer {
37
37
  get(id: string, field: string): [GraphQLField, 'link' | 'scalar'];
38
38
  getOperations(id: string, field: string): Operation[] | undefined;
39
39
  writeField(id: string, field: string, value: GraphQLField): LayerID;
40
- writeLink(id: string, field: string, value: null | string | LinkedList): LayerID;
40
+ writeLink(id: string, field: string, value: null | string | NestedList): LayerID;
41
41
  isDisplayLayer(displayLayers: number[]): boolean;
42
42
  clear(): void;
43
43
  replaceID({ from, to }: {
@@ -47,19 +47,19 @@ export declare class Layer {
47
47
  removeUndefinedFields(): void;
48
48
  delete(id: string): void;
49
49
  deleteField(id: string, field: string): void;
50
- insert(id: string, field: string, where: OperationLocation, target: string): void;
50
+ insert(id: string, field: string, where: OperationLocations, target: string): void;
51
51
  remove(id: string, field: string, target: string): void;
52
52
  writeLayer(layer: Layer): void;
53
53
  private addFieldOperation;
54
54
  }
55
- type GraphQLField = GraphQLValue | LinkedList;
55
+ type GraphQLField = GraphQLValue | NestedList;
56
56
  type EntityMap<_Value> = {
57
57
  [id: string]: {
58
58
  [field: string]: _Value;
59
59
  };
60
60
  };
61
61
  type EntityFieldMap = EntityMap<GraphQLField>;
62
- type LinkMap = EntityMap<string | null | LinkedList>;
62
+ type LinkMap = EntityMap<string | null | NestedList>;
63
63
  type OperationMap = {
64
64
  [id: string]: {
65
65
  deleted?: boolean;
@@ -69,30 +69,33 @@ type OperationMap = {
69
69
  };
70
70
  };
71
71
  };
72
- type LinkedList<_Result = string> = (_Result | null | LinkedList<_Result>)[];
72
+ type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
73
73
  type InsertOperation = {
74
- kind: OperationKind.insert;
75
- location: OperationLocation;
74
+ kind: 'insert';
75
+ location: OperationLocations;
76
76
  id: string;
77
77
  };
78
78
  type RemoveOperation = {
79
- kind: OperationKind.remove;
79
+ kind: 'remove';
80
80
  id: string;
81
81
  };
82
82
  type DeleteOperation = {
83
- kind: OperationKind.delete;
83
+ kind: 'delete';
84
84
  target: string;
85
85
  };
86
86
  type ListOperation = InsertOperation | RemoveOperation;
87
87
  type Operation = ListOperation | DeleteOperation;
88
- export declare enum OperationLocation {
89
- start = "start",
90
- end = "end"
91
- }
92
- export declare enum OperationKind {
93
- delete = "delete",
94
- insert = "insert",
95
- remove = "remove"
96
- }
88
+ type ValuesOf<Target> = Target[keyof Target];
89
+ export declare const OperationLocation: {
90
+ readonly start: "start";
91
+ readonly end: "end";
92
+ };
93
+ export type OperationLocations = ValuesOf<typeof OperationLocation>;
94
+ export declare const OperationKind: {
95
+ readonly delete: "delete";
96
+ readonly insert: "insert";
97
+ readonly remove: "remove";
98
+ };
99
+ export type OperationKinds = ValuesOf<typeof OperationKind>;
97
100
  export type LayerID = number;
98
101
  export {};
@@ -1,4 +1,4 @@
1
- import { flattenList } from "./stuff";
1
+ import { flatten } from "../lib/flatten";
2
2
  class InMemoryStorage {
3
3
  data;
4
4
  idCount = 0;
@@ -198,7 +198,7 @@ class Layer {
198
198
  }
199
199
  writeLink(id, field, value) {
200
200
  const valueList = Array.isArray(value) ? value : [value];
201
- for (const value2 of flattenList(valueList)) {
201
+ for (const value2 of flatten(valueList)) {
202
202
  if (!value2) {
203
203
  continue;
204
204
  }
@@ -350,17 +350,15 @@ function isInsertOperation(value) {
350
350
  function isRemoveOperation(value) {
351
351
  return !!value && value.kind === OperationKind.remove;
352
352
  }
353
- var OperationLocation = /* @__PURE__ */ ((OperationLocation2) => {
354
- OperationLocation2["start"] = "start";
355
- OperationLocation2["end"] = "end";
356
- return OperationLocation2;
357
- })(OperationLocation || {});
358
- var OperationKind = /* @__PURE__ */ ((OperationKind2) => {
359
- OperationKind2["delete"] = "delete";
360
- OperationKind2["insert"] = "insert";
361
- OperationKind2["remove"] = "remove";
362
- return OperationKind2;
363
- })(OperationKind || {});
353
+ const OperationLocation = {
354
+ start: "start",
355
+ end: "end"
356
+ };
357
+ const OperationKind = {
358
+ delete: "delete",
359
+ insert: "insert",
360
+ remove: "remove"
361
+ };
364
362
  export {
365
363
  InMemoryStorage,
366
364
  Layer,
@@ -1,6 +1,4 @@
1
1
  import type { GraphQLValue } from '../lib/types';
2
- import type { LinkedList } from './cache';
3
- export declare function flattenList<T>(source: LinkedList<T>): T[];
4
2
  export declare function evaluateKey(key: string, variables?: {
5
3
  [key: string]: GraphQLValue;
6
4
  }): string;
@@ -1,18 +1,3 @@
1
- function flattenList(source) {
2
- const flat = [];
3
- const unvisited = [source || []];
4
- while (unvisited.length > 0) {
5
- const target = unvisited.shift();
6
- for (const id of target) {
7
- if (Array.isArray(id)) {
8
- unvisited.push(id);
9
- continue;
10
- }
11
- flat.push(id);
12
- }
13
- }
14
- return flat;
15
- }
16
1
  function evaluateKey(key, variables = {}) {
17
2
  let evaluated = "";
18
3
  let varName = "";
@@ -40,6 +25,5 @@ function evaluateKey(key, variables = {}) {
40
25
  }
41
26
  const varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
42
27
  export {
43
- evaluateKey,
44
- flattenList
28
+ evaluateKey
45
29
  };
@@ -19,10 +19,11 @@ export declare class InMemorySubscriptions {
19
19
  [key: string]: GraphQLValue;
20
20
  };
21
21
  }): void;
22
- addFieldSubscription({ id, key, selection, }: {
22
+ addFieldSubscription({ id, key, selection, type, }: {
23
23
  id: string;
24
24
  key: string;
25
25
  selection: FieldSelection;
26
+ type: string;
26
27
  }): void;
27
28
  registerList({ list, id, key, parentType, selection, filters, variables, }: {
28
29
  list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
@@ -1,5 +1,6 @@
1
+ import { flatten } from "../lib/flatten";
1
2
  import { getFieldsForType } from "../lib/selection";
2
- import { evaluateKey, flattenList } from "./stuff";
3
+ import { evaluateKey } from "./stuff";
3
4
  class InMemorySubscriptions {
4
5
  cache;
5
6
  constructor(cache) {
@@ -28,7 +29,8 @@ class InMemorySubscriptions {
28
29
  this.addFieldSubscription({
29
30
  id: parent,
30
31
  key,
31
- selection: [spec, targetSelection2]
32
+ selection: [spec, targetSelection2],
33
+ type
32
34
  });
33
35
  if (list) {
34
36
  this.registerList({
@@ -46,7 +48,7 @@ class InMemorySubscriptions {
46
48
  parent,
47
49
  key
48
50
  );
49
- let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flattenList(linkedRecord) || [];
51
+ let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
50
52
  for (const child of children) {
51
53
  if (!child) {
52
54
  continue;
@@ -65,7 +67,8 @@ class InMemorySubscriptions {
65
67
  addFieldSubscription({
66
68
  id,
67
69
  key,
68
- selection
70
+ selection,
71
+ type
69
72
  }) {
70
73
  const spec = selection[0];
71
74
  if (!this.subscribers[id]) {
@@ -137,7 +140,8 @@ class InMemorySubscriptions {
137
140
  this.addFieldSubscription({
138
141
  id: parent,
139
142
  key,
140
- selection: [spec, fieldSelection]
143
+ selection: [spec, fieldSelection],
144
+ type: linkedType
141
145
  });
142
146
  if (list) {
143
147
  this.registerList({
@@ -153,7 +157,7 @@ class InMemorySubscriptions {
153
157
  const childSelection = selection.selection;
154
158
  if (childSelection) {
155
159
  const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
156
- const children = !Array.isArray(link) ? [link] : flattenList(link);
160
+ const children = !Array.isArray(link) ? [link] : flatten(link);
157
161
  for (const linkedRecord of children) {
158
162
  if (!linkedRecord) {
159
163
  continue;
@@ -189,7 +193,7 @@ class InMemorySubscriptions {
189
193
  continue;
190
194
  }
191
195
  const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
192
- const links = !Array.isArray(previousValue) ? [previousValue] : flattenList(previousValue);
196
+ const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
193
197
  for (const link of links) {
194
198
  if (link !== null) {
195
199
  linkedIDs.push([link, fieldSelection.selection || {}]);
@@ -229,7 +233,7 @@ class InMemorySubscriptions {
229
233
  if (kind === "scalar") {
230
234
  continue;
231
235
  }
232
- const nextTargets = Array.isArray(value) ? flattenList(value) : [value];
236
+ const nextTargets = Array.isArray(value) ? flatten(value) : [value];
233
237
  for (const id2 of nextTargets) {
234
238
  if (visited.includes(id2)) {
235
239
  continue;
@@ -2,31 +2,23 @@ import type { HoudiniClient } from '.';
2
2
  import type { Layer } from '../cache/storage';
3
3
  import type { ConfigFile } from '../lib/config';
4
4
  import { Writable } from '../lib/store';
5
- import type { CachePolicy, DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec } from '../lib/types';
5
+ import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies } from '../lib/types';
6
6
  export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> extends Writable<QueryResult<_Data, _Input>> {
7
7
  #private;
8
8
  constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
9
9
  artifact: DocumentArtifact;
10
- plugins?: ClientPlugin[];
11
- pipeline?: ClientPlugin[];
12
- client: HoudiniClient;
10
+ plugins?: ClientHooks[];
11
+ pipeline?: ClientHooks[];
12
+ client: HoudiniClient | null;
13
13
  cache?: boolean;
14
14
  initialValue?: _Data | null;
15
15
  fetching?: boolean;
16
16
  });
17
- send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, }?: {
18
- fetch?: Fetch;
19
- variables?: Record<string, any> | null;
20
- metadata?: App.Metadata | null;
21
- session?: App.Session | null;
22
- policy?: CachePolicy;
23
- stuff?: Partial<App.Stuff>;
24
- cacheParams?: ClientPluginContext['cacheParams'];
25
- setup?: boolean;
26
- }): Promise<QueryResult<_Data, _Input>>;
17
+ send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
27
18
  }
28
19
  declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
29
- export type ClientPlugin = () => {
20
+ export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
21
+ export type ClientHooks = {
30
22
  start?: ClientPluginEnterPhase;
31
23
  beforeNetwork?: ClientPluginEnterPhase;
32
24
  network?: ClientPluginEnterPhase;
@@ -41,7 +33,7 @@ export type ClientPluginContext = {
41
33
  text: string;
42
34
  hash: string;
43
35
  artifact: DocumentArtifact;
44
- policy?: CachePolicy;
36
+ policy?: CachePolicies;
45
37
  fetch?: Fetch;
46
38
  variables?: Record<string, any>;
47
39
  metadata?: App.Metadata | null;
@@ -53,7 +45,7 @@ export type ClientPluginContext = {
53
45
  forceNotify?: boolean;
54
46
  disableWrite?: boolean;
55
47
  disableRead?: boolean;
56
- applyUpdates?: boolean;
48
+ applyUpdates?: string[];
57
49
  };
58
50
  stuff: App.Stuff;
59
51
  };
@@ -84,4 +76,15 @@ export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'
84
76
  export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
85
77
  error: unknown;
86
78
  };
79
+ export type SendParams = {
80
+ fetch?: Fetch;
81
+ variables?: Record<string, any> | null;
82
+ metadata?: App.Metadata | null;
83
+ session?: App.Session | null;
84
+ policy?: CachePolicies;
85
+ stuff?: Partial<App.Stuff>;
86
+ cacheParams?: ClientPluginContext['cacheParams'];
87
+ setup?: boolean;
88
+ silenceEcho?: boolean;
89
+ };
87
90
  export {};
@@ -3,7 +3,7 @@ import { deepEquals } from "../lib/deepEquals";
3
3
  import { marshalInputs, unmarshalSelection } from "../lib/scalars";
4
4
  import { Writable } from "../lib/store";
5
5
  import { ArtifactKind } from "../lib/types";
6
- import { cachePolicyPlugin } from "./plugins";
6
+ import { cachePolicy } from "./plugins";
7
7
  const steps = {
8
8
  forward: ["start", "beforeNetwork", "network"],
9
9
  backwards: ["end", "afterNetwork"]
@@ -24,13 +24,12 @@ class DocumentStore extends Writable {
24
24
  initialValue,
25
25
  fetching
26
26
  }) {
27
- if (fetching === void 0) {
28
- fetching = artifact.kind === ArtifactKind.Query;
29
- }
27
+ fetching ??= artifact.kind === ArtifactKind.Query;
30
28
  const initialState = {
31
29
  data: initialValue ?? null,
32
30
  errors: null,
33
31
  partial: false,
32
+ stale: false,
34
33
  source: null,
35
34
  fetching,
36
35
  variables: null
@@ -47,13 +46,13 @@ class DocumentStore extends Writable {
47
46
  this.#client = client;
48
47
  this.#lastVariables = null;
49
48
  this.#configFile = getCurrentConfig();
50
- this.#plugins = (pipeline ?? [
51
- cachePolicyPlugin({
49
+ this.#plugins = pipeline ?? [
50
+ cachePolicy({
52
51
  enabled: cache,
53
52
  setFetching: (fetching2) => this.update((state) => ({ ...state, fetching: fetching2 }))
54
- }),
53
+ })(),
55
54
  ...plugins ?? []
56
- ]).map((factory) => factory());
55
+ ];
57
56
  }
58
57
  async send({
59
58
  metadata,
@@ -63,7 +62,8 @@ class DocumentStore extends Writable {
63
62
  policy,
64
63
  stuff,
65
64
  cacheParams,
66
- setup = false
65
+ setup = false,
66
+ silenceEcho = false
67
67
  } = {}) {
68
68
  let context = new ClientPluginContextWrapper({
69
69
  config: this.#configFile,
@@ -94,6 +94,7 @@ class DocumentStore extends Writable {
94
94
  setup,
95
95
  currentStep: 0,
96
96
  index: 0,
97
+ silenceEcho,
97
98
  promise: {
98
99
  resolved: false,
99
100
  resolve,
@@ -231,6 +232,9 @@ class DocumentStore extends Writable {
231
232
  }
232
233
  this.#lastContext = ctx.context.draft();
233
234
  this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
235
+ if (ctx.silenceEcho && finalValue.data === this.state.data) {
236
+ return;
237
+ }
234
238
  this.set(finalValue);
235
239
  }
236
240
  }
@@ -1,25 +1,27 @@
1
1
  /// <reference path="../../../../../houdini.d.ts" />
2
- import type { DocumentArtifact, GraphQLObject } from '../lib/types';
3
- import type { ClientPlugin } from './documentStore';
2
+ import type { DocumentArtifact, GraphQLObject, NestedList } from '../lib/types';
3
+ import type { ClientPlugin, ClientHooks } from './documentStore';
4
4
  import { DocumentStore } from './documentStore';
5
5
  import { type FetchParamFn, type ThrowOnErrorParams } from './plugins';
6
6
  export { DocumentStore, type ClientPlugin } from './documentStore';
7
- export { fetchPlugin, mutationPlugin, queryPlugin, subscriptionPlugin } from './plugins';
7
+ export { fetch, mutation, query, subscription } from './plugins';
8
8
  type ConstructorArgs = {
9
9
  url: string;
10
10
  fetchParams?: FetchParamFn;
11
- plugins?: ClientPlugin[];
12
- pipeline?: ClientPlugin[];
11
+ plugins?: NestedList<ClientPlugin>;
12
+ pipeline?: NestedList<ClientPlugin>;
13
13
  throwOnError?: ThrowOnErrorParams;
14
14
  };
15
+ export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact> = {
16
+ artifact: _Artifact;
17
+ cache?: boolean;
18
+ initialValue?: _Data | null;
19
+ fetching?: boolean;
20
+ };
15
21
  export declare class HoudiniClient {
16
22
  #private;
17
23
  url: string;
18
24
  constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
19
- observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: {
20
- artifact: DocumentArtifact;
21
- cache?: boolean;
22
- initialValue?: _Data | null;
23
- fetching?: boolean;
24
- }): DocumentStore<_Data, _Input>;
25
+ observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
25
26
  }
27
+ export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
@@ -1,14 +1,15 @@
1
+ import { flatten } from "../lib/flatten";
1
2
  import { DocumentStore } from "./documentStore";
2
3
  import {
3
- fetchParamsPlugin,
4
- fetchPlugin,
5
- mutationPlugin,
6
- queryPlugin,
7
- throwOnErrorPlugin
4
+ fetch as fetchPlugin,
5
+ mutation as mutationPlugin,
6
+ query as queryPlugin,
7
+ throwOnError as throwOnErrorPlugin,
8
+ fetchParams as fetchParamsPlugin
8
9
  } from "./plugins";
9
10
  import pluginsFromPlugins from "./plugins/injectedPlugins";
10
11
  import { DocumentStore as DocumentStore2 } from "./documentStore";
11
- import { fetchPlugin as fetchPlugin2, mutationPlugin as mutationPlugin2, queryPlugin as queryPlugin2, subscriptionPlugin } from "./plugins";
12
+ import { fetch, mutation, query, subscription } from "./plugins";
12
13
  class HoudiniClient {
13
14
  url;
14
15
  #plugins;
@@ -18,16 +19,18 @@ class HoudiniClient {
18
19
  "A client cannot be given a pipeline and a list of plugins at the same time."
19
20
  );
20
21
  }
21
- this.#plugins = [].concat(
22
- throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
23
- fetchParamsPlugin(fetchParams),
24
- pipeline ?? [
25
- queryPlugin,
26
- mutationPlugin
27
- ].concat(
28
- plugins ?? [],
29
- pluginsFromPlugins,
30
- fetchPlugin()
22
+ this.#plugins = flatten(
23
+ [].concat(
24
+ throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
25
+ fetchParamsPlugin(fetchParams),
26
+ pipeline ?? [
27
+ queryPlugin,
28
+ mutationPlugin
29
+ ].concat(
30
+ plugins ?? [],
31
+ pluginsFromPlugins,
32
+ fetchPlugin()
33
+ )
31
34
  )
32
35
  );
33
36
  this.url = url;
@@ -41,18 +44,43 @@ class HoudiniClient {
41
44
  return new DocumentStore({
42
45
  client: this,
43
46
  artifact,
44
- plugins: this.#plugins,
47
+ plugins: createPluginHooks(this.#plugins),
45
48
  cache,
46
49
  initialValue,
47
50
  fetching
48
51
  });
49
52
  }
50
53
  }
54
+ function createPluginHooks(plugins) {
55
+ return plugins.reduce((hooks, plugin) => {
56
+ if (typeof plugin !== "function") {
57
+ throw new Error("Encountered client plugin that's not a function");
58
+ }
59
+ const result = plugin();
60
+ if (!result) {
61
+ return hooks;
62
+ }
63
+ if (!Array.isArray(result)) {
64
+ return hooks.concat(result);
65
+ }
66
+ for (const value of result) {
67
+ if (!value) {
68
+ continue;
69
+ }
70
+ if (typeof value === "function") {
71
+ return hooks.concat(createPluginHooks([value]));
72
+ }
73
+ hooks.push(value);
74
+ }
75
+ return hooks;
76
+ }, []);
77
+ }
51
78
  export {
52
79
  DocumentStore2 as DocumentStore,
53
80
  HoudiniClient,
54
- fetchPlugin2 as fetchPlugin,
55
- mutationPlugin2 as mutationPlugin,
56
- queryPlugin2 as queryPlugin,
57
- subscriptionPlugin
81
+ createPluginHooks,
82
+ fetch,
83
+ mutation,
84
+ query,
85
+ subscription
58
86
  };
@@ -1,7 +1,7 @@
1
1
  import cache from '../../cache';
2
2
  import type { Cache } from '../../cache/cache';
3
3
  import type { ClientPlugin } from '../documentStore';
4
- export declare const cachePolicyPlugin: ({ enabled, setFetching, cache: localCache, }: {
4
+ export declare const cachePolicy: ({ enabled, setFetching, cache: localCache, }: {
5
5
  enabled: boolean;
6
6
  setFetching: (val: boolean) => void;
7
7
  cache?: Cache | undefined;
@@ -1,12 +1,12 @@
1
1
  import cache from "../../cache";
2
2
  import { ArtifactKind, CachePolicy, DataSource } from "../../lib/types";
3
- const cachePolicyPlugin = ({
3
+ const cachePolicy = ({
4
4
  enabled,
5
5
  setFetching,
6
6
  cache: localCache = cache
7
7
  }) => () => {
8
8
  return {
9
- network(ctx, { next, resolve, marshalVariables }) {
9
+ network(ctx, { initialValue, next, resolve, marshalVariables }) {
10
10
  const { policy, artifact } = ctx;
11
11
  let useCache = false;
12
12
  if (enabled && artifact.kind === ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
@@ -20,10 +20,11 @@ const cachePolicyPlugin = ({
20
20
  return resolve(ctx, {
21
21
  fetching: false,
22
22
  variables: ctx.variables ?? null,
23
- data: value.data,
23
+ data: allowed ? value.data : initialValue.data,
24
24
  errors: null,
25
25
  source: DataSource.Cache,
26
- partial: value.partial
26
+ partial: allowed ? value.partial : false,
27
+ stale: value.stale
27
28
  });
28
29
  }
29
30
  useCache = !!(value.data !== null && allowed);
@@ -34,10 +35,11 @@ const cachePolicyPlugin = ({
34
35
  data: value.data,
35
36
  errors: null,
36
37
  source: DataSource.Cache,
37
- partial: value.partial
38
+ partial: value.partial,
39
+ stale: value.stale
38
40
  });
39
41
  }
40
- if (useCache && !value.partial) {
42
+ if (useCache && !value.partial && !value.stale) {
41
43
  return;
42
44
  }
43
45
  }
@@ -65,5 +67,5 @@ const cachePolicyPlugin = ({
65
67
  };
66
68
  };
67
69
  export {
68
- cachePolicyPlugin
70
+ cachePolicy
69
71
  };
@@ -1,6 +1,6 @@
1
1
  import type { RequestPayload } from '../../lib/types';
2
2
  import type { ClientPlugin } from '../documentStore';
3
- export declare const fetchPlugin: (target?: RequestHandler | string) => ClientPlugin;
3
+ export declare const fetch: (target?: RequestHandler | string) => ClientPlugin;
4
4
  export type FetchContext = {
5
5
  fetch: typeof globalThis.fetch;
6
6
  metadata?: App.Metadata | null;
@@ -1,9 +1,9 @@
1
1
  import { DataSource } from "../../lib/types";
2
- const fetchPlugin = (target) => {
2
+ const fetch = (target) => {
3
3
  return () => {
4
4
  return {
5
5
  async network(ctx, { client, resolve, marshalVariables }) {
6
- const fetch = ctx.fetch ?? globalThis.fetch;
6
+ const fetch2 = ctx.fetch ?? globalThis.fetch;
7
7
  const fetchParams = {
8
8
  text: ctx.text,
9
9
  hash: ctx.hash,
@@ -20,7 +20,7 @@ const fetchPlugin = (target) => {
20
20
  const result = await fetchFn({
21
21
  fetch: (url, args) => {
22
22
  const newArgs = handleMultipart(fetchParams, args) ?? args;
23
- return fetch(url, newArgs);
23
+ return fetch2(url, newArgs);
24
24
  },
25
25
  metadata: ctx.metadata,
26
26
  session: ctx.session || {},
@@ -32,6 +32,7 @@ const fetchPlugin = (target) => {
32
32
  data: result.data,
33
33
  errors: !result.errors || result.errors.length === 0 ? null : result.errors,
34
34
  partial: false,
35
+ stale: false,
35
36
  source: DataSource.Network
36
37
  });
37
38
  }
@@ -41,11 +42,11 @@ const fetchPlugin = (target) => {
41
42
  const defaultFetch = (url, params) => {
42
43
  if (!url) {
43
44
  throw new Error(
44
- "Could not find configured client url. Please specify one in your houdini.config.js file."
45
+ "Could not find configured client url. Please specify one in your HoudiniClient constructor."
45
46
  );
46
47
  }
47
- return async ({ fetch, text, variables }) => {
48
- const result = await fetch(url, {
48
+ return async ({ fetch: fetch2, text, variables }) => {
49
+ const result = await fetch2(url, {
49
50
  method: "POST",
50
51
  body: JSON.stringify({ query: text, variables }),
51
52
  ...params,
@@ -146,6 +147,6 @@ function isPlainObject(value) {
146
147
  }
147
148
  export {
148
149
  extractFiles,
149
- fetchPlugin,
150
+ fetch,
150
151
  isExtractableFile
151
152
  };