houdini 1.1.7 → 1.2.0-next.1
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/README.md +1 -1
- package/build/cmd-cjs/index.js +1739 -1256
- package/build/cmd-esm/index.js +1739 -1256
- package/build/codegen/generators/artifacts/selection.d.ts +2 -1
- package/build/codegen/generators/typescript/inlineType.d.ts +5 -2
- package/build/codegen/generators/typescript/loadingState.d.ts +8 -0
- package/build/codegen-cjs/index.js +1701 -1241
- package/build/codegen-esm/index.js +1701 -1241
- package/build/lib/config.d.ts +5 -0
- package/build/lib/graphql.d.ts +5 -1
- package/build/lib/parse.d.ts +11 -1
- package/build/lib/types.d.ts +4 -1
- package/build/lib-cjs/index.js +611 -493
- package/build/lib-esm/index.js +608 -493
- package/build/runtime/cache/cache.d.ts +7 -8
- package/build/runtime/cache/stuff.d.ts +1 -4
- package/build/runtime/client/documentStore.d.ts +6 -3
- package/build/runtime/client/index.d.ts +9 -8
- package/build/runtime/client/plugins/cache.d.ts +1 -1
- package/build/runtime/client/plugins/fetch.d.ts +1 -0
- package/build/runtime/client/plugins/subscription.d.ts +1 -0
- package/build/runtime/client/plugins/throwOnError.d.ts +2 -1
- package/build/runtime/lib/pageInfo.d.ts +7 -0
- package/build/runtime/lib/pagination.d.ts +27 -0
- package/build/runtime/lib/selection.d.ts +1 -1
- package/build/runtime/lib/types.d.ts +79 -4
- package/build/runtime-cjs/cache/cache.d.ts +7 -8
- package/build/runtime-cjs/cache/cache.js +78 -36
- package/build/runtime-cjs/cache/stuff.d.ts +1 -4
- package/build/runtime-cjs/cache/stuff.js +2 -2
- package/build/runtime-cjs/cache/subscription.js +5 -5
- package/build/runtime-cjs/client/documentStore.d.ts +6 -3
- package/build/runtime-cjs/client/documentStore.js +20 -7
- package/build/runtime-cjs/client/index.d.ts +9 -8
- package/build/runtime-cjs/client/index.js +12 -4
- package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +12 -2
- package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -0
- package/build/runtime-cjs/client/plugins/fetch.js +3 -2
- package/build/runtime-cjs/client/plugins/fragment.js +8 -1
- package/build/runtime-cjs/client/plugins/query.js +2 -1
- package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -0
- package/build/runtime-cjs/client/plugins/subscription.js +1 -0
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +2 -1
- package/build/runtime-cjs/lib/config.js +2 -1
- package/build/runtime-cjs/lib/pageInfo.d.ts +7 -0
- package/build/runtime-cjs/lib/pageInfo.js +79 -0
- package/build/runtime-cjs/lib/pagination.d.ts +27 -0
- package/build/runtime-cjs/lib/pagination.js +219 -0
- package/build/runtime-cjs/lib/scalars.js +1 -1
- package/build/runtime-cjs/lib/selection.d.ts +1 -1
- package/build/runtime-cjs/lib/selection.js +28 -1
- package/build/runtime-cjs/lib/types.d.ts +79 -4
- package/build/runtime-cjs/lib/types.js +3 -0
- package/build/runtime-esm/cache/cache.d.ts +7 -8
- package/build/runtime-esm/cache/cache.js +79 -37
- package/build/runtime-esm/cache/stuff.d.ts +1 -4
- package/build/runtime-esm/cache/stuff.js +2 -2
- package/build/runtime-esm/cache/subscription.js +5 -5
- package/build/runtime-esm/client/documentStore.d.ts +6 -3
- package/build/runtime-esm/client/documentStore.js +20 -7
- package/build/runtime-esm/client/index.d.ts +9 -8
- package/build/runtime-esm/client/index.js +15 -7
- package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +12 -2
- package/build/runtime-esm/client/plugins/fetch.d.ts +1 -0
- package/build/runtime-esm/client/plugins/fetch.js +3 -2
- package/build/runtime-esm/client/plugins/fragment.js +8 -1
- package/build/runtime-esm/client/plugins/query.js +2 -1
- package/build/runtime-esm/client/plugins/subscription.d.ts +1 -0
- package/build/runtime-esm/client/plugins/subscription.js +1 -0
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +2 -1
- package/build/runtime-esm/lib/config.js +2 -1
- package/build/runtime-esm/lib/pageInfo.d.ts +7 -0
- package/build/runtime-esm/lib/pageInfo.js +52 -0
- package/build/runtime-esm/lib/pagination.d.ts +27 -0
- package/build/runtime-esm/lib/pagination.js +194 -0
- package/build/runtime-esm/lib/scalars.js +1 -1
- package/build/runtime-esm/lib/selection.d.ts +1 -1
- package/build/runtime-esm/lib/selection.js +28 -1
- package/build/runtime-esm/lib/types.d.ts +79 -4
- package/build/runtime-esm/lib/types.js +2 -0
- package/build/test/index.d.ts +15 -0
- package/build/test-cjs/index.js +1706 -1223
- package/build/test-esm/index.js +1706 -1223
- package/build/vite-cjs/index.js +1757 -1274
- package/build/vite-esm/index.js +1757 -1274
- package/package.json +5 -1
|
@@ -21,7 +21,7 @@ __export(stuff_exports, {
|
|
|
21
21
|
evaluateKey: () => evaluateKey
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(stuff_exports);
|
|
24
|
-
function evaluateKey(key, variables =
|
|
24
|
+
function evaluateKey(key, variables = null) {
|
|
25
25
|
let evaluated = "";
|
|
26
26
|
let varName = "";
|
|
27
27
|
let inString = false;
|
|
@@ -31,7 +31,7 @@ function evaluateKey(key, variables = {}) {
|
|
|
31
31
|
varName += char;
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
|
-
const value = variables[varName.slice(1)];
|
|
34
|
+
const value = variables?.[varName.slice(1)];
|
|
35
35
|
evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
|
|
36
36
|
varName = "";
|
|
37
37
|
}
|
|
@@ -40,7 +40,7 @@ class InMemorySubscriptions {
|
|
|
40
40
|
parentType
|
|
41
41
|
}) {
|
|
42
42
|
const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
43
|
-
let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
|
|
43
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename, false);
|
|
44
44
|
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
45
45
|
const {
|
|
46
46
|
keyRaw,
|
|
@@ -57,7 +57,7 @@ class InMemorySubscriptions {
|
|
|
57
57
|
let targetSelection2;
|
|
58
58
|
if (innerSelection) {
|
|
59
59
|
const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
60
|
-
targetSelection2 = (0, import_selection.getFieldsForType)(innerSelection, __typename2);
|
|
60
|
+
targetSelection2 = (0, import_selection.getFieldsForType)(innerSelection, __typename2, false);
|
|
61
61
|
}
|
|
62
62
|
this.addFieldSubscription({
|
|
63
63
|
id: parent,
|
|
@@ -168,7 +168,7 @@ class InMemorySubscriptions {
|
|
|
168
168
|
filters
|
|
169
169
|
} = selection;
|
|
170
170
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
171
|
-
const fieldSelection = innerSelection ? (0, import_selection.getFieldsForType)(innerSelection, parentType) : void 0;
|
|
171
|
+
const fieldSelection = innerSelection ? (0, import_selection.getFieldsForType)(innerSelection, parentType, false) : void 0;
|
|
172
172
|
this.addFieldSubscription({
|
|
173
173
|
id: parent,
|
|
174
174
|
key,
|
|
@@ -198,7 +198,7 @@ class InMemorySubscriptions {
|
|
|
198
198
|
linkedRecord,
|
|
199
199
|
"__typename"
|
|
200
200
|
).value;
|
|
201
|
-
let targetSelection2 = (0, import_selection.getFieldsForType)(childSelection, __typename);
|
|
201
|
+
let targetSelection2 = (0, import_selection.getFieldsForType)(childSelection, __typename, false);
|
|
202
202
|
this.addMany({
|
|
203
203
|
parent: linkedRecord,
|
|
204
204
|
variables,
|
|
@@ -217,7 +217,7 @@ class InMemorySubscriptions {
|
|
|
217
217
|
visited.push(id);
|
|
218
218
|
const linkedIDs = [];
|
|
219
219
|
const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
|
|
220
|
-
let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
|
|
220
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename, false);
|
|
221
221
|
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
222
222
|
const key = (0, import_stuff.evaluateKey)(fieldSelection.keyRaw, variables);
|
|
223
223
|
this.removeSubscribers(id, key, targets);
|
|
@@ -2,9 +2,12 @@ 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 { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies } from '../lib/types';
|
|
6
|
-
export declare class DocumentStore<_Data extends GraphQLObject, _Input extends
|
|
5
|
+
import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies, GraphQLVariables } from '../lib/types';
|
|
6
|
+
export declare class DocumentStore<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends Writable<QueryResult<_Data, _Input>> {
|
|
7
7
|
#private;
|
|
8
|
+
pendingPromise: {
|
|
9
|
+
then: (val: any) => void;
|
|
10
|
+
} | null;
|
|
8
11
|
constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
|
|
9
12
|
artifact: DocumentArtifact;
|
|
10
13
|
plugins?: ClientHooks[];
|
|
@@ -17,7 +20,7 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
|
|
|
17
20
|
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
|
|
18
21
|
cleanup(): Promise<void>;
|
|
19
22
|
}
|
|
20
|
-
declare function marshalVariables<_Data extends GraphQLObject, _Input extends
|
|
23
|
+
declare function marshalVariables<_Data extends GraphQLObject, _Input extends GraphQLVariables>(ctx: ClientPluginContext): Record<string, any>;
|
|
21
24
|
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
22
25
|
export type ClientHooks = {
|
|
23
26
|
start?: ClientPluginEnterPhase;
|
|
@@ -38,6 +38,7 @@ class DocumentStore extends import_store.Writable {
|
|
|
38
38
|
#plugins;
|
|
39
39
|
#lastVariables;
|
|
40
40
|
#lastContext = null;
|
|
41
|
+
pendingPromise = null;
|
|
41
42
|
constructor({
|
|
42
43
|
artifact,
|
|
43
44
|
plugins,
|
|
@@ -70,7 +71,15 @@ class DocumentStore extends import_store.Writable {
|
|
|
70
71
|
this.#plugins = pipeline ?? [
|
|
71
72
|
(0, import_plugins.cachePolicy)({
|
|
72
73
|
enabled: cache,
|
|
73
|
-
setFetching: (fetching2
|
|
74
|
+
setFetching: (fetching2, data) => {
|
|
75
|
+
this.update((state) => {
|
|
76
|
+
const newState = { ...state, fetching: fetching2 };
|
|
77
|
+
if (fetching2 && data) {
|
|
78
|
+
newState.data = data;
|
|
79
|
+
}
|
|
80
|
+
return newState;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
74
83
|
})(),
|
|
75
84
|
...plugins ?? []
|
|
76
85
|
];
|
|
@@ -110,7 +119,7 @@ class DocumentStore extends import_store.Writable {
|
|
|
110
119
|
const draft = context.draft();
|
|
111
120
|
draft.variables = variables ?? null;
|
|
112
121
|
context = context.apply(draft, false);
|
|
113
|
-
|
|
122
|
+
const promise = new Promise((resolve, reject) => {
|
|
114
123
|
const state = {
|
|
115
124
|
setup,
|
|
116
125
|
currentStep: 0,
|
|
@@ -119,12 +128,17 @@ class DocumentStore extends import_store.Writable {
|
|
|
119
128
|
promise: {
|
|
120
129
|
resolved: false,
|
|
121
130
|
resolve,
|
|
122
|
-
reject
|
|
131
|
+
reject,
|
|
132
|
+
then: (...args) => promise.then(...args)
|
|
123
133
|
},
|
|
124
134
|
context
|
|
125
135
|
};
|
|
136
|
+
if (this.pendingPromise === null) {
|
|
137
|
+
this.pendingPromise = state.promise;
|
|
138
|
+
}
|
|
126
139
|
this.#step("forward", state);
|
|
127
140
|
});
|
|
141
|
+
return await promise;
|
|
128
142
|
}
|
|
129
143
|
async cleanup() {
|
|
130
144
|
for (const plugin of this.#plugins) {
|
|
@@ -243,16 +257,15 @@ class DocumentStore extends import_store.Writable {
|
|
|
243
257
|
value
|
|
244
258
|
);
|
|
245
259
|
}
|
|
260
|
+
if (!ctx.silenceEcho || value.data !== this.state.data) {
|
|
261
|
+
this.set(value);
|
|
262
|
+
}
|
|
246
263
|
if (!ctx.promise.resolved) {
|
|
247
264
|
ctx.promise.resolve(value);
|
|
248
265
|
ctx.promise.resolved = true;
|
|
249
266
|
}
|
|
250
267
|
this.#lastContext = ctx.context.draft();
|
|
251
268
|
this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
|
|
252
|
-
if (ctx.silenceEcho && value.data === this.state.data) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
this.set(value);
|
|
256
269
|
}
|
|
257
270
|
}
|
|
258
271
|
class ClientPluginContextWrapper {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference path="../../../../../houdini.d.ts" />
|
|
2
|
-
import type { DocumentArtifact, GraphQLObject, NestedList } from '../lib/types';
|
|
3
|
-
import type {
|
|
2
|
+
import type { DocumentArtifact, GraphQLVariables, GraphQLObject, NestedList } from '../lib/types';
|
|
3
|
+
import type { ClientHooks, ClientPlugin } from './documentStore';
|
|
4
4
|
import { DocumentStore } from './documentStore';
|
|
5
|
-
import {
|
|
6
|
-
export { DocumentStore, type ClientPlugin } from './documentStore';
|
|
5
|
+
import type { FetchParamFn, ThrowOnErrorOperations, ThrowOnErrorParams } from './plugins';
|
|
6
|
+
export { DocumentStore, type ClientPlugin, type SendParams } from './documentStore';
|
|
7
7
|
export { fetch, mutation, query, subscription } from './plugins';
|
|
8
|
-
type
|
|
8
|
+
export type HoudiniClientConstructorArgs = {
|
|
9
9
|
url: string;
|
|
10
10
|
fetchParams?: FetchParamFn;
|
|
11
11
|
plugins?: NestedList<ClientPlugin>;
|
|
@@ -19,9 +19,10 @@ export type ObserveParams<_Data extends GraphQLObject, _Artifact extends Documen
|
|
|
19
19
|
fetching?: boolean;
|
|
20
20
|
};
|
|
21
21
|
export declare class HoudiniClient {
|
|
22
|
-
#private;
|
|
23
22
|
url: string;
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
readonly plugins: ClientPlugin[];
|
|
24
|
+
readonly throwOnError_operations: ThrowOnErrorOperations[];
|
|
25
|
+
constructor({ url, fetchParams, plugins, pipeline, throwOnError, }: HoudiniClientConstructorArgs);
|
|
26
|
+
observe<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
|
|
26
27
|
}
|
|
27
28
|
export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
|
|
@@ -41,14 +41,22 @@ var import_documentStore2 = require("./documentStore");
|
|
|
41
41
|
var import_plugins2 = require("./plugins");
|
|
42
42
|
class HoudiniClient {
|
|
43
43
|
url;
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
plugins;
|
|
45
|
+
throwOnError_operations;
|
|
46
|
+
constructor({
|
|
47
|
+
url,
|
|
48
|
+
fetchParams,
|
|
49
|
+
plugins,
|
|
50
|
+
pipeline,
|
|
51
|
+
throwOnError
|
|
52
|
+
}) {
|
|
46
53
|
if (plugins && pipeline) {
|
|
47
54
|
throw new Error(
|
|
48
55
|
"A client cannot be given a pipeline and a list of plugins at the same time."
|
|
49
56
|
);
|
|
50
57
|
}
|
|
51
|
-
this
|
|
58
|
+
this.throwOnError_operations = throwOnError?.operations ?? [];
|
|
59
|
+
this.plugins = (0, import_flatten.flatten)(
|
|
52
60
|
[].concat(
|
|
53
61
|
throwOnError ? [(0, import_plugins.throwOnError)(throwOnError)] : [],
|
|
54
62
|
(0, import_plugins.fetchParams)(fetchParams),
|
|
@@ -74,7 +82,7 @@ class HoudiniClient {
|
|
|
74
82
|
return new import_documentStore.DocumentStore({
|
|
75
83
|
client: this,
|
|
76
84
|
artifact,
|
|
77
|
-
plugins: createPluginHooks(this
|
|
85
|
+
plugins: createPluginHooks(this.plugins),
|
|
78
86
|
cache,
|
|
79
87
|
initialValue,
|
|
80
88
|
fetching
|
|
@@ -3,7 +3,7 @@ import { Cache } from '../../cache/cache';
|
|
|
3
3
|
import type { ClientPlugin } from '../documentStore';
|
|
4
4
|
export declare const cachePolicy: ({ enabled, setFetching, cache: localCache, serverSideFallback, }: {
|
|
5
5
|
enabled: boolean;
|
|
6
|
-
setFetching: (val: boolean) => void;
|
|
6
|
+
setFetching: (val: boolean, data?: any) => void;
|
|
7
7
|
cache?: Cache | undefined;
|
|
8
8
|
serverSideFallback?: boolean | undefined;
|
|
9
9
|
}) => ClientPlugin;
|
|
@@ -41,7 +41,7 @@ const cachePolicy = ({
|
|
|
41
41
|
network(ctx, { initialValue, next, resolve, marshalVariables }) {
|
|
42
42
|
const { policy, artifact } = ctx;
|
|
43
43
|
let useCache = false;
|
|
44
|
-
if (enabled && artifact.kind === import_types.ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
|
|
44
|
+
if (enabled && (artifact.kind === import_types.ArtifactKind.Query || artifact.kind === import_types.ArtifactKind.Fragment) && !ctx.cacheParams?.disableRead) {
|
|
45
45
|
if (policy !== import_types.CachePolicy.NetworkOnly) {
|
|
46
46
|
const value = localCache.read({
|
|
47
47
|
selection: artifact.selection,
|
|
@@ -82,7 +82,17 @@ const cachePolicy = ({
|
|
|
82
82
|
localCache._internal_unstable.collectGarbage();
|
|
83
83
|
}, 0);
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
if (!ctx.stuff?.silenceLoading) {
|
|
86
|
+
let fetchingState = null;
|
|
87
|
+
if (!useCache && "enableLoadingState" in artifact && artifact.enableLoadingState) {
|
|
88
|
+
fetchingState = localCache.read({
|
|
89
|
+
selection: artifact.selection,
|
|
90
|
+
variables: marshalVariables(ctx),
|
|
91
|
+
loading: true
|
|
92
|
+
}).data;
|
|
93
|
+
}
|
|
94
|
+
setFetching(!useCache, fetchingState);
|
|
95
|
+
}
|
|
86
96
|
return next(ctx);
|
|
87
97
|
},
|
|
88
98
|
afterNetwork(ctx, { resolve, value, marshalVariables }) {
|
|
@@ -21,6 +21,7 @@ export type FetchContext = {
|
|
|
21
21
|
export type RequestHandlerArgs = FetchContext & FetchParams;
|
|
22
22
|
export type RequestHandler<_Data = any> = (args: RequestHandlerArgs) => Promise<RequestPayload<_Data>>;
|
|
23
23
|
export type FetchParams = {
|
|
24
|
+
name: string;
|
|
24
25
|
text: string;
|
|
25
26
|
hash: string;
|
|
26
27
|
variables: {
|
|
@@ -33,6 +33,7 @@ const fetch = (target) => {
|
|
|
33
33
|
}
|
|
34
34
|
const fetch2 = ctx.fetch ?? globalThis.fetch;
|
|
35
35
|
const fetchParams = {
|
|
36
|
+
name: ctx.artifact.name,
|
|
36
37
|
text: ctx.text,
|
|
37
38
|
hash: ctx.hash,
|
|
38
39
|
variables: marshalVariables(ctx)
|
|
@@ -73,10 +74,10 @@ const defaultFetch = (url, params) => {
|
|
|
73
74
|
"Could not find configured client url. Please specify one in your HoudiniClient constructor."
|
|
74
75
|
);
|
|
75
76
|
}
|
|
76
|
-
return async ({ fetch: fetch2, text, variables }) => {
|
|
77
|
+
return async ({ fetch: fetch2, name, text, variables }) => {
|
|
77
78
|
const result = await fetch2(url, {
|
|
78
79
|
method: "POST",
|
|
79
|
-
body: JSON.stringify({ query: text, variables }),
|
|
80
|
+
body: JSON.stringify({ operationName: name, query: text, variables }),
|
|
80
81
|
...params,
|
|
81
82
|
headers: {
|
|
82
83
|
Accept: "application/graphql+json, application/json",
|
|
@@ -28,16 +28,22 @@ __export(fragment_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(fragment_exports);
|
|
30
30
|
var import_cache = __toESM(require("../../cache"), 1);
|
|
31
|
+
var import_deepEquals = require("../../lib/deepEquals");
|
|
31
32
|
var import_types = require("../../lib/types");
|
|
32
33
|
var import_utils = require("../utils");
|
|
33
34
|
const fragment = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Fragment, function() {
|
|
34
35
|
let subscriptionSpec = null;
|
|
36
|
+
let lastReference = null;
|
|
35
37
|
return {
|
|
36
38
|
start(ctx, { next, resolve, variablesChanged, marshalVariables }) {
|
|
37
39
|
if (!ctx.stuff.parentID) {
|
|
38
40
|
return next(ctx);
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
const currentReference = {
|
|
43
|
+
parent: ctx.stuff.parentID,
|
|
44
|
+
variables: marshalVariables(ctx)
|
|
45
|
+
};
|
|
46
|
+
if (!ctx.cacheParams?.disableSubscriptions && (!(0, import_deepEquals.deepEquals)(lastReference, currentReference) || variablesChanged(ctx))) {
|
|
41
47
|
if (subscriptionSpec) {
|
|
42
48
|
import_cache.default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
|
|
43
49
|
}
|
|
@@ -60,6 +66,7 @@ const fragment = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Frag
|
|
|
60
66
|
}
|
|
61
67
|
};
|
|
62
68
|
import_cache.default.subscribe(subscriptionSpec, variables);
|
|
69
|
+
lastReference = currentReference;
|
|
63
70
|
}
|
|
64
71
|
next(ctx);
|
|
65
72
|
},
|
|
@@ -47,10 +47,11 @@ const query = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Query,
|
|
|
47
47
|
import_cache.default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
|
|
48
48
|
}
|
|
49
49
|
lastVariables = { ...marshalVariables(ctx) };
|
|
50
|
+
const variables = lastVariables;
|
|
50
51
|
subscriptionSpec = {
|
|
51
52
|
rootType: ctx.artifact.rootType,
|
|
52
53
|
selection: ctx.artifact.selection,
|
|
53
|
-
variables: () =>
|
|
54
|
+
variables: () => variables,
|
|
54
55
|
set: (newValue) => {
|
|
55
56
|
resolve(ctx, {
|
|
56
57
|
data: newValue,
|
|
@@ -3,6 +3,7 @@ export declare function subscription(factory: SubscriptionHandler): import("../d
|
|
|
3
3
|
export type SubscriptionHandler = (ctx: ClientPluginContext) => SubscriptionClient;
|
|
4
4
|
export type SubscriptionClient = {
|
|
5
5
|
subscribe: (payload: {
|
|
6
|
+
operationName: string;
|
|
6
7
|
query: string;
|
|
7
8
|
variables?: {};
|
|
8
9
|
}, handlers: {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { QueryResult } from '../../lib';
|
|
2
2
|
import type { ClientPlugin, ClientPluginContext } from '../documentStore';
|
|
3
|
+
export type ThrowOnErrorOperations = 'all' | 'query' | 'mutation' | 'subscription';
|
|
3
4
|
export type ThrowOnErrorParams = {
|
|
4
|
-
operations:
|
|
5
|
+
operations: ThrowOnErrorOperations[];
|
|
5
6
|
error?: (errors: NonNullable<QueryResult<any, any>['errors']>, ctx: ClientPluginContext) => unknown;
|
|
6
7
|
};
|
|
7
8
|
export declare const throwOnError: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
|
|
@@ -58,7 +58,8 @@ function defaultConfigValues(file) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
function keyFieldsForType(configFile, type) {
|
|
61
|
-
|
|
61
|
+
const withDefault = defaultConfigValues(configFile);
|
|
62
|
+
return withDefault.types?.[type]?.keys || withDefault.defaultKeys;
|
|
62
63
|
}
|
|
63
64
|
function computeID(configFile, type, data) {
|
|
64
65
|
const fields = keyFieldsForType(configFile, type);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GraphQLObject, PageInfo } from './types';
|
|
2
|
+
export declare function nullPageInfo(): PageInfo;
|
|
3
|
+
export declare function missingPageSizeError(fnName: string): {
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function extractPageInfo(data: any, path: string[]): PageInfo;
|
|
7
|
+
export declare function countPage<_Data extends GraphQLObject>(source: string[], value: _Data | null): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var pageInfo_exports = {};
|
|
20
|
+
__export(pageInfo_exports, {
|
|
21
|
+
countPage: () => countPage,
|
|
22
|
+
extractPageInfo: () => extractPageInfo,
|
|
23
|
+
missingPageSizeError: () => missingPageSizeError,
|
|
24
|
+
nullPageInfo: () => nullPageInfo
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(pageInfo_exports);
|
|
27
|
+
var import_constants = require("./constants");
|
|
28
|
+
function nullPageInfo() {
|
|
29
|
+
return { startCursor: null, endCursor: null, hasNextPage: false, hasPreviousPage: false };
|
|
30
|
+
}
|
|
31
|
+
function missingPageSizeError(fnName) {
|
|
32
|
+
return {
|
|
33
|
+
message: `${fnName} is missing the required page arguments. For more information, please visit this link: ${import_constants.siteURL}/guides/pagination`
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function extractPageInfo(data, path) {
|
|
37
|
+
if (!data) {
|
|
38
|
+
return {
|
|
39
|
+
startCursor: null,
|
|
40
|
+
endCursor: null,
|
|
41
|
+
hasNextPage: false,
|
|
42
|
+
hasPreviousPage: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
let localPath = [...path];
|
|
46
|
+
let current = data;
|
|
47
|
+
while (localPath.length > 0) {
|
|
48
|
+
if (!current) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
current = current[localPath.shift()];
|
|
52
|
+
}
|
|
53
|
+
return current?.pageInfo ?? nullPageInfo();
|
|
54
|
+
}
|
|
55
|
+
function countPage(source, value) {
|
|
56
|
+
let data = value;
|
|
57
|
+
if (value === null || data === null || data === void 0) {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
for (const field of source) {
|
|
61
|
+
const obj = data[field];
|
|
62
|
+
if (obj && !Array.isArray(obj)) {
|
|
63
|
+
data = obj;
|
|
64
|
+
} else if (!data) {
|
|
65
|
+
throw new Error("Could not count page size");
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(obj)) {
|
|
68
|
+
return obj.length;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
countPage,
|
|
76
|
+
extractPageInfo,
|
|
77
|
+
missingPageSizeError,
|
|
78
|
+
nullPageInfo
|
|
79
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SendParams } from '../client/documentStore';
|
|
2
|
+
import type { CursorHandlers, FetchFn, GraphQLObject, GraphQLVariables, QueryArtifact, QueryResult, FetchParams } from './types';
|
|
3
|
+
export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, getSession, }: {
|
|
4
|
+
artifact: QueryArtifact;
|
|
5
|
+
getState: () => _Data | null;
|
|
6
|
+
getVariables: () => NonNullable<_Input>;
|
|
7
|
+
getSession: () => Promise<App.Session>;
|
|
8
|
+
fetch: FetchFn<_Data, _Input>;
|
|
9
|
+
fetchUpdate: (arg: SendParams, updates: string[]) => ReturnType<FetchFn<_Data, _Input>>;
|
|
10
|
+
}): CursorHandlers<_Data, _Input>;
|
|
11
|
+
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, getSession, }: {
|
|
12
|
+
artifact: QueryArtifact;
|
|
13
|
+
fetch: FetchFn<_Data, _Input>;
|
|
14
|
+
fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
|
|
15
|
+
storeName: string;
|
|
16
|
+
getState: () => _Data | null;
|
|
17
|
+
getVariables: () => _Input;
|
|
18
|
+
getSession: () => Promise<App.Session>;
|
|
19
|
+
}): {
|
|
20
|
+
loadNextPage: ({ limit, offset, fetch, metadata, }?: {
|
|
21
|
+
limit?: number | undefined;
|
|
22
|
+
offset?: number | undefined;
|
|
23
|
+
fetch?: typeof fetch | undefined;
|
|
24
|
+
metadata?: {} | undefined;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
fetch(params?: FetchParams<_Input>): Promise<QueryResult<_Data, _Input>>;
|
|
27
|
+
};
|