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
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { getCurrentConfig } from "./config";
|
|
2
|
-
import { siteURL } from "./constants";
|
|
3
|
-
import { deepEquals } from "./deepEquals";
|
|
4
|
-
import { countPage, extractPageInfo, missingPageSizeError } from "./pageInfo";
|
|
5
|
-
import { CachePolicy } from "./types";
|
|
6
|
-
function cursorHandlers({
|
|
7
|
-
artifact,
|
|
8
|
-
storeName,
|
|
9
|
-
fetchUpdate: parentFetchUpdate,
|
|
10
|
-
fetch: parentFetch,
|
|
11
|
-
getState,
|
|
12
|
-
getVariables,
|
|
13
|
-
getSession
|
|
14
|
-
}) {
|
|
15
|
-
const loadPage = async ({
|
|
16
|
-
pageSizeVar,
|
|
17
|
-
input,
|
|
18
|
-
functionName,
|
|
19
|
-
metadata = {},
|
|
20
|
-
fetch,
|
|
21
|
-
where
|
|
22
|
-
}) => {
|
|
23
|
-
const config = getCurrentConfig();
|
|
24
|
-
const loadVariables = {
|
|
25
|
-
...getVariables(),
|
|
26
|
-
...input
|
|
27
|
-
};
|
|
28
|
-
if (!loadVariables[pageSizeVar] && !artifact.refetch.pageSize) {
|
|
29
|
-
throw missingPageSizeError(functionName);
|
|
30
|
-
}
|
|
31
|
-
let isSinglePage = artifact.refetch?.mode === "SinglePage";
|
|
32
|
-
await (isSinglePage ? parentFetch : parentFetchUpdate)(
|
|
33
|
-
{
|
|
34
|
-
variables: loadVariables,
|
|
35
|
-
fetch,
|
|
36
|
-
metadata,
|
|
37
|
-
policy: isSinglePage ? artifact.policy : CachePolicy.NetworkOnly,
|
|
38
|
-
session: await getSession()
|
|
39
|
-
},
|
|
40
|
-
isSinglePage ? [] : [where === "start" ? "prepend" : "append"]
|
|
41
|
-
);
|
|
42
|
-
const resultPath = [...artifact.refetch.path];
|
|
43
|
-
if (artifact.refetch.embedded) {
|
|
44
|
-
const { targetType } = artifact.refetch;
|
|
45
|
-
if (!config.types?.[targetType]?.resolve) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
`Missing type resolve configuration for ${targetType}. For more information, see ${siteURL}/guides/pagination#paginated-fragments`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
resultPath.unshift(config.types[targetType].resolve.queryField);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const getPageInfo = () => {
|
|
54
|
-
return extractPageInfo(getState(), artifact.refetch?.path ?? []);
|
|
55
|
-
};
|
|
56
|
-
return {
|
|
57
|
-
loadNextPage: async ({
|
|
58
|
-
first,
|
|
59
|
-
after,
|
|
60
|
-
fetch,
|
|
61
|
-
metadata
|
|
62
|
-
} = {}) => {
|
|
63
|
-
const currentPageInfo = getPageInfo();
|
|
64
|
-
if (!currentPageInfo.hasNextPage) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const input = {
|
|
68
|
-
first: first ?? artifact.refetch.pageSize,
|
|
69
|
-
after: after ?? currentPageInfo.endCursor,
|
|
70
|
-
before: null,
|
|
71
|
-
last: null
|
|
72
|
-
};
|
|
73
|
-
return await loadPage({
|
|
74
|
-
pageSizeVar: "first",
|
|
75
|
-
functionName: "loadNextPage",
|
|
76
|
-
input,
|
|
77
|
-
fetch,
|
|
78
|
-
metadata,
|
|
79
|
-
where: "end"
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
loadPreviousPage: async ({
|
|
83
|
-
last,
|
|
84
|
-
before,
|
|
85
|
-
fetch,
|
|
86
|
-
metadata
|
|
87
|
-
} = {}) => {
|
|
88
|
-
const currentPageInfo = getPageInfo();
|
|
89
|
-
if (!currentPageInfo.hasPreviousPage) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const input = {
|
|
93
|
-
before: before ?? currentPageInfo.startCursor,
|
|
94
|
-
last: last ?? artifact.refetch.pageSize,
|
|
95
|
-
first: null,
|
|
96
|
-
after: null
|
|
97
|
-
};
|
|
98
|
-
return await loadPage({
|
|
99
|
-
pageSizeVar: "last",
|
|
100
|
-
functionName: "loadPreviousPage",
|
|
101
|
-
input,
|
|
102
|
-
fetch,
|
|
103
|
-
metadata,
|
|
104
|
-
where: "start"
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
async fetch(args) {
|
|
108
|
-
const { variables } = args ?? {};
|
|
109
|
-
if (variables && !deepEquals(getVariables(), variables)) {
|
|
110
|
-
return await parentFetch(args);
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
var currentPageInfo = extractPageInfo(getState(), artifact.refetch.path);
|
|
114
|
-
} catch {
|
|
115
|
-
return await parentFetch(args);
|
|
116
|
-
}
|
|
117
|
-
const queryVariables = {};
|
|
118
|
-
const count = countPage(artifact.refetch.path.concat("edges"), getState()) || artifact.refetch.pageSize;
|
|
119
|
-
if (count && count > artifact.refetch.pageSize) {
|
|
120
|
-
if (currentPageInfo.hasPreviousPage && currentPageInfo.hasNextPage && !(variables?.["first"] && variables?.["after"] || variables?.["last"] && variables?.["before"])) {
|
|
121
|
-
console.warn(`\u26A0\uFE0F Encountered a fetch() in the middle of the connection.
|
|
122
|
-
Make sure to pass a cursor value by hand that includes the current set (ie the entry before startCursor)
|
|
123
|
-
`);
|
|
124
|
-
}
|
|
125
|
-
if (!currentPageInfo.hasPreviousPage) {
|
|
126
|
-
queryVariables["first"] = count;
|
|
127
|
-
queryVariables["after"] = null;
|
|
128
|
-
queryVariables["last"] = null;
|
|
129
|
-
queryVariables["before"] = null;
|
|
130
|
-
} else if (!currentPageInfo.hasNextPage) {
|
|
131
|
-
queryVariables["last"] = count;
|
|
132
|
-
queryVariables["first"] = null;
|
|
133
|
-
queryVariables["after"] = null;
|
|
134
|
-
queryVariables["before"] = null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
Object.assign(queryVariables, variables ?? {});
|
|
138
|
-
const result = await parentFetch({
|
|
139
|
-
...args,
|
|
140
|
-
variables: queryVariables
|
|
141
|
-
});
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function offsetHandlers({
|
|
147
|
-
artifact,
|
|
148
|
-
storeName,
|
|
149
|
-
getState,
|
|
150
|
-
getVariables,
|
|
151
|
-
fetch: parentFetch,
|
|
152
|
-
fetchUpdate: parentFetchUpdate,
|
|
153
|
-
getSession
|
|
154
|
-
}) {
|
|
155
|
-
let getOffset = () => artifact.refetch?.start || countPage(artifact.refetch.path, getState()) || artifact.refetch.pageSize;
|
|
156
|
-
let currentOffset = getOffset() ?? 0;
|
|
157
|
-
return {
|
|
158
|
-
loadNextPage: async ({
|
|
159
|
-
limit,
|
|
160
|
-
offset,
|
|
161
|
-
fetch,
|
|
162
|
-
metadata
|
|
163
|
-
} = {}) => {
|
|
164
|
-
const queryVariables = {
|
|
165
|
-
...getVariables(),
|
|
166
|
-
offset: offset ?? getOffset()
|
|
167
|
-
};
|
|
168
|
-
if (limit || limit === 0) {
|
|
169
|
-
queryVariables.limit = limit;
|
|
170
|
-
}
|
|
171
|
-
if (!queryVariables.limit && !artifact.refetch.pageSize) {
|
|
172
|
-
throw missingPageSizeError("loadNextPage");
|
|
173
|
-
}
|
|
174
|
-
let isSinglePage = artifact.refetch?.mode === "SinglePage";
|
|
175
|
-
const targetFetch = isSinglePage ? parentFetch : parentFetchUpdate;
|
|
176
|
-
await targetFetch({
|
|
177
|
-
variables: queryVariables,
|
|
178
|
-
fetch,
|
|
179
|
-
metadata,
|
|
180
|
-
policy: isSinglePage ? artifact.policy : CachePolicy.NetworkOnly,
|
|
181
|
-
session: await getSession()
|
|
182
|
-
});
|
|
183
|
-
const pageSize = queryVariables.limit || artifact.refetch.pageSize;
|
|
184
|
-
currentOffset = offset + pageSize;
|
|
185
|
-
},
|
|
186
|
-
async fetch(params = {}) {
|
|
187
|
-
const { variables } = params;
|
|
188
|
-
if (variables && !deepEquals(getVariables(), variables)) {
|
|
189
|
-
return parentFetch.call(this, params);
|
|
190
|
-
}
|
|
191
|
-
const count = currentOffset || getOffset();
|
|
192
|
-
const queryVariables = {};
|
|
193
|
-
if (!artifact.refetch.pageSize || count > artifact.refetch.pageSize) {
|
|
194
|
-
queryVariables.limit = count;
|
|
195
|
-
}
|
|
196
|
-
return await parentFetch.call(this, {
|
|
197
|
-
...params,
|
|
198
|
-
variables: queryVariables
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
export {
|
|
204
|
-
cursorHandlers,
|
|
205
|
-
offsetHandlers
|
|
206
|
-
};
|