houdini 2.0.0-next.32 → 2.0.0-next.33

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.
package/build/cmd/init.js CHANGED
@@ -472,7 +472,7 @@ async function packageJSON(targetPath, frameworkInfo) {
472
472
  }
473
473
  packageJSON2.devDependencies = {
474
474
  ...packageJSON2.devDependencies,
475
- houdini: "^2.0.0-next.32"
475
+ houdini: "^2.0.0-next.33"
476
476
  };
477
477
  if (frameworkInfo.framework === "svelte" || frameworkInfo.framework === "kit") {
478
478
  packageJSON2.devDependencies = {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "2.0.0-next.32",
3
+ "version": "2.0.0-next.33",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "keywords": [
6
6
  "typescript",
@@ -54,9 +54,11 @@ export declare class Cache {
54
54
  hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
55
55
  clearLayer(layerID: Layer['id']): void;
56
56
  reset(): void;
57
+ getEpoch(): number;
57
58
  }
58
59
  declare class CacheInternal {
59
60
  disabled: boolean;
61
+ epoch: number;
60
62
  _config?: ConfigFile;
61
63
  storage: InMemoryStorage;
62
64
  subscriptions: InMemorySubscriptions;
@@ -203,10 +203,16 @@ class Cache {
203
203
  this._internal_unstable.storage.reset();
204
204
  this.#notifySubscribers(subSpecs);
205
205
  }
206
+ // returns the current notification generation; fragment references carry this value
207
+ // so hooks can detect which epoch of data they were rendered with
208
+ getEpoch() {
209
+ return this._internal_unstable.epoch;
210
+ }
206
211
  #notifySubscribers(subs) {
207
212
  if (subs.length === 0) {
208
213
  return;
209
214
  }
215
+ this._internal_unstable.epoch++;
210
216
  const notified = [];
211
217
  for (const spec of subs) {
212
218
  if (!notified.includes(spec.set)) {
@@ -226,6 +232,9 @@ class Cache {
226
232
  class CacheInternal {
227
233
  // for server-side requests we need to be able to flag the cache as disabled so we dont write to it
228
234
  disabled = false;
235
+ // monotonically increasing counter incremented on every cache notification flush;
236
+ // threaded into fragment references so hooks know which generation of data they hold
237
+ epoch = 0;
229
238
  _config;
230
239
  storage;
231
240
  subscriptions;
@@ -149,8 +149,12 @@ class InMemorySubscriptions {
149
149
  keyRaw,
150
150
  selection: innerSelection,
151
151
  list,
152
- filters
152
+ filters,
153
+ visible
153
154
  } = selection;
155
+ if (!visible) {
156
+ continue;
157
+ }
154
158
  const key = evaluateKey(keyRaw, variables);
155
159
  const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType, false) : void 0;
156
160
  this.addFieldSubscription({
@@ -28,7 +28,7 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends G
28
28
  }) => Promise<any>>;
29
29
  config: ConfigFile;
30
30
  });
31
- send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, abortController, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
31
+ send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, initialState, silenceEcho, abortController, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
32
32
  cleanup(): Promise<void>;
33
33
  getFetch(getSession: () => App.Session | null | undefined): (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>;
34
34
  }
@@ -105,6 +105,7 @@ export type SendParams = {
105
105
  stuff?: Partial<App.Stuff>;
106
106
  cacheParams?: ClientPluginContext['cacheParams'];
107
107
  setup?: boolean;
108
+ initialState?: QueryResult;
108
109
  silenceEcho?: boolean;
109
110
  abortController?: AbortController;
110
111
  };
@@ -69,15 +69,17 @@ class DocumentStore extends Writable {
69
69
  stuff,
70
70
  cacheParams,
71
71
  setup = false,
72
+ initialState,
72
73
  silenceEcho = false,
73
74
  abortController = new AbortController()
74
75
  } = {}) {
75
76
  if ("dedupe" in this.artifact && this.artifact.dedupe && this.artifact.dedupe.match !== "None") {
76
77
  const dedupeKey = this.controllerKey(variables);
77
- if (inflightRequests[dedupeKey]) {
78
+ const existingRequest = inflightRequests[dedupeKey];
79
+ if (existingRequest && !existingRequest.controller.signal.aborted) {
78
80
  if (this.artifact.dedupe.cancel === "first") {
79
- inflightRequests[dedupeKey].controller.abort();
80
- inflightRequests[dedupeKey].controller = abortController;
81
+ existingRequest.controller.abort();
82
+ existingRequest.controller = abortController;
81
83
  } else {
82
84
  abortController.abort();
83
85
  }
@@ -117,6 +119,7 @@ class DocumentStore extends Writable {
117
119
  const promise = new Promise((resolve, reject) => {
118
120
  const state = {
119
121
  setup,
122
+ initialState,
120
123
  currentStep: 0,
121
124
  index: 0,
122
125
  silenceEcho,
@@ -135,9 +138,11 @@ class DocumentStore extends Writable {
135
138
  }
136
139
  this.#step("forward", state);
137
140
  });
138
- const response = await promise;
139
- delete inflightRequests[this.controllerKey(variables)];
140
- return response;
141
+ try {
142
+ return await promise;
143
+ } finally {
144
+ delete inflightRequests[this.controllerKey(variables)];
145
+ }
141
146
  }
142
147
  async cleanup() {
143
148
  for (const plugin of this.#plugins) {
@@ -285,7 +290,7 @@ class DocumentStore extends Writable {
285
290
  currentStep: 0,
286
291
  index: this.#plugins.length
287
292
  },
288
- this.state
293
+ ctx.initialState ?? this.state
289
294
  );
290
295
  return;
291
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "2.0.0-next.32",
3
+ "version": "2.0.0-next.33",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "keywords": [
6
6
  "typescript",
@@ -50,7 +50,7 @@
50
50
  "recast": "^0.23.11",
51
51
  "sql.js": "^1.14.1",
52
52
  "ws": "^8.21.0",
53
- "houdini-core": "^2.0.0-next.20"
53
+ "houdini-core": "^2.0.0-next.21"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "graphql": ">=16",