houdini 1.1.4-react.0 → 1.1.5
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-cjs/index.js +603 -442
- package/build/cmd-esm/index.js +603 -442
- package/build/codegen/transforms/fragmentVariables.d.ts +0 -11
- package/build/codegen-cjs/index.js +572 -398
- package/build/codegen-esm/index.js +572 -398
- package/build/lib/config.d.ts +1 -1
- package/build/lib/parse.d.ts +1 -2
- package/build/lib/types.d.ts +1 -4
- package/build/lib-cjs/index.js +188 -196
- package/build/lib-esm/index.js +188 -196
- package/build/runtime/cache/cache.d.ts +4 -2
- package/build/runtime/client/documentStore.d.ts +0 -3
- package/build/runtime/client/index.d.ts +1 -1
- package/build/runtime/lib/types.d.ts +4 -46
- package/build/runtime-cjs/cache/cache.d.ts +4 -2
- package/build/runtime-cjs/cache/cache.js +37 -14
- package/build/runtime-cjs/client/documentStore.d.ts +0 -3
- package/build/runtime-cjs/client/documentStore.js +6 -11
- package/build/runtime-cjs/client/index.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +3 -5
- package/build/runtime-cjs/client/plugins/fragment.js +1 -8
- package/build/runtime-cjs/client/plugins/query.js +1 -2
- package/build/runtime-cjs/lib/types.d.ts +4 -46
- package/build/runtime-esm/cache/cache.d.ts +4 -2
- package/build/runtime-esm/cache/cache.js +37 -14
- package/build/runtime-esm/client/documentStore.d.ts +0 -3
- package/build/runtime-esm/client/documentStore.js +6 -11
- package/build/runtime-esm/client/index.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +3 -5
- package/build/runtime-esm/client/plugins/fragment.js +1 -8
- package/build/runtime-esm/client/plugins/query.js +1 -2
- package/build/runtime-esm/lib/types.d.ts +4 -46
- package/build/test-cjs/index.js +594 -424
- package/build/test-esm/index.js +594 -424
- package/build/vite-cjs/index.js +613 -450
- package/build/vite-esm/index.js +613 -450
- package/package.json +3 -1
- package/build/runtime/lib/pageInfo.d.ts +0 -7
- package/build/runtime/lib/pagination.d.ts +0 -29
- package/build/runtime-cjs/lib/pageInfo.d.ts +0 -7
- package/build/runtime-cjs/lib/pageInfo.js +0 -79
- package/build/runtime-cjs/lib/pagination.d.ts +0 -29
- package/build/runtime-cjs/lib/pagination.js +0 -231
- package/build/runtime-esm/lib/pageInfo.d.ts +0 -7
- package/build/runtime-esm/lib/pageInfo.js +0 -52
- package/build/runtime-esm/lib/pagination.d.ts +0 -29
- package/build/runtime-esm/lib/pagination.js +0 -206
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "The disappearing GraphQL clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"@types/glob": "^8.0.0",
|
|
21
21
|
"@types/minimatch": "^5.1.2",
|
|
22
22
|
"@types/node": "^18.7.23",
|
|
23
|
+
"@types/ungap__structured-clone": "^0.3.0",
|
|
23
24
|
"prettier": "^2.8.3",
|
|
24
25
|
"rollup": "^3.7.4",
|
|
25
26
|
"vite": "^4.1.4",
|
|
@@ -34,6 +35,7 @@
|
|
|
34
35
|
"@types/fs-extra": "^9.0.13",
|
|
35
36
|
"@types/micromatch": "^4.0.2",
|
|
36
37
|
"@types/prompts": "^2.0.14",
|
|
38
|
+
"@ungap/structured-clone": "^1.0.2",
|
|
37
39
|
"ast-types": "^0.16.1",
|
|
38
40
|
"commander": "^9.4.0",
|
|
39
41
|
"deepmerge": "^4.2.2",
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { SendParams } from '../client/documentStore';
|
|
2
|
-
import { FetchParams } from './types';
|
|
3
|
-
import type { CursorHandlers, FetchFn, GraphQLObject, QueryArtifact, QueryResult } from './types';
|
|
4
|
-
export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, storeName, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, getSession, }: {
|
|
5
|
-
artifact: QueryArtifact;
|
|
6
|
-
storeName: string;
|
|
7
|
-
getState: () => _Data | null;
|
|
8
|
-
getVariables: () => _Input;
|
|
9
|
-
getSession: () => Promise<App.Session>;
|
|
10
|
-
fetch: FetchFn<_Data, _Input>;
|
|
11
|
-
fetchUpdate: (arg: SendParams, updates: string[]) => ReturnType<FetchFn<_Data, _Input>>;
|
|
12
|
-
}): CursorHandlers<_Data, _Input>;
|
|
13
|
-
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends {}>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, getSession, }: {
|
|
14
|
-
artifact: QueryArtifact;
|
|
15
|
-
fetch: FetchFn<_Data, _Input>;
|
|
16
|
-
fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
|
|
17
|
-
storeName: string;
|
|
18
|
-
getState: () => _Data | null;
|
|
19
|
-
getVariables: () => _Input;
|
|
20
|
-
getSession: () => Promise<App.Session>;
|
|
21
|
-
}): {
|
|
22
|
-
loadNextPage: ({ limit, offset, fetch, metadata, }?: {
|
|
23
|
-
limit?: number | undefined;
|
|
24
|
-
offset?: number | undefined;
|
|
25
|
-
fetch?: typeof fetch | undefined;
|
|
26
|
-
metadata?: {} | undefined;
|
|
27
|
-
}) => Promise<void>;
|
|
28
|
-
fetch(params?: FetchParams<_Input>): Promise<QueryResult<_Data, _Input>>;
|
|
29
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { SendParams } from '../client/documentStore';
|
|
2
|
-
import { FetchParams } from './types';
|
|
3
|
-
import type { CursorHandlers, FetchFn, GraphQLObject, QueryArtifact, QueryResult } from './types';
|
|
4
|
-
export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, storeName, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, getSession, }: {
|
|
5
|
-
artifact: QueryArtifact;
|
|
6
|
-
storeName: string;
|
|
7
|
-
getState: () => _Data | null;
|
|
8
|
-
getVariables: () => _Input;
|
|
9
|
-
getSession: () => Promise<App.Session>;
|
|
10
|
-
fetch: FetchFn<_Data, _Input>;
|
|
11
|
-
fetchUpdate: (arg: SendParams, updates: string[]) => ReturnType<FetchFn<_Data, _Input>>;
|
|
12
|
-
}): CursorHandlers<_Data, _Input>;
|
|
13
|
-
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends {}>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, getSession, }: {
|
|
14
|
-
artifact: QueryArtifact;
|
|
15
|
-
fetch: FetchFn<_Data, _Input>;
|
|
16
|
-
fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
|
|
17
|
-
storeName: string;
|
|
18
|
-
getState: () => _Data | null;
|
|
19
|
-
getVariables: () => _Input;
|
|
20
|
-
getSession: () => Promise<App.Session>;
|
|
21
|
-
}): {
|
|
22
|
-
loadNextPage: ({ limit, offset, fetch, metadata, }?: {
|
|
23
|
-
limit?: number | undefined;
|
|
24
|
-
offset?: number | undefined;
|
|
25
|
-
fetch?: typeof fetch | undefined;
|
|
26
|
-
metadata?: {} | undefined;
|
|
27
|
-
}) => Promise<void>;
|
|
28
|
-
fetch(params?: FetchParams<_Input>): Promise<QueryResult<_Data, _Input>>;
|
|
29
|
-
};
|
|
@@ -1,231 +0,0 @@
|
|
|
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 pagination_exports = {};
|
|
20
|
-
__export(pagination_exports, {
|
|
21
|
-
cursorHandlers: () => cursorHandlers,
|
|
22
|
-
offsetHandlers: () => offsetHandlers
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(pagination_exports);
|
|
25
|
-
var import_config = require("./config");
|
|
26
|
-
var import_constants = require("./constants");
|
|
27
|
-
var import_deepEquals = require("./deepEquals");
|
|
28
|
-
var import_pageInfo = require("./pageInfo");
|
|
29
|
-
var import_types = require("./types");
|
|
30
|
-
function cursorHandlers({
|
|
31
|
-
artifact,
|
|
32
|
-
storeName,
|
|
33
|
-
fetchUpdate: parentFetchUpdate,
|
|
34
|
-
fetch: parentFetch,
|
|
35
|
-
getState,
|
|
36
|
-
getVariables,
|
|
37
|
-
getSession
|
|
38
|
-
}) {
|
|
39
|
-
const loadPage = async ({
|
|
40
|
-
pageSizeVar,
|
|
41
|
-
input,
|
|
42
|
-
functionName,
|
|
43
|
-
metadata = {},
|
|
44
|
-
fetch,
|
|
45
|
-
where
|
|
46
|
-
}) => {
|
|
47
|
-
const config = (0, import_config.getCurrentConfig)();
|
|
48
|
-
const loadVariables = {
|
|
49
|
-
...getVariables(),
|
|
50
|
-
...input
|
|
51
|
-
};
|
|
52
|
-
if (!loadVariables[pageSizeVar] && !artifact.refetch.pageSize) {
|
|
53
|
-
throw (0, import_pageInfo.missingPageSizeError)(functionName);
|
|
54
|
-
}
|
|
55
|
-
let isSinglePage = artifact.refetch?.mode === "SinglePage";
|
|
56
|
-
await (isSinglePage ? parentFetch : parentFetchUpdate)(
|
|
57
|
-
{
|
|
58
|
-
variables: loadVariables,
|
|
59
|
-
fetch,
|
|
60
|
-
metadata,
|
|
61
|
-
policy: isSinglePage ? artifact.policy : import_types.CachePolicy.NetworkOnly,
|
|
62
|
-
session: await getSession()
|
|
63
|
-
},
|
|
64
|
-
isSinglePage ? [] : [where === "start" ? "prepend" : "append"]
|
|
65
|
-
);
|
|
66
|
-
const resultPath = [...artifact.refetch.path];
|
|
67
|
-
if (artifact.refetch.embedded) {
|
|
68
|
-
const { targetType } = artifact.refetch;
|
|
69
|
-
if (!config.types?.[targetType]?.resolve) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`Missing type resolve configuration for ${targetType}. For more information, see ${import_constants.siteURL}/guides/pagination#paginated-fragments`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
resultPath.unshift(config.types[targetType].resolve.queryField);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const getPageInfo = () => {
|
|
78
|
-
return (0, import_pageInfo.extractPageInfo)(getState(), artifact.refetch?.path ?? []);
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
loadNextPage: async ({
|
|
82
|
-
first,
|
|
83
|
-
after,
|
|
84
|
-
fetch,
|
|
85
|
-
metadata
|
|
86
|
-
} = {}) => {
|
|
87
|
-
const currentPageInfo = getPageInfo();
|
|
88
|
-
if (!currentPageInfo.hasNextPage) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const input = {
|
|
92
|
-
first: first ?? artifact.refetch.pageSize,
|
|
93
|
-
after: after ?? currentPageInfo.endCursor,
|
|
94
|
-
before: null,
|
|
95
|
-
last: null
|
|
96
|
-
};
|
|
97
|
-
return await loadPage({
|
|
98
|
-
pageSizeVar: "first",
|
|
99
|
-
functionName: "loadNextPage",
|
|
100
|
-
input,
|
|
101
|
-
fetch,
|
|
102
|
-
metadata,
|
|
103
|
-
where: "end"
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
loadPreviousPage: async ({
|
|
107
|
-
last,
|
|
108
|
-
before,
|
|
109
|
-
fetch,
|
|
110
|
-
metadata
|
|
111
|
-
} = {}) => {
|
|
112
|
-
const currentPageInfo = getPageInfo();
|
|
113
|
-
if (!currentPageInfo.hasPreviousPage) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const input = {
|
|
117
|
-
before: before ?? currentPageInfo.startCursor,
|
|
118
|
-
last: last ?? artifact.refetch.pageSize,
|
|
119
|
-
first: null,
|
|
120
|
-
after: null
|
|
121
|
-
};
|
|
122
|
-
return await loadPage({
|
|
123
|
-
pageSizeVar: "last",
|
|
124
|
-
functionName: "loadPreviousPage",
|
|
125
|
-
input,
|
|
126
|
-
fetch,
|
|
127
|
-
metadata,
|
|
128
|
-
where: "start"
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
async fetch(args) {
|
|
132
|
-
const { variables } = args ?? {};
|
|
133
|
-
if (variables && !(0, import_deepEquals.deepEquals)(getVariables(), variables)) {
|
|
134
|
-
return await parentFetch(args);
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
var currentPageInfo = (0, import_pageInfo.extractPageInfo)(getState(), artifact.refetch.path);
|
|
138
|
-
} catch {
|
|
139
|
-
return await parentFetch(args);
|
|
140
|
-
}
|
|
141
|
-
const queryVariables = {};
|
|
142
|
-
const count = (0, import_pageInfo.countPage)(artifact.refetch.path.concat("edges"), getState()) || artifact.refetch.pageSize;
|
|
143
|
-
if (count && count > artifact.refetch.pageSize) {
|
|
144
|
-
if (currentPageInfo.hasPreviousPage && currentPageInfo.hasNextPage && !(variables?.["first"] && variables?.["after"] || variables?.["last"] && variables?.["before"])) {
|
|
145
|
-
console.warn(`\u26A0\uFE0F Encountered a fetch() in the middle of the connection.
|
|
146
|
-
Make sure to pass a cursor value by hand that includes the current set (ie the entry before startCursor)
|
|
147
|
-
`);
|
|
148
|
-
}
|
|
149
|
-
if (!currentPageInfo.hasPreviousPage) {
|
|
150
|
-
queryVariables["first"] = count;
|
|
151
|
-
queryVariables["after"] = null;
|
|
152
|
-
queryVariables["last"] = null;
|
|
153
|
-
queryVariables["before"] = null;
|
|
154
|
-
} else if (!currentPageInfo.hasNextPage) {
|
|
155
|
-
queryVariables["last"] = count;
|
|
156
|
-
queryVariables["first"] = null;
|
|
157
|
-
queryVariables["after"] = null;
|
|
158
|
-
queryVariables["before"] = null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
Object.assign(queryVariables, variables ?? {});
|
|
162
|
-
const result = await parentFetch({
|
|
163
|
-
...args,
|
|
164
|
-
variables: queryVariables
|
|
165
|
-
});
|
|
166
|
-
return result;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function offsetHandlers({
|
|
171
|
-
artifact,
|
|
172
|
-
storeName,
|
|
173
|
-
getState,
|
|
174
|
-
getVariables,
|
|
175
|
-
fetch: parentFetch,
|
|
176
|
-
fetchUpdate: parentFetchUpdate,
|
|
177
|
-
getSession
|
|
178
|
-
}) {
|
|
179
|
-
let getOffset = () => artifact.refetch?.start || (0, import_pageInfo.countPage)(artifact.refetch.path, getState()) || artifact.refetch.pageSize;
|
|
180
|
-
let currentOffset = getOffset() ?? 0;
|
|
181
|
-
return {
|
|
182
|
-
loadNextPage: async ({
|
|
183
|
-
limit,
|
|
184
|
-
offset,
|
|
185
|
-
fetch,
|
|
186
|
-
metadata
|
|
187
|
-
} = {}) => {
|
|
188
|
-
const queryVariables = {
|
|
189
|
-
...getVariables(),
|
|
190
|
-
offset: offset ?? getOffset()
|
|
191
|
-
};
|
|
192
|
-
if (limit || limit === 0) {
|
|
193
|
-
queryVariables.limit = limit;
|
|
194
|
-
}
|
|
195
|
-
if (!queryVariables.limit && !artifact.refetch.pageSize) {
|
|
196
|
-
throw (0, import_pageInfo.missingPageSizeError)("loadNextPage");
|
|
197
|
-
}
|
|
198
|
-
let isSinglePage = artifact.refetch?.mode === "SinglePage";
|
|
199
|
-
const targetFetch = isSinglePage ? parentFetch : parentFetchUpdate;
|
|
200
|
-
await targetFetch({
|
|
201
|
-
variables: queryVariables,
|
|
202
|
-
fetch,
|
|
203
|
-
metadata,
|
|
204
|
-
policy: isSinglePage ? artifact.policy : import_types.CachePolicy.NetworkOnly,
|
|
205
|
-
session: await getSession()
|
|
206
|
-
});
|
|
207
|
-
const pageSize = queryVariables.limit || artifact.refetch.pageSize;
|
|
208
|
-
currentOffset = offset + pageSize;
|
|
209
|
-
},
|
|
210
|
-
async fetch(params = {}) {
|
|
211
|
-
const { variables } = params;
|
|
212
|
-
if (variables && !(0, import_deepEquals.deepEquals)(getVariables(), variables)) {
|
|
213
|
-
return parentFetch.call(this, params);
|
|
214
|
-
}
|
|
215
|
-
const count = currentOffset || getOffset();
|
|
216
|
-
const queryVariables = {};
|
|
217
|
-
if (!artifact.refetch.pageSize || count > artifact.refetch.pageSize) {
|
|
218
|
-
queryVariables.limit = count;
|
|
219
|
-
}
|
|
220
|
-
return await parentFetch.call(this, {
|
|
221
|
-
...params,
|
|
222
|
-
variables: queryVariables
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
228
|
-
0 && (module.exports = {
|
|
229
|
-
cursorHandlers,
|
|
230
|
-
offsetHandlers
|
|
231
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { siteURL } from "./constants";
|
|
2
|
-
function nullPageInfo() {
|
|
3
|
-
return { startCursor: null, endCursor: null, hasNextPage: false, hasPreviousPage: false };
|
|
4
|
-
}
|
|
5
|
-
function missingPageSizeError(fnName) {
|
|
6
|
-
return {
|
|
7
|
-
message: `${fnName} is missing the required page arguments. For more information, please visit this link: ${siteURL}/guides/pagination`
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function extractPageInfo(data, path) {
|
|
11
|
-
if (!data) {
|
|
12
|
-
return {
|
|
13
|
-
startCursor: null,
|
|
14
|
-
endCursor: null,
|
|
15
|
-
hasNextPage: false,
|
|
16
|
-
hasPreviousPage: false
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
let localPath = [...path];
|
|
20
|
-
let current = data;
|
|
21
|
-
while (localPath.length > 0) {
|
|
22
|
-
if (!current) {
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
current = current[localPath.shift()];
|
|
26
|
-
}
|
|
27
|
-
return current?.pageInfo ?? nullPageInfo();
|
|
28
|
-
}
|
|
29
|
-
function countPage(source, value) {
|
|
30
|
-
let data = value;
|
|
31
|
-
if (value === null || data === null || data === void 0) {
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
for (const field of source) {
|
|
35
|
-
const obj = data[field];
|
|
36
|
-
if (obj && !Array.isArray(obj)) {
|
|
37
|
-
data = obj;
|
|
38
|
-
} else if (!data) {
|
|
39
|
-
throw new Error("Could not count page size");
|
|
40
|
-
}
|
|
41
|
-
if (Array.isArray(obj)) {
|
|
42
|
-
return obj.length;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
countPage,
|
|
49
|
-
extractPageInfo,
|
|
50
|
-
missingPageSizeError,
|
|
51
|
-
nullPageInfo
|
|
52
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { SendParams } from '../client/documentStore';
|
|
2
|
-
import { FetchParams } from './types';
|
|
3
|
-
import type { CursorHandlers, FetchFn, GraphQLObject, QueryArtifact, QueryResult } from './types';
|
|
4
|
-
export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, storeName, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, getSession, }: {
|
|
5
|
-
artifact: QueryArtifact;
|
|
6
|
-
storeName: string;
|
|
7
|
-
getState: () => _Data | null;
|
|
8
|
-
getVariables: () => _Input;
|
|
9
|
-
getSession: () => Promise<App.Session>;
|
|
10
|
-
fetch: FetchFn<_Data, _Input>;
|
|
11
|
-
fetchUpdate: (arg: SendParams, updates: string[]) => ReturnType<FetchFn<_Data, _Input>>;
|
|
12
|
-
}): CursorHandlers<_Data, _Input>;
|
|
13
|
-
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends {}>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, getSession, }: {
|
|
14
|
-
artifact: QueryArtifact;
|
|
15
|
-
fetch: FetchFn<_Data, _Input>;
|
|
16
|
-
fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
|
|
17
|
-
storeName: string;
|
|
18
|
-
getState: () => _Data | null;
|
|
19
|
-
getVariables: () => _Input;
|
|
20
|
-
getSession: () => Promise<App.Session>;
|
|
21
|
-
}): {
|
|
22
|
-
loadNextPage: ({ limit, offset, fetch, metadata, }?: {
|
|
23
|
-
limit?: number | undefined;
|
|
24
|
-
offset?: number | undefined;
|
|
25
|
-
fetch?: typeof fetch | undefined;
|
|
26
|
-
metadata?: {} | undefined;
|
|
27
|
-
}) => Promise<void>;
|
|
28
|
-
fetch(params?: FetchParams<_Input>): Promise<QueryResult<_Data, _Input>>;
|
|
29
|
-
};
|