houdini-svelte 2.1.9 → 2.1.10
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 +4 -4
- package/build/plugin-esm/index.js +4 -4
- package/build/preprocess-cjs/index.js +4 -4
- package/build/preprocess-esm/index.js +4 -4
- 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/fragments.d.ts +1 -1
- package/build/runtime-cjs/stores/fragment.d.ts +58 -2
- package/build/runtime-cjs/stores/fragment.js +180 -2
- package/build/runtime-cjs/stores/index.d.ts +2 -3
- package/build/runtime-cjs/stores/index.js +8 -2
- package/build/runtime-cjs/stores/query.d.ts +27 -1
- package/build/runtime-cjs/stores/query.js +118 -0
- package/build/runtime-esm/fragments.d.ts +1 -1
- package/build/runtime-esm/stores/fragment.d.ts +58 -2
- package/build/runtime-esm/stores/fragment.js +179 -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/query.d.ts +27 -1
- package/build/runtime-esm/stores/query.js +118 -2
- package/build/test-cjs/index.js +4 -4
- package/build/test-esm/index.js +4 -4
- 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
|
@@ -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");
|
|
@@ -190,8 +194,122 @@ 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
|
+
const paginationObserver = (0, import_client.getClient)().observe({
|
|
208
|
+
artifact: this.artifact
|
|
209
|
+
});
|
|
210
|
+
this.#_handlers = (0, import_pagination.cursorHandlers)({
|
|
211
|
+
artifact: this.artifact,
|
|
212
|
+
getState: () => (0, import_store.get)(this.observer).data,
|
|
213
|
+
getVariables: () => (0, import_store.get)(this.observer).variables,
|
|
214
|
+
fetch: super.fetch.bind(this),
|
|
215
|
+
getSession: import_session.getSession,
|
|
216
|
+
fetchUpdate: async (args, updates) => {
|
|
217
|
+
return paginationObserver.send({
|
|
218
|
+
...args,
|
|
219
|
+
cacheParams: {
|
|
220
|
+
applyUpdates: updates,
|
|
221
|
+
disableSubscriptions: true,
|
|
222
|
+
...args?.cacheParams
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return this.#_handlers;
|
|
228
|
+
}
|
|
229
|
+
async fetch(args) {
|
|
230
|
+
const handlers = await this.#handlers();
|
|
231
|
+
return await handlers.fetch.call(this, args);
|
|
232
|
+
}
|
|
233
|
+
async loadPreviousPage(args) {
|
|
234
|
+
const handlers = await this.#handlers();
|
|
235
|
+
try {
|
|
236
|
+
return await handlers.loadPreviousPage(args);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
const err = e;
|
|
239
|
+
if (err.name === "AbortError") {
|
|
240
|
+
return (0, import_store.get)(this.observer);
|
|
241
|
+
} else {
|
|
242
|
+
throw err;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async loadNextPage(args) {
|
|
247
|
+
const handlers = await this.#handlers();
|
|
248
|
+
try {
|
|
249
|
+
return await handlers.loadNextPage(args);
|
|
250
|
+
} catch (e) {
|
|
251
|
+
const err = e;
|
|
252
|
+
if (err.name === "AbortError") {
|
|
253
|
+
return (0, import_store.get)(this.observer);
|
|
254
|
+
} else {
|
|
255
|
+
throw err;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
subscribe(run, invalidate) {
|
|
260
|
+
const combined = (0, import_store.derived)([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
|
|
261
|
+
return {
|
|
262
|
+
...$parent,
|
|
263
|
+
pageInfo: (0, import_pageInfo.extractPageInfo)($parent.data, this.artifact.refetch.path)
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
return combined.subscribe(run, invalidate);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
class QueryStoreOffset extends QueryStore {
|
|
270
|
+
paginated = true;
|
|
271
|
+
async loadNextPage(args) {
|
|
272
|
+
const handlers = await this.#handlers();
|
|
273
|
+
return await handlers.loadNextPage.call(this, args);
|
|
274
|
+
}
|
|
275
|
+
async fetch(args) {
|
|
276
|
+
const handlers = await this.#handlers();
|
|
277
|
+
return await handlers.fetch.call(this, args);
|
|
278
|
+
}
|
|
279
|
+
#_handlers = null;
|
|
280
|
+
async #handlers() {
|
|
281
|
+
if (this.#_handlers) {
|
|
282
|
+
return this.#_handlers;
|
|
283
|
+
}
|
|
284
|
+
const paginationObserver = (0, import_client.getClient)().observe({
|
|
285
|
+
artifact: this.artifact
|
|
286
|
+
});
|
|
287
|
+
this.#_handlers = (0, import_pagination.offsetHandlers)({
|
|
288
|
+
artifact: this.artifact,
|
|
289
|
+
storeName: this.name,
|
|
290
|
+
fetch: super.fetch.bind(this),
|
|
291
|
+
getState: () => (0, import_store.get)(this.observer).data,
|
|
292
|
+
getVariables: () => (0, import_store.get)(this.observer).variables,
|
|
293
|
+
getSession: import_session.getSession,
|
|
294
|
+
fetchUpdate: async (args) => {
|
|
295
|
+
return paginationObserver.send({
|
|
296
|
+
...args,
|
|
297
|
+
variables: {
|
|
298
|
+
...args?.variables
|
|
299
|
+
},
|
|
300
|
+
cacheParams: {
|
|
301
|
+
applyUpdates: ["append"]
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
return this.#_handlers;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
193
309
|
// Annotate the CommonJS export names for ESM import in node:
|
|
194
310
|
0 && (module.exports = {
|
|
195
311
|
QueryStore,
|
|
312
|
+
QueryStoreCursor,
|
|
313
|
+
QueryStoreOffset,
|
|
196
314
|
fetchParams
|
|
197
315
|
});
|
|
@@ -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,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 } from "../client";
|
|
11
|
+
import { getSession } from "../session";
|
|
7
12
|
import { BaseStore } from "./base";
|
|
8
13
|
class FragmentStore {
|
|
9
14
|
artifact;
|
|
@@ -52,6 +57,177 @@ 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
|
+
return observer.send({
|
|
135
|
+
session: await getSession(),
|
|
136
|
+
...args,
|
|
137
|
+
variables: {
|
|
138
|
+
...args?.variables,
|
|
139
|
+
...this.queryVariables(getState)
|
|
140
|
+
},
|
|
141
|
+
cacheParams: {
|
|
142
|
+
applyUpdates: updates,
|
|
143
|
+
disableSubscriptions: true
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
fetch: async (args) => {
|
|
148
|
+
return await observer.send({
|
|
149
|
+
session: await getSession(),
|
|
150
|
+
...args,
|
|
151
|
+
variables: {
|
|
152
|
+
...args?.variables,
|
|
153
|
+
...this.queryVariables(getState)
|
|
154
|
+
},
|
|
155
|
+
cacheParams: {
|
|
156
|
+
disableSubscriptions: true
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
getSession
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
class FragmentStoreOffset extends BasePaginatedFragmentStore {
|
|
165
|
+
get(initialValue) {
|
|
166
|
+
const base = new FragmentStore({
|
|
167
|
+
artifact: this.artifact,
|
|
168
|
+
storeName: this.name
|
|
169
|
+
});
|
|
170
|
+
const store = base.get(initialValue);
|
|
171
|
+
const paginationStore = getClient().observe({
|
|
172
|
+
artifact: this.paginationArtifact,
|
|
173
|
+
initialValue: store.initialValue
|
|
174
|
+
});
|
|
175
|
+
const getState = () => get(store);
|
|
176
|
+
const handlers = offsetHandlers({
|
|
177
|
+
getState,
|
|
178
|
+
getVariables: () => store.variables,
|
|
179
|
+
artifact: this.paginationArtifact,
|
|
180
|
+
fetch: async (args) => {
|
|
181
|
+
return paginationStore.send({
|
|
182
|
+
...args,
|
|
183
|
+
session: await getSession(),
|
|
184
|
+
variables: {
|
|
185
|
+
...this.queryVariables(getState),
|
|
186
|
+
...args?.variables
|
|
187
|
+
},
|
|
188
|
+
cacheParams: {
|
|
189
|
+
disableSubscriptions: true
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
fetchUpdate: async (args) => {
|
|
194
|
+
return paginationStore.send({
|
|
195
|
+
session: await getSession(),
|
|
196
|
+
...args,
|
|
197
|
+
variables: {
|
|
198
|
+
...this.queryVariables(getState),
|
|
199
|
+
...args?.variables
|
|
200
|
+
},
|
|
201
|
+
cacheParams: {
|
|
202
|
+
disableSubscriptions: true,
|
|
203
|
+
applyUpdates: ["append"]
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
getSession,
|
|
208
|
+
storeName: this.name
|
|
209
|
+
});
|
|
210
|
+
const subscribe = (run, invalidate) => {
|
|
211
|
+
const combined = derived([store, paginationStore], ([$parent, $pagination]) => {
|
|
212
|
+
return {
|
|
213
|
+
...$pagination,
|
|
214
|
+
data: $parent
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
return combined.subscribe(run, invalidate);
|
|
218
|
+
};
|
|
219
|
+
return {
|
|
220
|
+
kind: CompiledFragmentKind,
|
|
221
|
+
data: derived(paginationStore, ($value) => $value.data),
|
|
222
|
+
subscribe,
|
|
223
|
+
fetch: handlers.fetch,
|
|
224
|
+
loadNextPage: handlers.loadNextPage,
|
|
225
|
+
fetching: derived(paginationStore, ($store) => $store.fetching)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
55
229
|
export {
|
|
56
|
-
FragmentStore
|
|
230
|
+
FragmentStore,
|
|
231
|
+
FragmentStoreCursor,
|
|
232
|
+
FragmentStoreOffset
|
|
57
233
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { FragmentStore } from './fragment';
|
|
1
|
+
export { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from './fragment';
|
|
3
2
|
export { SubscriptionStore } from './subscription';
|
|
4
3
|
export { MutationStore, type MutationConfig } from './mutation';
|
|
5
|
-
export { QueryStore } from './query';
|
|
4
|
+
export { QueryStore, QueryStoreCursor, QueryStoreOffset } from './query';
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { FragmentStore } from "./fragment";
|
|
1
|
+
import { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from "./fragment";
|
|
3
2
|
import { SubscriptionStore } from "./subscription";
|
|
4
3
|
import { MutationStore } from "./mutation";
|
|
5
|
-
import { QueryStore } from "./query";
|
|
4
|
+
import { QueryStore, QueryStoreCursor, QueryStoreOffset } 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,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
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getCurrentConfig } from "$houdini/runtime/lib/config";
|
|
2
2
|
import * as log from "$houdini/runtime/lib/log";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
|
|
4
|
+
import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
|
|
5
|
+
import { CompiledQueryKind, CachePolicy, ArtifactKind } from "$houdini/runtime/lib/types";
|
|
6
|
+
import { get, derived } from "svelte/store";
|
|
5
7
|
import { clientStarted, isBrowser } from "../adapter";
|
|
6
8
|
import { getClient } from "../client";
|
|
7
9
|
import { getSession } from "../session";
|
|
@@ -160,7 +162,121 @@ export async function load(${log.yellow("event")}: LoadEvent) {
|
|
|
160
162
|
// in a server-side mutation:
|
|
161
163
|
await mutation.mutate({ ... }, ${log.yellow("{ event }")})
|
|
162
164
|
`;
|
|
165
|
+
class QueryStoreCursor extends QueryStore {
|
|
166
|
+
paginated = true;
|
|
167
|
+
constructor(config) {
|
|
168
|
+
super(config);
|
|
169
|
+
}
|
|
170
|
+
#_handlers = null;
|
|
171
|
+
async #handlers() {
|
|
172
|
+
if (this.#_handlers) {
|
|
173
|
+
return this.#_handlers;
|
|
174
|
+
}
|
|
175
|
+
const paginationObserver = getClient().observe({
|
|
176
|
+
artifact: this.artifact
|
|
177
|
+
});
|
|
178
|
+
this.#_handlers = cursorHandlers({
|
|
179
|
+
artifact: this.artifact,
|
|
180
|
+
getState: () => get(this.observer).data,
|
|
181
|
+
getVariables: () => get(this.observer).variables,
|
|
182
|
+
fetch: super.fetch.bind(this),
|
|
183
|
+
getSession,
|
|
184
|
+
fetchUpdate: async (args, updates) => {
|
|
185
|
+
return paginationObserver.send({
|
|
186
|
+
...args,
|
|
187
|
+
cacheParams: {
|
|
188
|
+
applyUpdates: updates,
|
|
189
|
+
disableSubscriptions: true,
|
|
190
|
+
...args?.cacheParams
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return this.#_handlers;
|
|
196
|
+
}
|
|
197
|
+
async fetch(args) {
|
|
198
|
+
const handlers = await this.#handlers();
|
|
199
|
+
return await handlers.fetch.call(this, args);
|
|
200
|
+
}
|
|
201
|
+
async loadPreviousPage(args) {
|
|
202
|
+
const handlers = await this.#handlers();
|
|
203
|
+
try {
|
|
204
|
+
return await handlers.loadPreviousPage(args);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
const err = e;
|
|
207
|
+
if (err.name === "AbortError") {
|
|
208
|
+
return get(this.observer);
|
|
209
|
+
} else {
|
|
210
|
+
throw err;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
async loadNextPage(args) {
|
|
215
|
+
const handlers = await this.#handlers();
|
|
216
|
+
try {
|
|
217
|
+
return await handlers.loadNextPage(args);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
const err = e;
|
|
220
|
+
if (err.name === "AbortError") {
|
|
221
|
+
return get(this.observer);
|
|
222
|
+
} else {
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
subscribe(run, invalidate) {
|
|
228
|
+
const combined = derived([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
|
|
229
|
+
return {
|
|
230
|
+
...$parent,
|
|
231
|
+
pageInfo: extractPageInfo($parent.data, this.artifact.refetch.path)
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
return combined.subscribe(run, invalidate);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
class QueryStoreOffset extends QueryStore {
|
|
238
|
+
paginated = true;
|
|
239
|
+
async loadNextPage(args) {
|
|
240
|
+
const handlers = await this.#handlers();
|
|
241
|
+
return await handlers.loadNextPage.call(this, args);
|
|
242
|
+
}
|
|
243
|
+
async fetch(args) {
|
|
244
|
+
const handlers = await this.#handlers();
|
|
245
|
+
return await handlers.fetch.call(this, args);
|
|
246
|
+
}
|
|
247
|
+
#_handlers = null;
|
|
248
|
+
async #handlers() {
|
|
249
|
+
if (this.#_handlers) {
|
|
250
|
+
return this.#_handlers;
|
|
251
|
+
}
|
|
252
|
+
const paginationObserver = getClient().observe({
|
|
253
|
+
artifact: this.artifact
|
|
254
|
+
});
|
|
255
|
+
this.#_handlers = offsetHandlers({
|
|
256
|
+
artifact: this.artifact,
|
|
257
|
+
storeName: this.name,
|
|
258
|
+
fetch: super.fetch.bind(this),
|
|
259
|
+
getState: () => get(this.observer).data,
|
|
260
|
+
getVariables: () => get(this.observer).variables,
|
|
261
|
+
getSession,
|
|
262
|
+
fetchUpdate: async (args) => {
|
|
263
|
+
return paginationObserver.send({
|
|
264
|
+
...args,
|
|
265
|
+
variables: {
|
|
266
|
+
...args?.variables
|
|
267
|
+
},
|
|
268
|
+
cacheParams: {
|
|
269
|
+
applyUpdates: ["append"]
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
return this.#_handlers;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
163
277
|
export {
|
|
164
278
|
QueryStore,
|
|
279
|
+
QueryStoreCursor,
|
|
280
|
+
QueryStoreOffset,
|
|
165
281
|
fetchParams
|
|
166
282
|
};
|
package/build/test-cjs/index.js
CHANGED
|
@@ -212509,10 +212509,10 @@ function plugin_config(config) {
|
|
|
212509
212509
|
mutation: "../runtime/stores/mutation.MutationStore",
|
|
212510
212510
|
fragment: "../runtime/stores/fragment.FragmentStore",
|
|
212511
212511
|
subscription: "../runtime/stores/subscription.SubscriptionStore",
|
|
212512
|
-
queryCursor: "../runtime/stores/
|
|
212513
|
-
queryOffset: "../runtime/stores/
|
|
212514
|
-
fragmentCursor: "../runtime/stores/
|
|
212515
|
-
fragmentOffset: "../runtime/stores/
|
|
212512
|
+
queryCursor: "../runtime/stores/query.QueryStoreCursor",
|
|
212513
|
+
queryOffset: "../runtime/stores/query.QueryStoreOffset",
|
|
212514
|
+
fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
|
|
212515
|
+
fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
|
|
212516
212516
|
...cfg?.customStores
|
|
212517
212517
|
}
|
|
212518
212518
|
};
|
package/build/test-esm/index.js
CHANGED
|
@@ -212499,10 +212499,10 @@ function plugin_config(config) {
|
|
|
212499
212499
|
mutation: "../runtime/stores/mutation.MutationStore",
|
|
212500
212500
|
fragment: "../runtime/stores/fragment.FragmentStore",
|
|
212501
212501
|
subscription: "../runtime/stores/subscription.SubscriptionStore",
|
|
212502
|
-
queryCursor: "../runtime/stores/
|
|
212503
|
-
queryOffset: "../runtime/stores/
|
|
212504
|
-
fragmentCursor: "../runtime/stores/
|
|
212505
|
-
fragmentOffset: "../runtime/stores/
|
|
212502
|
+
queryCursor: "../runtime/stores/query.QueryStoreCursor",
|
|
212503
|
+
queryOffset: "../runtime/stores/query.QueryStoreOffset",
|
|
212504
|
+
fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
|
|
212505
|
+
fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
|
|
212506
212506
|
...cfg?.customStores
|
|
212507
212507
|
}
|
|
212508
212508
|
};
|