houdini-svelte 2.1.9 → 2.1.11
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/plugin-cjs/index.js +7 -5
- package/build/plugin-esm/index.js +7 -5
- package/build/preprocess-cjs/index.js +4 -4
- package/build/preprocess-esm/index.js +4 -4
- package/build/runtime/client.d.ts +1 -0
- package/build/runtime/fragments.d.ts +1 -1
- package/build/runtime/stores/fragment.d.ts +58 -2
- package/build/runtime/stores/index.d.ts +2 -3
- package/build/runtime/stores/query.d.ts +27 -1
- package/build/runtime-cjs/client.d.ts +1 -0
- package/build/runtime-cjs/client.js +22 -5
- package/build/runtime-cjs/fragments.d.ts +1 -1
- package/build/runtime-cjs/stores/base.js +5 -0
- package/build/runtime-cjs/stores/fragment.d.ts +58 -2
- package/build/runtime-cjs/stores/fragment.js +184 -2
- package/build/runtime-cjs/stores/index.d.ts +2 -3
- package/build/runtime-cjs/stores/index.js +9 -3
- package/build/runtime-cjs/stores/mutation.js +2 -0
- package/build/runtime-cjs/stores/query.d.ts +27 -1
- package/build/runtime-cjs/stores/query.js +123 -1
- package/build/runtime-cjs/stores/subscription.js +3 -0
- package/build/runtime-esm/client.d.ts +1 -0
- package/build/runtime-esm/client.js +18 -2
- package/build/runtime-esm/fragments.d.ts +1 -1
- package/build/runtime-esm/stores/base.js +6 -1
- package/build/runtime-esm/stores/fragment.d.ts +58 -2
- package/build/runtime-esm/stores/fragment.js +183 -3
- package/build/runtime-esm/stores/index.d.ts +2 -3
- package/build/runtime-esm/stores/index.js +6 -3
- package/build/runtime-esm/stores/mutation.js +2 -0
- package/build/runtime-esm/stores/query.d.ts +27 -1
- package/build/runtime-esm/stores/query.js +124 -4
- package/build/runtime-esm/stores/subscription.js +3 -0
- package/build/test-cjs/index.js +7 -5
- package/build/test-esm/index.js +7 -5
- package/package.json +1 -1
- package/build/runtime/stores/pagination/fragment.d.ts +0 -58
- package/build/runtime/stores/pagination/index.d.ts +0 -2
- package/build/runtime/stores/pagination/query.d.ts +0 -30
- package/build/runtime-cjs/stores/pagination/fragment.d.ts +0 -58
- package/build/runtime-cjs/stores/pagination/fragment.js +0 -207
- package/build/runtime-cjs/stores/pagination/index.d.ts +0 -2
- package/build/runtime-cjs/stores/pagination/index.js +0 -35
- package/build/runtime-cjs/stores/pagination/query.d.ts +0 -30
- package/build/runtime-cjs/stores/pagination/query.js +0 -147
- package/build/runtime-esm/stores/pagination/fragment.d.ts +0 -58
- package/build/runtime-esm/stores/pagination/fragment.js +0 -182
- package/build/runtime-esm/stores/pagination/index.d.ts +0 -2
- package/build/runtime-esm/stores/pagination/index.js +0 -8
- package/build/runtime-esm/stores/pagination/query.d.ts +0 -30
- package/build/runtime-esm/stores/pagination/query.js +0 -122
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
1
2
|
import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
|
|
2
|
-
import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
3
|
+
import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo } from '$houdini/runtime/lib/types';
|
|
4
|
+
import type { Subscriber } from 'svelte/store';
|
|
3
5
|
import type { PluginArtifactData } from '../../plugin/artifactData';
|
|
4
6
|
import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../types';
|
|
5
7
|
import { BaseStore } from './base';
|
|
@@ -31,3 +33,27 @@ export declare function fetchParams<_Data extends GraphQLObject, _Input>(artifac
|
|
|
31
33
|
policy: CachePolicies | undefined;
|
|
32
34
|
params: QueryStoreFetchParams<_Data, _Input>;
|
|
33
35
|
}>;
|
|
36
|
+
export type CursorStoreResult<_Data extends GraphQLObject, _Input extends GraphQLVariables> = QueryResult<_Data, _Input> & {
|
|
37
|
+
pageInfo: PageInfo;
|
|
38
|
+
};
|
|
39
|
+
export declare class QueryStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
|
|
40
|
+
#private;
|
|
41
|
+
paginated: boolean;
|
|
42
|
+
constructor(config: StoreConfig<_Data, _Input, QueryArtifact>);
|
|
43
|
+
fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
44
|
+
fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
45
|
+
fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
46
|
+
fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
47
|
+
loadPreviousPage(args?: Parameters<Required<CursorHandlers<_Data, _Input>>['loadPreviousPage']>[0]): Promise<QueryResult<_Data, _Input>>;
|
|
48
|
+
loadNextPage(args?: Parameters<CursorHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<QueryResult<_Data, _Input>>;
|
|
49
|
+
subscribe(run: Subscriber<CursorStoreResult<_Data, _Input>>, invalidate?: ((value?: CursorStoreResult<_Data, _Input> | undefined) => void) | undefined): () => void;
|
|
50
|
+
}
|
|
51
|
+
export declare class QueryStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
|
|
52
|
+
#private;
|
|
53
|
+
paginated: boolean;
|
|
54
|
+
loadNextPage(args?: Parameters<OffsetHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<void>;
|
|
55
|
+
fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
56
|
+
fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
57
|
+
fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
58
|
+
fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
59
|
+
}
|
|
@@ -25,11 +25,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var query_exports = {};
|
|
26
26
|
__export(query_exports, {
|
|
27
27
|
QueryStore: () => QueryStore,
|
|
28
|
+
QueryStoreCursor: () => QueryStoreCursor,
|
|
29
|
+
QueryStoreOffset: () => QueryStoreOffset,
|
|
28
30
|
fetchParams: () => fetchParams
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(query_exports);
|
|
31
33
|
var import_config = require("$houdini/runtime/lib/config");
|
|
32
34
|
var log = __toESM(require("$houdini/runtime/lib/log"), 1);
|
|
35
|
+
var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
|
|
36
|
+
var import_pagination = require("$houdini/runtime/lib/pagination");
|
|
33
37
|
var import_types = require("$houdini/runtime/lib/types");
|
|
34
38
|
var import_store = require("svelte/store");
|
|
35
39
|
var import_adapter = require("../adapter");
|
|
@@ -52,7 +56,7 @@ class QueryStore extends import_base.BaseStore {
|
|
|
52
56
|
this.variables = variables;
|
|
53
57
|
}
|
|
54
58
|
async fetch(args) {
|
|
55
|
-
const client = (0, import_client.
|
|
59
|
+
const client = await (0, import_client.initClient)();
|
|
56
60
|
this.setup(false);
|
|
57
61
|
const { policy, params, context } = await fetchParams(this.artifact, this.storeName, args);
|
|
58
62
|
if (!import_adapter.isBrowser && !(params && "fetch" in params) && (!params || !("event" in params))) {
|
|
@@ -190,8 +194,126 @@ export async function load(${log.yellow("event")}: LoadEvent) {
|
|
|
190
194
|
// in a server-side mutation:
|
|
191
195
|
await mutation.mutate({ ... }, ${log.yellow("{ event }")})
|
|
192
196
|
`;
|
|
197
|
+
class QueryStoreCursor extends QueryStore {
|
|
198
|
+
paginated = true;
|
|
199
|
+
constructor(config) {
|
|
200
|
+
super(config);
|
|
201
|
+
}
|
|
202
|
+
#_handlers = null;
|
|
203
|
+
async #handlers() {
|
|
204
|
+
if (this.#_handlers) {
|
|
205
|
+
return this.#_handlers;
|
|
206
|
+
}
|
|
207
|
+
await (0, import_client.initClient)();
|
|
208
|
+
const paginationObserver = (0, import_client.getClient)().observe({
|
|
209
|
+
artifact: this.artifact
|
|
210
|
+
});
|
|
211
|
+
this.#_handlers = (0, import_pagination.cursorHandlers)({
|
|
212
|
+
artifact: this.artifact,
|
|
213
|
+
getState: () => (0, import_store.get)(this.observer).data,
|
|
214
|
+
getVariables: () => (0, import_store.get)(this.observer).variables,
|
|
215
|
+
fetch: super.fetch.bind(this),
|
|
216
|
+
getSession: import_session.getSession,
|
|
217
|
+
fetchUpdate: async (args, updates) => {
|
|
218
|
+
await (0, import_client.initClient)();
|
|
219
|
+
return paginationObserver.send({
|
|
220
|
+
...args,
|
|
221
|
+
cacheParams: {
|
|
222
|
+
applyUpdates: updates,
|
|
223
|
+
disableSubscriptions: true,
|
|
224
|
+
...args?.cacheParams
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return this.#_handlers;
|
|
230
|
+
}
|
|
231
|
+
async fetch(args) {
|
|
232
|
+
const handlers = await this.#handlers();
|
|
233
|
+
return await handlers.fetch.call(this, args);
|
|
234
|
+
}
|
|
235
|
+
async loadPreviousPage(args) {
|
|
236
|
+
const handlers = await this.#handlers();
|
|
237
|
+
try {
|
|
238
|
+
return await handlers.loadPreviousPage(args);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
const err = e;
|
|
241
|
+
if (err.name === "AbortError") {
|
|
242
|
+
return (0, import_store.get)(this.observer);
|
|
243
|
+
} else {
|
|
244
|
+
throw err;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async loadNextPage(args) {
|
|
249
|
+
const handlers = await this.#handlers();
|
|
250
|
+
try {
|
|
251
|
+
return await handlers.loadNextPage(args);
|
|
252
|
+
} catch (e) {
|
|
253
|
+
const err = e;
|
|
254
|
+
if (err.name === "AbortError") {
|
|
255
|
+
return (0, import_store.get)(this.observer);
|
|
256
|
+
} else {
|
|
257
|
+
throw err;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
subscribe(run, invalidate) {
|
|
262
|
+
const combined = (0, import_store.derived)([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
|
|
263
|
+
return {
|
|
264
|
+
...$parent,
|
|
265
|
+
pageInfo: (0, import_pageInfo.extractPageInfo)($parent.data, this.artifact.refetch.path)
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
return combined.subscribe(run, invalidate);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
class QueryStoreOffset extends QueryStore {
|
|
272
|
+
paginated = true;
|
|
273
|
+
async loadNextPage(args) {
|
|
274
|
+
const handlers = await this.#handlers();
|
|
275
|
+
return await handlers.loadNextPage.call(this, args);
|
|
276
|
+
}
|
|
277
|
+
async fetch(args) {
|
|
278
|
+
const handlers = await this.#handlers();
|
|
279
|
+
return await handlers.fetch.call(this, args);
|
|
280
|
+
}
|
|
281
|
+
#_handlers = null;
|
|
282
|
+
async #handlers() {
|
|
283
|
+
if (this.#_handlers) {
|
|
284
|
+
return this.#_handlers;
|
|
285
|
+
}
|
|
286
|
+
await (0, import_client.initClient)();
|
|
287
|
+
const paginationObserver = (0, import_client.getClient)().observe({
|
|
288
|
+
artifact: this.artifact
|
|
289
|
+
});
|
|
290
|
+
this.#_handlers = (0, import_pagination.offsetHandlers)({
|
|
291
|
+
artifact: this.artifact,
|
|
292
|
+
storeName: this.name,
|
|
293
|
+
fetch: super.fetch.bind(this),
|
|
294
|
+
getState: () => (0, import_store.get)(this.observer).data,
|
|
295
|
+
getVariables: () => (0, import_store.get)(this.observer).variables,
|
|
296
|
+
getSession: import_session.getSession,
|
|
297
|
+
fetchUpdate: async (args) => {
|
|
298
|
+
await (0, import_client.initClient)();
|
|
299
|
+
return paginationObserver.send({
|
|
300
|
+
...args,
|
|
301
|
+
variables: {
|
|
302
|
+
...args?.variables
|
|
303
|
+
},
|
|
304
|
+
cacheParams: {
|
|
305
|
+
applyUpdates: ["append"]
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
return this.#_handlers;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
193
313
|
// Annotate the CommonJS export names for ESM import in node:
|
|
194
314
|
0 && (module.exports = {
|
|
195
315
|
QueryStore,
|
|
316
|
+
QueryStoreCursor,
|
|
317
|
+
QueryStoreOffset,
|
|
196
318
|
fetchParams
|
|
197
319
|
});
|
|
@@ -23,6 +23,7 @@ __export(subscription_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(subscription_exports);
|
|
24
24
|
var import_types = require("$houdini/runtime/lib/types");
|
|
25
25
|
var import_store = require("svelte/store");
|
|
26
|
+
var import_client = require("../client");
|
|
26
27
|
var import_session = require("../session");
|
|
27
28
|
var import_base = require("./base");
|
|
28
29
|
class SubscriptionStore extends import_base.BaseStore {
|
|
@@ -33,6 +34,7 @@ class SubscriptionStore extends import_base.BaseStore {
|
|
|
33
34
|
this.fetchingStore = (0, import_store.writable)(false);
|
|
34
35
|
}
|
|
35
36
|
async listen(variables, args) {
|
|
37
|
+
await (0, import_client.initClient)();
|
|
36
38
|
this.fetchingStore.set(true);
|
|
37
39
|
this.observer.send({
|
|
38
40
|
variables,
|
|
@@ -41,6 +43,7 @@ class SubscriptionStore extends import_base.BaseStore {
|
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
async unlisten() {
|
|
46
|
+
await (0, import_client.initClient)();
|
|
44
47
|
this.fetchingStore.set(false);
|
|
45
48
|
await this.observer.cleanup();
|
|
46
49
|
}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
let client = null;
|
|
2
|
+
async function initClient() {
|
|
3
|
+
if (client) {
|
|
4
|
+
return client;
|
|
5
|
+
}
|
|
6
|
+
client = (await import("HOUDINI_CLIENT_PATH")).default;
|
|
7
|
+
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
|
8
|
+
for (let retry = 0; retry < 10; retry++) {
|
|
9
|
+
if (client) {
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
await delay(100);
|
|
13
|
+
client = (await import("HOUDINI_CLIENT_PATH")).default;
|
|
14
|
+
}
|
|
15
|
+
return client;
|
|
16
|
+
}
|
|
2
17
|
function getClient() {
|
|
3
18
|
if (!client) {
|
|
4
19
|
throw new Error("client hasn't been initialized");
|
|
@@ -6,5 +21,6 @@ function getClient() {
|
|
|
6
21
|
return client;
|
|
7
22
|
}
|
|
8
23
|
export {
|
|
9
|
-
getClient
|
|
24
|
+
getClient,
|
|
25
|
+
initClient
|
|
10
26
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { Fragment, FragmentArtifact } from '$houdini/runtime/lib/types';
|
|
3
3
|
import type { Readable } from 'svelte/store';
|
|
4
4
|
import type { FragmentStore } from './stores';
|
|
5
|
-
import type { FragmentStorePaginated } from './stores/
|
|
5
|
+
import type { FragmentStorePaginated } from './stores/fragment';
|
|
6
6
|
export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment, fragment: FragmentStore<_Fragment['shape'], {}>): Readable<Exclude<_Fragment['shape'], undefined>> & {
|
|
7
7
|
data: Readable<_Fragment>;
|
|
8
8
|
artifact: FragmentArtifact;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DocumentStore } from "$houdini/runtime/client";
|
|
2
2
|
import { get } from "svelte/store";
|
|
3
3
|
import { isBrowser } from "../adapter";
|
|
4
|
-
import { getClient } from "../client";
|
|
4
|
+
import { getClient, initClient } from "../client";
|
|
5
5
|
class BaseStore {
|
|
6
6
|
#params;
|
|
7
7
|
get artifact() {
|
|
@@ -50,6 +50,11 @@ class BaseStore {
|
|
|
50
50
|
#subscriberCount = 0;
|
|
51
51
|
setup(init = true) {
|
|
52
52
|
let initPromise = Promise.resolve();
|
|
53
|
+
try {
|
|
54
|
+
getClient();
|
|
55
|
+
} catch {
|
|
56
|
+
initPromise = initClient();
|
|
57
|
+
}
|
|
53
58
|
initPromise.then(() => {
|
|
54
59
|
if (this.#unsubscribe) {
|
|
55
60
|
return;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import type { DocumentStore } from '$houdini/runtime/client';
|
|
3
|
+
import type { GraphQLObject, FragmentArtifact, HoudiniFetchContext, GraphQLVariables, QueryArtifact, PageInfo, CursorHandlers } from '$houdini/runtime/lib/types';
|
|
2
4
|
import { fragmentKey } from '$houdini/runtime/lib/types';
|
|
3
|
-
import type {
|
|
5
|
+
import type { Readable, Subscriber } from 'svelte/store';
|
|
6
|
+
import type { FragmentStoreInstance, OffsetFragmentStoreInstance } from '../types';
|
|
7
|
+
import type { StoreConfig } from './query';
|
|
4
8
|
export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType extends {}, _Input extends GraphQLVariables = GraphQLVariables> {
|
|
5
9
|
artifact: FragmentArtifact;
|
|
6
10
|
name: string;
|
|
@@ -16,3 +20,55 @@ export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType e
|
|
|
16
20
|
initialValue: _Data | null;
|
|
17
21
|
};
|
|
18
22
|
}
|
|
23
|
+
type FragmentStoreConfig<_Data extends GraphQLObject, _Input> = StoreConfig<_Data, _Input, FragmentArtifact> & {
|
|
24
|
+
paginationArtifact: QueryArtifact;
|
|
25
|
+
};
|
|
26
|
+
declare class BasePaginatedFragmentStore<_Data extends GraphQLObject, _Input> {
|
|
27
|
+
paginated: boolean;
|
|
28
|
+
protected paginationArtifact: QueryArtifact;
|
|
29
|
+
name: string;
|
|
30
|
+
kind: "HoudiniFragment";
|
|
31
|
+
artifact: FragmentArtifact;
|
|
32
|
+
constructor(config: FragmentStoreConfig<_Data, _Input>);
|
|
33
|
+
protected queryVariables(getState: () => _Data | null): _Input;
|
|
34
|
+
}
|
|
35
|
+
export declare class FragmentStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
|
|
36
|
+
get(initialValue: _Data | null): {
|
|
37
|
+
kind: "HoudiniFragment";
|
|
38
|
+
subscribe: (run: Subscriber<FragmentPaginatedResult<_Data, {
|
|
39
|
+
pageInfo: PageInfo;
|
|
40
|
+
}>>, invalidate?: ((value?: FragmentPaginatedResult<_Data, {
|
|
41
|
+
pageInfo: PageInfo;
|
|
42
|
+
}> | undefined) => void) | undefined) => (() => void);
|
|
43
|
+
fetch: (args?: import("$houdini/runtime/lib/types").FetchParams<_Input> | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
|
|
44
|
+
loadNextPage: (args?: {
|
|
45
|
+
first?: number | undefined;
|
|
46
|
+
after?: string | undefined;
|
|
47
|
+
fetch?: typeof fetch | undefined;
|
|
48
|
+
metadata?: {} | undefined;
|
|
49
|
+
} | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
|
|
50
|
+
loadPreviousPage: (args?: {
|
|
51
|
+
last?: number | undefined;
|
|
52
|
+
before?: string | undefined;
|
|
53
|
+
fetch?: typeof fetch | undefined;
|
|
54
|
+
metadata?: {} | undefined;
|
|
55
|
+
} | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
|
|
56
|
+
};
|
|
57
|
+
protected storeHandlers(observer: DocumentStore<_Data, _Input>, initialValue: _Data | null, getState: () => _Data | null, getVariables: () => NonNullable<_Input>): CursorHandlers<_Data, _Input>;
|
|
58
|
+
}
|
|
59
|
+
export declare class FragmentStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
|
|
60
|
+
get(initialValue: _Data | null): OffsetFragmentStoreInstance<_Data, _Input>;
|
|
61
|
+
}
|
|
62
|
+
export type FragmentStorePaginated<_Data extends GraphQLObject, _Input> = Readable<{
|
|
63
|
+
data: _Data;
|
|
64
|
+
fetching: boolean;
|
|
65
|
+
pageInfo: PageInfo;
|
|
66
|
+
}> & {
|
|
67
|
+
loadNextPage(pageCount?: number, after?: string | number, houdiniContext?: HoudiniFetchContext): Promise<void>;
|
|
68
|
+
loadPreviousPage(pageCount?: number, before?: string, houdiniContext?: HoudiniFetchContext): Promise<void>;
|
|
69
|
+
};
|
|
70
|
+
export type FragmentPaginatedResult<_Data, _ExtraFields = {}> = {
|
|
71
|
+
data: _Data | null;
|
|
72
|
+
fetching: boolean;
|
|
73
|
+
} & _ExtraFields;
|
|
74
|
+
export {};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import cache from "$houdini/runtime/cache";
|
|
2
|
-
import { getCurrentConfig } from "$houdini/runtime/lib/config";
|
|
2
|
+
import { getCurrentConfig, keyFieldsForType } from "$houdini/runtime/lib/config";
|
|
3
|
+
import { siteURL } from "$houdini/runtime/lib/constants";
|
|
4
|
+
import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
|
|
5
|
+
import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
|
|
3
6
|
import { marshalInputs } from "$houdini/runtime/lib/scalars";
|
|
4
7
|
import { CompiledFragmentKind, fragmentKey } from "$houdini/runtime/lib/types";
|
|
5
|
-
import { derived } from "svelte/store";
|
|
8
|
+
import { get, derived } from "svelte/store";
|
|
6
9
|
import { isBrowser } from "../adapter";
|
|
10
|
+
import { getClient, initClient } from "../client";
|
|
11
|
+
import { getSession } from "../session";
|
|
7
12
|
import { BaseStore } from "./base";
|
|
8
13
|
class FragmentStore {
|
|
9
14
|
artifact;
|
|
@@ -52,6 +57,181 @@ Please ensure that you have passed a record that has ${this.artifact.name} mixed
|
|
|
52
57
|
};
|
|
53
58
|
}
|
|
54
59
|
}
|
|
60
|
+
class BasePaginatedFragmentStore {
|
|
61
|
+
paginated = true;
|
|
62
|
+
paginationArtifact;
|
|
63
|
+
name;
|
|
64
|
+
kind = CompiledFragmentKind;
|
|
65
|
+
artifact;
|
|
66
|
+
constructor(config) {
|
|
67
|
+
this.paginationArtifact = config.paginationArtifact;
|
|
68
|
+
this.name = config.storeName;
|
|
69
|
+
this.artifact = config.artifact;
|
|
70
|
+
}
|
|
71
|
+
queryVariables(getState) {
|
|
72
|
+
const config = getCurrentConfig();
|
|
73
|
+
const { targetType } = this.paginationArtifact.refetch || {};
|
|
74
|
+
const typeConfig = config.types?.[targetType || ""];
|
|
75
|
+
if (!typeConfig) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Missing type refetch configuration for ${targetType}. For more information, see ${siteURL}/guides/pagination#paginated-fragments`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
let idVariables = {};
|
|
81
|
+
const value = getState();
|
|
82
|
+
if (typeConfig.resolve?.arguments) {
|
|
83
|
+
idVariables = typeConfig.resolve.arguments?.(value) || {};
|
|
84
|
+
} else {
|
|
85
|
+
const keys = keyFieldsForType(config, targetType || "");
|
|
86
|
+
idVariables = Object.fromEntries(keys.map((key) => [key, value[key]]));
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
...idVariables
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
class FragmentStoreCursor extends BasePaginatedFragmentStore {
|
|
94
|
+
get(initialValue) {
|
|
95
|
+
const base = new FragmentStore({
|
|
96
|
+
artifact: this.artifact,
|
|
97
|
+
storeName: this.name
|
|
98
|
+
});
|
|
99
|
+
const store = base.get(initialValue);
|
|
100
|
+
const paginationStore = getClient().observe({
|
|
101
|
+
artifact: this.paginationArtifact,
|
|
102
|
+
initialValue: store.initialValue
|
|
103
|
+
});
|
|
104
|
+
const handlers = this.storeHandlers(
|
|
105
|
+
paginationStore,
|
|
106
|
+
initialValue,
|
|
107
|
+
() => get(store),
|
|
108
|
+
() => store.variables
|
|
109
|
+
);
|
|
110
|
+
const subscribe = (run, invalidate) => {
|
|
111
|
+
const combined = derived([store, paginationStore], ([$parent, $pagination]) => {
|
|
112
|
+
return {
|
|
113
|
+
...$pagination,
|
|
114
|
+
data: $parent,
|
|
115
|
+
pageInfo: extractPageInfo($parent, this.paginationArtifact.refetch.path)
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
return combined.subscribe(run, invalidate);
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
kind: CompiledFragmentKind,
|
|
122
|
+
subscribe,
|
|
123
|
+
fetch: handlers.fetch,
|
|
124
|
+
loadNextPage: handlers.loadNextPage,
|
|
125
|
+
loadPreviousPage: handlers.loadPreviousPage
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
storeHandlers(observer, initialValue, getState, getVariables) {
|
|
129
|
+
return cursorHandlers({
|
|
130
|
+
getState,
|
|
131
|
+
getVariables,
|
|
132
|
+
artifact: this.paginationArtifact,
|
|
133
|
+
fetchUpdate: async (args, updates) => {
|
|
134
|
+
await initClient();
|
|
135
|
+
return observer.send({
|
|
136
|
+
session: await getSession(),
|
|
137
|
+
...args,
|
|
138
|
+
variables: {
|
|
139
|
+
...args?.variables,
|
|
140
|
+
...this.queryVariables(getState)
|
|
141
|
+
},
|
|
142
|
+
cacheParams: {
|
|
143
|
+
applyUpdates: updates,
|
|
144
|
+
disableSubscriptions: true
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
fetch: async (args) => {
|
|
149
|
+
await initClient();
|
|
150
|
+
return await observer.send({
|
|
151
|
+
session: await getSession(),
|
|
152
|
+
...args,
|
|
153
|
+
variables: {
|
|
154
|
+
...args?.variables,
|
|
155
|
+
...this.queryVariables(getState)
|
|
156
|
+
},
|
|
157
|
+
cacheParams: {
|
|
158
|
+
disableSubscriptions: true
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
getSession
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
class FragmentStoreOffset extends BasePaginatedFragmentStore {
|
|
167
|
+
get(initialValue) {
|
|
168
|
+
const base = new FragmentStore({
|
|
169
|
+
artifact: this.artifact,
|
|
170
|
+
storeName: this.name
|
|
171
|
+
});
|
|
172
|
+
const store = base.get(initialValue);
|
|
173
|
+
const paginationStore = getClient().observe({
|
|
174
|
+
artifact: this.paginationArtifact,
|
|
175
|
+
initialValue: store.initialValue
|
|
176
|
+
});
|
|
177
|
+
const getState = () => get(store);
|
|
178
|
+
const handlers = offsetHandlers({
|
|
179
|
+
getState,
|
|
180
|
+
getVariables: () => store.variables,
|
|
181
|
+
artifact: this.paginationArtifact,
|
|
182
|
+
fetch: async (args) => {
|
|
183
|
+
await initClient();
|
|
184
|
+
return paginationStore.send({
|
|
185
|
+
...args,
|
|
186
|
+
session: await getSession(),
|
|
187
|
+
variables: {
|
|
188
|
+
...this.queryVariables(getState),
|
|
189
|
+
...args?.variables
|
|
190
|
+
},
|
|
191
|
+
cacheParams: {
|
|
192
|
+
disableSubscriptions: true
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
fetchUpdate: async (args) => {
|
|
197
|
+
await initClient();
|
|
198
|
+
return paginationStore.send({
|
|
199
|
+
session: await getSession(),
|
|
200
|
+
...args,
|
|
201
|
+
variables: {
|
|
202
|
+
...this.queryVariables(getState),
|
|
203
|
+
...args?.variables
|
|
204
|
+
},
|
|
205
|
+
cacheParams: {
|
|
206
|
+
disableSubscriptions: true,
|
|
207
|
+
applyUpdates: ["append"]
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
getSession,
|
|
212
|
+
storeName: this.name
|
|
213
|
+
});
|
|
214
|
+
const subscribe = (run, invalidate) => {
|
|
215
|
+
const combined = derived([store, paginationStore], ([$parent, $pagination]) => {
|
|
216
|
+
return {
|
|
217
|
+
...$pagination,
|
|
218
|
+
data: $parent
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
return combined.subscribe(run, invalidate);
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
kind: CompiledFragmentKind,
|
|
225
|
+
data: derived(paginationStore, ($value) => $value.data),
|
|
226
|
+
subscribe,
|
|
227
|
+
fetch: handlers.fetch,
|
|
228
|
+
loadNextPage: handlers.loadNextPage,
|
|
229
|
+
fetching: derived(paginationStore, ($store) => $store.fetching)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
55
233
|
export {
|
|
56
|
-
FragmentStore
|
|
234
|
+
FragmentStore,
|
|
235
|
+
FragmentStoreCursor,
|
|
236
|
+
FragmentStoreOffset
|
|
57
237
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { FragmentStore } from './fragment';
|
|
1
|
+
export { QueryStore, QueryStoreCursor, QueryStoreOffset } from './query';
|
|
2
|
+
export { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from './fragment';
|
|
3
3
|
export { SubscriptionStore } from './subscription';
|
|
4
4
|
export { MutationStore, type MutationConfig } from './mutation';
|
|
5
|
-
export { QueryStore } from './query';
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { FragmentStore } from "./fragment";
|
|
1
|
+
import { QueryStore, QueryStoreCursor, QueryStoreOffset } from "./query";
|
|
2
|
+
import { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from "./fragment";
|
|
3
3
|
import { SubscriptionStore } from "./subscription";
|
|
4
4
|
import { MutationStore } from "./mutation";
|
|
5
|
-
import { QueryStore } from "./query";
|
|
6
5
|
export {
|
|
7
6
|
FragmentStore,
|
|
7
|
+
FragmentStoreCursor,
|
|
8
|
+
FragmentStoreOffset,
|
|
8
9
|
MutationStore,
|
|
9
10
|
QueryStore,
|
|
11
|
+
QueryStoreCursor,
|
|
12
|
+
QueryStoreOffset,
|
|
10
13
|
SubscriptionStore
|
|
11
14
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { initClient } from "../client";
|
|
1
2
|
import { BaseStore } from "./base";
|
|
2
3
|
import { fetchParams } from "./query";
|
|
3
4
|
class MutationStore extends BaseStore {
|
|
@@ -9,6 +10,7 @@ class MutationStore extends BaseStore {
|
|
|
9
10
|
abortController,
|
|
10
11
|
...mutationConfig
|
|
11
12
|
} = {}) {
|
|
13
|
+
await initClient();
|
|
12
14
|
const { context } = await fetchParams(this.artifact, this.artifact.name, {
|
|
13
15
|
fetch,
|
|
14
16
|
metadata,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
1
2
|
import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
|
|
2
|
-
import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
3
|
+
import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo } from '$houdini/runtime/lib/types';
|
|
4
|
+
import type { Subscriber } from 'svelte/store';
|
|
3
5
|
import type { PluginArtifactData } from '../../plugin/artifactData';
|
|
4
6
|
import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../types';
|
|
5
7
|
import { BaseStore } from './base';
|
|
@@ -31,3 +33,27 @@ export declare function fetchParams<_Data extends GraphQLObject, _Input>(artifac
|
|
|
31
33
|
policy: CachePolicies | undefined;
|
|
32
34
|
params: QueryStoreFetchParams<_Data, _Input>;
|
|
33
35
|
}>;
|
|
36
|
+
export type CursorStoreResult<_Data extends GraphQLObject, _Input extends GraphQLVariables> = QueryResult<_Data, _Input> & {
|
|
37
|
+
pageInfo: PageInfo;
|
|
38
|
+
};
|
|
39
|
+
export declare class QueryStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
|
|
40
|
+
#private;
|
|
41
|
+
paginated: boolean;
|
|
42
|
+
constructor(config: StoreConfig<_Data, _Input, QueryArtifact>);
|
|
43
|
+
fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
44
|
+
fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
45
|
+
fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
46
|
+
fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
47
|
+
loadPreviousPage(args?: Parameters<Required<CursorHandlers<_Data, _Input>>['loadPreviousPage']>[0]): Promise<QueryResult<_Data, _Input>>;
|
|
48
|
+
loadNextPage(args?: Parameters<CursorHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<QueryResult<_Data, _Input>>;
|
|
49
|
+
subscribe(run: Subscriber<CursorStoreResult<_Data, _Input>>, invalidate?: ((value?: CursorStoreResult<_Data, _Input> | undefined) => void) | undefined): () => void;
|
|
50
|
+
}
|
|
51
|
+
export declare class QueryStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
|
|
52
|
+
#private;
|
|
53
|
+
paginated: boolean;
|
|
54
|
+
loadNextPage(args?: Parameters<OffsetHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<void>;
|
|
55
|
+
fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
56
|
+
fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
57
|
+
fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
58
|
+
fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
59
|
+
}
|