houdini-svelte 0.17.11 → 0.17.13
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 +91 -23
- package/build/plugin-esm/index.js +91 -23
- package/build/runtime/stores/pagination/query.d.ts +1 -1
- package/build/runtime/stores/query.d.ts +1 -2
- package/build/runtime-cjs/stores/pagination/query.d.ts +1 -1
- package/build/runtime-cjs/stores/query.d.ts +1 -2
- package/build/runtime-cjs/stores/query.js +27 -12
- package/build/runtime-esm/stores/pagination/query.d.ts +1 -1
- package/build/runtime-esm/stores/query.d.ts +1 -2
- package/build/runtime-esm/stores/query.js +28 -11
- package/build/test-cjs/index.js +91 -23
- package/build/test-esm/index.js +91 -23
- package/package.json +5 -5
|
@@ -179846,6 +179846,24 @@ async function svelteKitGenerator(framework2, { config: config2 }) {
|
|
|
179846
179846
|
config2,
|
|
179847
179847
|
uniquePageQueries
|
|
179848
179848
|
);
|
|
179849
|
+
const layout_append_beforeLoad = append_beforeLoad(beforeLayoutLoad, "Layout");
|
|
179850
|
+
const page_append_beforeLoad = append_beforeLoad(beforePageLoad, "Page");
|
|
179851
|
+
const layout_append_afterLoad = append_afterLoad(
|
|
179852
|
+
afterLayoutLoad,
|
|
179853
|
+
"Layout",
|
|
179854
|
+
layoutQueries
|
|
179855
|
+
);
|
|
179856
|
+
const page_append_afterLoad = append_afterLoad(afterPageLoad, "Page", pageQueries);
|
|
179857
|
+
const layout_append_onError = append_onError(
|
|
179858
|
+
onLayoutError,
|
|
179859
|
+
"Layout",
|
|
179860
|
+
layoutQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179861
|
+
);
|
|
179862
|
+
const page_append_onError = append_onError(
|
|
179863
|
+
onPageError,
|
|
179864
|
+
"Page",
|
|
179865
|
+
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179866
|
+
);
|
|
179849
179867
|
const splitString = skTypeString.split("\n\n");
|
|
179850
179868
|
let typeImports = splitString[0];
|
|
179851
179869
|
let utilityTypes = splitString[1];
|
|
@@ -179868,17 +179886,7 @@ import type { ${functionImportsToBring.join(
|
|
|
179868
179886
|
const layoutParams = `${layoutQueries.length > 0 && !utilityTypes.includes("LayoutParams") ? "\ntype LayoutParams = LayoutLoadEvent['params'];" : ""}`;
|
|
179869
179887
|
const pageParams = `${pageQueries.length > 0 && !utilityTypes.includes("PageParams") ? "\ntype PageParams = PageLoadEvent['params'];" : ""}`;
|
|
179870
179888
|
utilityTypes = utilityTypes.concat(layoutParams).concat(pageParams).replaceAll(/\$types\.js/gm, "$houdini");
|
|
179871
|
-
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(
|
|
179872
|
-
append_onError(
|
|
179873
|
-
onPageError,
|
|
179874
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179875
|
-
)
|
|
179876
|
-
).concat(
|
|
179877
|
-
append_onError(
|
|
179878
|
-
onLayoutError,
|
|
179879
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179880
|
-
)
|
|
179881
|
-
).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
179889
|
+
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(layout_append_beforeLoad).concat(page_append_beforeLoad).concat(layout_append_afterLoad).concat(page_append_afterLoad).concat(layout_append_onError).concat(page_append_onError).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
179882
179890
|
/(?<=LayoutData = )([\s\S]*?)(?=;)/,
|
|
179883
179891
|
`Expand<$1 & { ${layoutQueries.map((query) => {
|
|
179884
179892
|
const name2 = query.name.value;
|
|
@@ -179942,15 +179950,15 @@ type LoadInput = { ${queries.filter((query) => query.variableDefinitions?.length
|
|
|
179942
179950
|
return [name2, name2 + "$input"].join(": ");
|
|
179943
179951
|
}).join("; ")} };` : ""}`;
|
|
179944
179952
|
}
|
|
179945
|
-
function append_afterLoad(
|
|
179953
|
+
function append_afterLoad(afterLoad, type, queries) {
|
|
179946
179954
|
return afterLoad ? `
|
|
179947
|
-
type AfterLoadReturn = ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad
|
|
179955
|
+
type AfterLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad>>;
|
|
179948
179956
|
type AfterLoadData = {
|
|
179949
179957
|
${internal_append_afterLoad(queries)}
|
|
179950
179958
|
};
|
|
179951
179959
|
|
|
179952
179960
|
export type AfterLoadEvent = {
|
|
179953
|
-
event:
|
|
179961
|
+
event: ${type}LoadEvent
|
|
179954
179962
|
data: AfterLoadData
|
|
179955
179963
|
input: ${queries.filter((q) => q.variableDefinitions?.length).length ? "LoadInput" : "{}"}
|
|
179956
179964
|
};
|
|
@@ -179962,15 +179970,15 @@ function internal_append_afterLoad(queries) {
|
|
|
179962
179970
|
return [name2, name2 + "$result"].join(": ");
|
|
179963
179971
|
}).join(";\n ")}`;
|
|
179964
179972
|
}
|
|
179965
|
-
function append_beforeLoad(beforeLoad) {
|
|
179973
|
+
function append_beforeLoad(beforeLoad, type) {
|
|
179966
179974
|
return beforeLoad ? `
|
|
179967
|
-
export type BeforeLoadEvent =
|
|
179968
|
-
type BeforeLoadReturn = ReturnType<typeof import('
|
|
179975
|
+
export type BeforeLoadEvent = ${type}LoadEvent;
|
|
179976
|
+
type BeforeLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').beforeLoad>>;
|
|
179969
179977
|
` : "";
|
|
179970
179978
|
}
|
|
179971
|
-
function append_onError(onError, hasLoadInput) {
|
|
179979
|
+
function append_onError(onError, type, hasLoadInput) {
|
|
179972
179980
|
return onError ? `
|
|
179973
|
-
type OnErrorReturn = ReturnType<typeof import('
|
|
179981
|
+
type OnErrorReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').onError>>;
|
|
179974
179982
|
export type OnErrorEvent = { event: Kit.LoadEvent, input: ${hasLoadInput ? "LoadInput" : "{}"}, error: Error | Error[] };
|
|
179975
179983
|
` : "";
|
|
179976
179984
|
}
|
|
@@ -180119,8 +180127,6 @@ async function queryStore({ config: config2, plugin_root }, doc) {
|
|
|
180119
180127
|
const storeData = `${statement}
|
|
180120
180128
|
import artifact from '$houdini/artifacts/${artifactName}'
|
|
180121
180129
|
|
|
180122
|
-
// create the query store
|
|
180123
|
-
|
|
180124
180130
|
export class ${storeName} extends ${store_class} {
|
|
180125
180131
|
constructor() {
|
|
180126
180132
|
super({
|
|
@@ -180150,16 +180156,78 @@ export default ${globalStoreName}
|
|
|
180150
180156
|
const typeDefs = `import type { ${_input}, ${_data}, ${store_class}, QueryStoreFetchParams} from '$houdini'
|
|
180151
180157
|
|
|
180152
180158
|
export declare class ${storeName} extends ${store_class}<${_data}, ${_input}> {
|
|
180159
|
+
/**
|
|
180160
|
+
* ### Route Loads
|
|
180161
|
+
* In a route's load function, manually instantiating a store can be used to look at the result:
|
|
180162
|
+
*
|
|
180163
|
+
* \`\`\`js
|
|
180164
|
+
* export async function load(event) {
|
|
180165
|
+
* const store = new ${storeName}Store()
|
|
180166
|
+
* const { data } = await store.fetch({event})
|
|
180167
|
+
* console.log('do something with', data)
|
|
180168
|
+
*
|
|
180169
|
+
* return {
|
|
180170
|
+
* ${storeName}: store,
|
|
180171
|
+
* }
|
|
180172
|
+
* }
|
|
180173
|
+
*
|
|
180174
|
+
* \`\`\`
|
|
180175
|
+
*
|
|
180176
|
+
* ### Client Side Loading
|
|
180177
|
+
* When performing a client-side only fetch, the best practice to use a store _manually_ is to do the following:
|
|
180178
|
+
*
|
|
180179
|
+
* \`\`\`js
|
|
180180
|
+
* const store = new ${storeName}Store()
|
|
180181
|
+
*
|
|
180182
|
+
* $: browser && store.fetch({ variables });
|
|
180183
|
+
* \`\`\`
|
|
180184
|
+
*/
|
|
180153
180185
|
constructor() {
|
|
180154
180186
|
// @ts-ignore
|
|
180155
180187
|
super({})
|
|
180156
180188
|
}
|
|
180157
180189
|
}
|
|
180158
180190
|
|
|
180159
|
-
|
|
180160
|
-
|
|
180191
|
+
/**
|
|
180192
|
+
* ### Manual Loads
|
|
180193
|
+
* Usually your load function will look like this:
|
|
180194
|
+
*
|
|
180195
|
+
* \`\`\`js
|
|
180196
|
+
* import { load_${artifactName} } from '$houdini';
|
|
180197
|
+
* import type { PageLoad } from './$types';
|
|
180198
|
+
*
|
|
180199
|
+
* export const load: PageLoad = async (event) => {
|
|
180200
|
+
* const variables = {
|
|
180201
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
180202
|
+
* };
|
|
180203
|
+
*
|
|
180204
|
+
* return await load_${artifactName}({ event, variables });
|
|
180205
|
+
* };
|
|
180206
|
+
* \`\`\`
|
|
180207
|
+
*
|
|
180208
|
+
* ### Multiple stores to load
|
|
180209
|
+
* You can trigger them in parallel with \`loadAll\` function
|
|
180210
|
+
*
|
|
180211
|
+
* \`\`\`js
|
|
180212
|
+
* import { loadAll, load_${artifactName} } from '$houdini';
|
|
180213
|
+
* import type { PageLoad } from './$types';
|
|
180214
|
+
*
|
|
180215
|
+
* export const load: PageLoad = async (event) => {
|
|
180216
|
+
* const variables = {
|
|
180217
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
180218
|
+
* };
|
|
180219
|
+
*
|
|
180220
|
+
* return await await loadAll(
|
|
180221
|
+
* load_${artifactName}({ event, variables }),
|
|
180222
|
+
* // load_ANOTHER_STORE
|
|
180223
|
+
* );
|
|
180224
|
+
* };
|
|
180225
|
+
* \`\`\`
|
|
180226
|
+
*/
|
|
180161
180227
|
export declare const load_${artifactName}: (params: QueryStoreFetchParams<${_data}, ${_input}>) => Promise<{${artifactName}: ${storeName}}>
|
|
180162
180228
|
|
|
180229
|
+
export const ${globalStoreName}: ${storeName}
|
|
180230
|
+
|
|
180163
180231
|
export default ${storeName}
|
|
180164
180232
|
`;
|
|
180165
180233
|
await Promise.all([
|
|
@@ -179842,6 +179842,24 @@ async function svelteKitGenerator(framework2, { config: config2 }) {
|
|
|
179842
179842
|
config2,
|
|
179843
179843
|
uniquePageQueries
|
|
179844
179844
|
);
|
|
179845
|
+
const layout_append_beforeLoad = append_beforeLoad(beforeLayoutLoad, "Layout");
|
|
179846
|
+
const page_append_beforeLoad = append_beforeLoad(beforePageLoad, "Page");
|
|
179847
|
+
const layout_append_afterLoad = append_afterLoad(
|
|
179848
|
+
afterLayoutLoad,
|
|
179849
|
+
"Layout",
|
|
179850
|
+
layoutQueries
|
|
179851
|
+
);
|
|
179852
|
+
const page_append_afterLoad = append_afterLoad(afterPageLoad, "Page", pageQueries);
|
|
179853
|
+
const layout_append_onError = append_onError(
|
|
179854
|
+
onLayoutError,
|
|
179855
|
+
"Layout",
|
|
179856
|
+
layoutQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179857
|
+
);
|
|
179858
|
+
const page_append_onError = append_onError(
|
|
179859
|
+
onPageError,
|
|
179860
|
+
"Page",
|
|
179861
|
+
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179862
|
+
);
|
|
179845
179863
|
const splitString = skTypeString.split("\n\n");
|
|
179846
179864
|
let typeImports = splitString[0];
|
|
179847
179865
|
let utilityTypes = splitString[1];
|
|
@@ -179864,17 +179882,7 @@ import type { ${functionImportsToBring.join(
|
|
|
179864
179882
|
const layoutParams = `${layoutQueries.length > 0 && !utilityTypes.includes("LayoutParams") ? "\ntype LayoutParams = LayoutLoadEvent['params'];" : ""}`;
|
|
179865
179883
|
const pageParams = `${pageQueries.length > 0 && !utilityTypes.includes("PageParams") ? "\ntype PageParams = PageLoadEvent['params'];" : ""}`;
|
|
179866
179884
|
utilityTypes = utilityTypes.concat(layoutParams).concat(pageParams).replaceAll(/\$types\.js/gm, "$houdini");
|
|
179867
|
-
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(
|
|
179868
|
-
append_onError(
|
|
179869
|
-
onPageError,
|
|
179870
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179871
|
-
)
|
|
179872
|
-
).concat(
|
|
179873
|
-
append_onError(
|
|
179874
|
-
onLayoutError,
|
|
179875
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
179876
|
-
)
|
|
179877
|
-
).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
179885
|
+
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(layout_append_beforeLoad).concat(page_append_beforeLoad).concat(layout_append_afterLoad).concat(page_append_afterLoad).concat(layout_append_onError).concat(page_append_onError).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
179878
179886
|
/(?<=LayoutData = )([\s\S]*?)(?=;)/,
|
|
179879
179887
|
`Expand<$1 & { ${layoutQueries.map((query) => {
|
|
179880
179888
|
const name2 = query.name.value;
|
|
@@ -179938,15 +179946,15 @@ type LoadInput = { ${queries.filter((query) => query.variableDefinitions?.length
|
|
|
179938
179946
|
return [name2, name2 + "$input"].join(": ");
|
|
179939
179947
|
}).join("; ")} };` : ""}`;
|
|
179940
179948
|
}
|
|
179941
|
-
function append_afterLoad(
|
|
179949
|
+
function append_afterLoad(afterLoad, type, queries) {
|
|
179942
179950
|
return afterLoad ? `
|
|
179943
|
-
type AfterLoadReturn = ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad
|
|
179951
|
+
type AfterLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad>>;
|
|
179944
179952
|
type AfterLoadData = {
|
|
179945
179953
|
${internal_append_afterLoad(queries)}
|
|
179946
179954
|
};
|
|
179947
179955
|
|
|
179948
179956
|
export type AfterLoadEvent = {
|
|
179949
|
-
event:
|
|
179957
|
+
event: ${type}LoadEvent
|
|
179950
179958
|
data: AfterLoadData
|
|
179951
179959
|
input: ${queries.filter((q) => q.variableDefinitions?.length).length ? "LoadInput" : "{}"}
|
|
179952
179960
|
};
|
|
@@ -179958,15 +179966,15 @@ function internal_append_afterLoad(queries) {
|
|
|
179958
179966
|
return [name2, name2 + "$result"].join(": ");
|
|
179959
179967
|
}).join(";\n ")}`;
|
|
179960
179968
|
}
|
|
179961
|
-
function append_beforeLoad(beforeLoad) {
|
|
179969
|
+
function append_beforeLoad(beforeLoad, type) {
|
|
179962
179970
|
return beforeLoad ? `
|
|
179963
|
-
export type BeforeLoadEvent =
|
|
179964
|
-
type BeforeLoadReturn = ReturnType<typeof import('
|
|
179971
|
+
export type BeforeLoadEvent = ${type}LoadEvent;
|
|
179972
|
+
type BeforeLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').beforeLoad>>;
|
|
179965
179973
|
` : "";
|
|
179966
179974
|
}
|
|
179967
|
-
function append_onError(onError, hasLoadInput) {
|
|
179975
|
+
function append_onError(onError, type, hasLoadInput) {
|
|
179968
179976
|
return onError ? `
|
|
179969
|
-
type OnErrorReturn = ReturnType<typeof import('
|
|
179977
|
+
type OnErrorReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').onError>>;
|
|
179970
179978
|
export type OnErrorEvent = { event: Kit.LoadEvent, input: ${hasLoadInput ? "LoadInput" : "{}"}, error: Error | Error[] };
|
|
179971
179979
|
` : "";
|
|
179972
179980
|
}
|
|
@@ -180115,8 +180123,6 @@ async function queryStore({ config: config2, plugin_root }, doc) {
|
|
|
180115
180123
|
const storeData = `${statement}
|
|
180116
180124
|
import artifact from '$houdini/artifacts/${artifactName}'
|
|
180117
180125
|
|
|
180118
|
-
// create the query store
|
|
180119
|
-
|
|
180120
180126
|
export class ${storeName} extends ${store_class} {
|
|
180121
180127
|
constructor() {
|
|
180122
180128
|
super({
|
|
@@ -180146,16 +180152,78 @@ export default ${globalStoreName}
|
|
|
180146
180152
|
const typeDefs = `import type { ${_input}, ${_data}, ${store_class}, QueryStoreFetchParams} from '$houdini'
|
|
180147
180153
|
|
|
180148
180154
|
export declare class ${storeName} extends ${store_class}<${_data}, ${_input}> {
|
|
180155
|
+
/**
|
|
180156
|
+
* ### Route Loads
|
|
180157
|
+
* In a route's load function, manually instantiating a store can be used to look at the result:
|
|
180158
|
+
*
|
|
180159
|
+
* \`\`\`js
|
|
180160
|
+
* export async function load(event) {
|
|
180161
|
+
* const store = new ${storeName}Store()
|
|
180162
|
+
* const { data } = await store.fetch({event})
|
|
180163
|
+
* console.log('do something with', data)
|
|
180164
|
+
*
|
|
180165
|
+
* return {
|
|
180166
|
+
* ${storeName}: store,
|
|
180167
|
+
* }
|
|
180168
|
+
* }
|
|
180169
|
+
*
|
|
180170
|
+
* \`\`\`
|
|
180171
|
+
*
|
|
180172
|
+
* ### Client Side Loading
|
|
180173
|
+
* When performing a client-side only fetch, the best practice to use a store _manually_ is to do the following:
|
|
180174
|
+
*
|
|
180175
|
+
* \`\`\`js
|
|
180176
|
+
* const store = new ${storeName}Store()
|
|
180177
|
+
*
|
|
180178
|
+
* $: browser && store.fetch({ variables });
|
|
180179
|
+
* \`\`\`
|
|
180180
|
+
*/
|
|
180149
180181
|
constructor() {
|
|
180150
180182
|
// @ts-ignore
|
|
180151
180183
|
super({})
|
|
180152
180184
|
}
|
|
180153
180185
|
}
|
|
180154
180186
|
|
|
180155
|
-
|
|
180156
|
-
|
|
180187
|
+
/**
|
|
180188
|
+
* ### Manual Loads
|
|
180189
|
+
* Usually your load function will look like this:
|
|
180190
|
+
*
|
|
180191
|
+
* \`\`\`js
|
|
180192
|
+
* import { load_${artifactName} } from '$houdini';
|
|
180193
|
+
* import type { PageLoad } from './$types';
|
|
180194
|
+
*
|
|
180195
|
+
* export const load: PageLoad = async (event) => {
|
|
180196
|
+
* const variables = {
|
|
180197
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
180198
|
+
* };
|
|
180199
|
+
*
|
|
180200
|
+
* return await load_${artifactName}({ event, variables });
|
|
180201
|
+
* };
|
|
180202
|
+
* \`\`\`
|
|
180203
|
+
*
|
|
180204
|
+
* ### Multiple stores to load
|
|
180205
|
+
* You can trigger them in parallel with \`loadAll\` function
|
|
180206
|
+
*
|
|
180207
|
+
* \`\`\`js
|
|
180208
|
+
* import { loadAll, load_${artifactName} } from '$houdini';
|
|
180209
|
+
* import type { PageLoad } from './$types';
|
|
180210
|
+
*
|
|
180211
|
+
* export const load: PageLoad = async (event) => {
|
|
180212
|
+
* const variables = {
|
|
180213
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
180214
|
+
* };
|
|
180215
|
+
*
|
|
180216
|
+
* return await await loadAll(
|
|
180217
|
+
* load_${artifactName}({ event, variables }),
|
|
180218
|
+
* // load_ANOTHER_STORE
|
|
180219
|
+
* );
|
|
180220
|
+
* };
|
|
180221
|
+
* \`\`\`
|
|
180222
|
+
*/
|
|
180157
180223
|
export declare const load_${artifactName}: (params: QueryStoreFetchParams<${_data}, ${_input}>) => Promise<{${artifactName}: ${storeName}}>
|
|
180158
180224
|
|
|
180225
|
+
export const ${globalStoreName}: ${storeName}
|
|
180226
|
+
|
|
180159
180227
|
export default ${storeName}
|
|
180160
180228
|
`;
|
|
180161
180229
|
await Promise.all([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
2
2
|
import { Subscriber } from 'svelte/store';
|
|
3
|
-
import {
|
|
3
|
+
import { ClientFetchParams, LoadEventFetchParams, QueryStore, QueryStoreFetchParams, RequestEventFetchParams, StoreConfig } from '../query';
|
|
4
4
|
import { CursorHandlers } from './cursor';
|
|
5
5
|
import { OffsetHandlers } from './offset';
|
|
6
6
|
import { PageInfo } from './pageInfo';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FetchContext } from '$houdini/runtime/lib/network';
|
|
2
2
|
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
3
|
-
import { CachePolicy, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
|
|
4
|
-
import { SubscriptionSpec, HoudiniFetchContext } from '$houdini/runtime/lib/types';
|
|
3
|
+
import { CachePolicy, GraphQLObject, HoudiniFetchContext, QueryResult, SubscriptionSpec } from '$houdini/runtime/lib/types';
|
|
5
4
|
import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
|
|
6
5
|
import { Readable, Writable } from 'svelte/store';
|
|
7
6
|
import { BaseStore } from './store';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
2
2
|
import { Subscriber } from 'svelte/store';
|
|
3
|
-
import {
|
|
3
|
+
import { ClientFetchParams, LoadEventFetchParams, QueryStore, QueryStoreFetchParams, RequestEventFetchParams, StoreConfig } from '../query';
|
|
4
4
|
import { CursorHandlers } from './cursor';
|
|
5
5
|
import { OffsetHandlers } from './offset';
|
|
6
6
|
import { PageInfo } from './pageInfo';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FetchContext } from '$houdini/runtime/lib/network';
|
|
2
2
|
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
3
|
-
import { CachePolicy, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
|
|
4
|
-
import { SubscriptionSpec, HoudiniFetchContext } from '$houdini/runtime/lib/types';
|
|
3
|
+
import { CachePolicy, GraphQLObject, HoudiniFetchContext, QueryResult, SubscriptionSpec } from '$houdini/runtime/lib/types';
|
|
5
4
|
import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
|
|
6
5
|
import { Readable, Writable } from 'svelte/store';
|
|
7
6
|
import { BaseStore } from './store';
|
|
@@ -34,16 +34,15 @@ var log = __toESM(require("$houdini/runtime/lib/log"), 1);
|
|
|
34
34
|
var import_network = require("$houdini/runtime/lib/network");
|
|
35
35
|
var import_scalars = require("$houdini/runtime/lib/scalars");
|
|
36
36
|
var import_types = require("$houdini/runtime/lib/types");
|
|
37
|
-
var import_types2 = require("$houdini/runtime/lib/types");
|
|
38
37
|
var import_store = require("svelte/store");
|
|
39
38
|
var import_adapter = require("../adapter");
|
|
40
|
-
var
|
|
39
|
+
var import_network2 = require("../network");
|
|
41
40
|
var import_session = require("../session");
|
|
42
41
|
var import_store2 = require("./store");
|
|
43
42
|
class QueryStore extends import_store2.BaseStore {
|
|
44
43
|
artifact;
|
|
45
44
|
variables;
|
|
46
|
-
kind =
|
|
45
|
+
kind = import_types.CompiledQueryKind;
|
|
47
46
|
store;
|
|
48
47
|
lastVariables = null;
|
|
49
48
|
subscriptionSpec = null;
|
|
@@ -83,9 +82,7 @@ class QueryStore extends import_store2.BaseStore {
|
|
|
83
82
|
}
|
|
84
83
|
if (this.loadPending && isComponentFetch) {
|
|
85
84
|
log.error(`\u26A0\uFE0F Encountered fetch from your component while ${this.storeName}.load was running.
|
|
86
|
-
This will result in duplicate queries. If you are trying to ensure there is always a good value, please a CachePolicy instead
|
|
87
|
-
If this is leftovers from old versions of houdini, you can safely remove this \`${this.storeName}\`.fetch() from your component.
|
|
88
|
-
`);
|
|
85
|
+
This will result in duplicate queries. If you are trying to ensure there is always a good value, please a CachePolicy instead.`);
|
|
89
86
|
return (0, import_store.get)(this.store);
|
|
90
87
|
}
|
|
91
88
|
if (isComponentFetch) {
|
|
@@ -94,8 +91,7 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
|
|
|
94
91
|
if (isLoadFetch) {
|
|
95
92
|
this.loadPending = true;
|
|
96
93
|
}
|
|
97
|
-
const
|
|
98
|
-
const request = this.fetchAndCache({
|
|
94
|
+
const fetchArgs = {
|
|
99
95
|
config,
|
|
100
96
|
context,
|
|
101
97
|
artifact: this.artifact,
|
|
@@ -106,7 +102,22 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
|
|
|
106
102
|
this.loadPending = val;
|
|
107
103
|
this.setFetching(val);
|
|
108
104
|
}
|
|
109
|
-
}
|
|
105
|
+
};
|
|
106
|
+
const fakeAwait = import_adapter.clientStarted && import_adapter.isBrowser && !params?.blocking;
|
|
107
|
+
if (policy !== import_types.CachePolicy.NetworkOnly && fakeAwait) {
|
|
108
|
+
const cachedStore = await this.fetchAndCache({
|
|
109
|
+
...fetchArgs,
|
|
110
|
+
rawCacheOnlyResult: true
|
|
111
|
+
});
|
|
112
|
+
if (cachedStore && cachedStore?.result.data) {
|
|
113
|
+
this.store.update((s) => ({
|
|
114
|
+
...s,
|
|
115
|
+
data: cachedStore?.result.data,
|
|
116
|
+
isFetching: false
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const request = this.fetchAndCache(fetchArgs);
|
|
110
121
|
if (params.then) {
|
|
111
122
|
request.then((val) => params.then?.(val.result.data));
|
|
112
123
|
}
|
|
@@ -144,19 +155,23 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
|
|
|
144
155
|
ignoreFollowup,
|
|
145
156
|
setLoadPending,
|
|
146
157
|
policy,
|
|
147
|
-
context
|
|
158
|
+
context,
|
|
159
|
+
rawCacheOnlyResult = false
|
|
148
160
|
}) {
|
|
149
161
|
const request = await (0, import_network.fetchQuery)({
|
|
150
162
|
...context,
|
|
151
|
-
client: await (0,
|
|
163
|
+
client: await (0, import_network2.getCurrentClient)(),
|
|
152
164
|
setFetching: (val) => this.setFetching(val),
|
|
153
165
|
artifact,
|
|
154
166
|
variables,
|
|
155
167
|
cached,
|
|
156
|
-
policy,
|
|
168
|
+
policy: rawCacheOnlyResult ? import_types.CachePolicy.CacheOnly : policy,
|
|
157
169
|
context
|
|
158
170
|
});
|
|
159
171
|
const { result, source, partial } = request;
|
|
172
|
+
if (rawCacheOnlyResult) {
|
|
173
|
+
return request;
|
|
174
|
+
}
|
|
160
175
|
setLoadPending(false);
|
|
161
176
|
if (result.data && source !== import_types.DataSource.Cache) {
|
|
162
177
|
(0, import_runtime.getCache)().write({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
2
2
|
import { Subscriber } from 'svelte/store';
|
|
3
|
-
import {
|
|
3
|
+
import { ClientFetchParams, LoadEventFetchParams, QueryStore, QueryStoreFetchParams, RequestEventFetchParams, StoreConfig } from '../query';
|
|
4
4
|
import { CursorHandlers } from './cursor';
|
|
5
5
|
import { OffsetHandlers } from './offset';
|
|
6
6
|
import { PageInfo } from './pageInfo';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FetchContext } from '$houdini/runtime/lib/network';
|
|
2
2
|
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
3
|
-
import { CachePolicy, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
|
|
4
|
-
import { SubscriptionSpec, HoudiniFetchContext } from '$houdini/runtime/lib/types';
|
|
3
|
+
import { CachePolicy, GraphQLObject, HoudiniFetchContext, QueryResult, SubscriptionSpec } from '$houdini/runtime/lib/types';
|
|
5
4
|
import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
|
|
6
5
|
import { Readable, Writable } from 'svelte/store';
|
|
7
6
|
import { BaseStore } from './store';
|
|
@@ -3,12 +3,13 @@ import { deepEquals } from "$houdini/runtime/lib/deepEquals";
|
|
|
3
3
|
import * as log from "$houdini/runtime/lib/log";
|
|
4
4
|
import { fetchQuery } from "$houdini/runtime/lib/network";
|
|
5
5
|
import { marshalInputs, unmarshalSelection } from "$houdini/runtime/lib/scalars";
|
|
6
|
-
import { CachePolicy, DataSource } from "$houdini/runtime/lib/types";
|
|
7
6
|
import {
|
|
8
|
-
|
|
7
|
+
CachePolicy,
|
|
8
|
+
CompiledQueryKind,
|
|
9
|
+
DataSource
|
|
9
10
|
} from "$houdini/runtime/lib/types";
|
|
10
11
|
import { get, writable } from "svelte/store";
|
|
11
|
-
import { clientStarted,
|
|
12
|
+
import { clientStarted, error, isBrowser } from "../adapter";
|
|
12
13
|
import { getCurrentClient } from "../network";
|
|
13
14
|
import { getSession } from "../session";
|
|
14
15
|
import { BaseStore } from "./store";
|
|
@@ -55,9 +56,7 @@ class QueryStore extends BaseStore {
|
|
|
55
56
|
}
|
|
56
57
|
if (this.loadPending && isComponentFetch) {
|
|
57
58
|
log.error(`\u26A0\uFE0F Encountered fetch from your component while ${this.storeName}.load was running.
|
|
58
|
-
This will result in duplicate queries. If you are trying to ensure there is always a good value, please a CachePolicy instead
|
|
59
|
-
If this is leftovers from old versions of houdini, you can safely remove this \`${this.storeName}\`.fetch() from your component.
|
|
60
|
-
`);
|
|
59
|
+
This will result in duplicate queries. If you are trying to ensure there is always a good value, please a CachePolicy instead.`);
|
|
61
60
|
return get(this.store);
|
|
62
61
|
}
|
|
63
62
|
if (isComponentFetch) {
|
|
@@ -66,8 +65,7 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
|
|
|
66
65
|
if (isLoadFetch) {
|
|
67
66
|
this.loadPending = true;
|
|
68
67
|
}
|
|
69
|
-
const
|
|
70
|
-
const request = this.fetchAndCache({
|
|
68
|
+
const fetchArgs = {
|
|
71
69
|
config,
|
|
72
70
|
context,
|
|
73
71
|
artifact: this.artifact,
|
|
@@ -78,7 +76,22 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
|
|
|
78
76
|
this.loadPending = val;
|
|
79
77
|
this.setFetching(val);
|
|
80
78
|
}
|
|
81
|
-
}
|
|
79
|
+
};
|
|
80
|
+
const fakeAwait = clientStarted && isBrowser && !params?.blocking;
|
|
81
|
+
if (policy !== CachePolicy.NetworkOnly && fakeAwait) {
|
|
82
|
+
const cachedStore = await this.fetchAndCache({
|
|
83
|
+
...fetchArgs,
|
|
84
|
+
rawCacheOnlyResult: true
|
|
85
|
+
});
|
|
86
|
+
if (cachedStore && cachedStore?.result.data) {
|
|
87
|
+
this.store.update((s) => ({
|
|
88
|
+
...s,
|
|
89
|
+
data: cachedStore?.result.data,
|
|
90
|
+
isFetching: false
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const request = this.fetchAndCache(fetchArgs);
|
|
82
95
|
if (params.then) {
|
|
83
96
|
request.then((val) => params.then?.(val.result.data));
|
|
84
97
|
}
|
|
@@ -116,7 +129,8 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
|
|
|
116
129
|
ignoreFollowup,
|
|
117
130
|
setLoadPending,
|
|
118
131
|
policy,
|
|
119
|
-
context
|
|
132
|
+
context,
|
|
133
|
+
rawCacheOnlyResult = false
|
|
120
134
|
}) {
|
|
121
135
|
const request = await fetchQuery({
|
|
122
136
|
...context,
|
|
@@ -125,10 +139,13 @@ If this is leftovers from old versions of houdini, you can safely remove this \`
|
|
|
125
139
|
artifact,
|
|
126
140
|
variables,
|
|
127
141
|
cached,
|
|
128
|
-
policy,
|
|
142
|
+
policy: rawCacheOnlyResult ? CachePolicy.CacheOnly : policy,
|
|
129
143
|
context
|
|
130
144
|
});
|
|
131
145
|
const { result, source, partial } = request;
|
|
146
|
+
if (rawCacheOnlyResult) {
|
|
147
|
+
return request;
|
|
148
|
+
}
|
|
132
149
|
setLoadPending(false);
|
|
133
150
|
if (result.data && source !== DataSource.Cache) {
|
|
134
151
|
getCache().write({
|
package/build/test-cjs/index.js
CHANGED
|
@@ -294501,6 +294501,24 @@ async function svelteKitGenerator(framework2, { config: config3 }) {
|
|
|
294501
294501
|
config3,
|
|
294502
294502
|
uniquePageQueries
|
|
294503
294503
|
);
|
|
294504
|
+
const layout_append_beforeLoad = append_beforeLoad(beforeLayoutLoad, "Layout");
|
|
294505
|
+
const page_append_beforeLoad = append_beforeLoad(beforePageLoad, "Page");
|
|
294506
|
+
const layout_append_afterLoad = append_afterLoad(
|
|
294507
|
+
afterLayoutLoad,
|
|
294508
|
+
"Layout",
|
|
294509
|
+
layoutQueries
|
|
294510
|
+
);
|
|
294511
|
+
const page_append_afterLoad = append_afterLoad(afterPageLoad, "Page", pageQueries);
|
|
294512
|
+
const layout_append_onError = append_onError(
|
|
294513
|
+
onLayoutError,
|
|
294514
|
+
"Layout",
|
|
294515
|
+
layoutQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294516
|
+
);
|
|
294517
|
+
const page_append_onError = append_onError(
|
|
294518
|
+
onPageError,
|
|
294519
|
+
"Page",
|
|
294520
|
+
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294521
|
+
);
|
|
294504
294522
|
const splitString = skTypeString.split("\n\n");
|
|
294505
294523
|
let typeImports = splitString[0];
|
|
294506
294524
|
let utilityTypes = splitString[1];
|
|
@@ -294523,17 +294541,7 @@ import type { ${functionImportsToBring.join(
|
|
|
294523
294541
|
const layoutParams = `${layoutQueries.length > 0 && !utilityTypes.includes("LayoutParams") ? "\ntype LayoutParams = LayoutLoadEvent['params'];" : ""}`;
|
|
294524
294542
|
const pageParams = `${pageQueries.length > 0 && !utilityTypes.includes("PageParams") ? "\ntype PageParams = PageLoadEvent['params'];" : ""}`;
|
|
294525
294543
|
utilityTypes = utilityTypes.concat(layoutParams).concat(pageParams).replaceAll(/\$types\.js/gm, "$houdini");
|
|
294526
|
-
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(
|
|
294527
|
-
append_onError(
|
|
294528
|
-
onPageError,
|
|
294529
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294530
|
-
)
|
|
294531
|
-
).concat(
|
|
294532
|
-
append_onError(
|
|
294533
|
-
onLayoutError,
|
|
294534
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294535
|
-
)
|
|
294536
|
-
).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
294544
|
+
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(layout_append_beforeLoad).concat(page_append_beforeLoad).concat(layout_append_afterLoad).concat(page_append_afterLoad).concat(layout_append_onError).concat(page_append_onError).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
294537
294545
|
/(?<=LayoutData = )([\s\S]*?)(?=;)/,
|
|
294538
294546
|
`Expand<$1 & { ${layoutQueries.map((query) => {
|
|
294539
294547
|
const name2 = query.name.value;
|
|
@@ -294597,15 +294605,15 @@ type LoadInput = { ${queries.filter((query) => query.variableDefinitions?.length
|
|
|
294597
294605
|
return [name2, name2 + "$input"].join(": ");
|
|
294598
294606
|
}).join("; ")} };` : ""}`;
|
|
294599
294607
|
}
|
|
294600
|
-
function append_afterLoad(
|
|
294608
|
+
function append_afterLoad(afterLoad, type, queries) {
|
|
294601
294609
|
return afterLoad ? `
|
|
294602
|
-
type AfterLoadReturn = ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad
|
|
294610
|
+
type AfterLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad>>;
|
|
294603
294611
|
type AfterLoadData = {
|
|
294604
294612
|
${internal_append_afterLoad(queries)}
|
|
294605
294613
|
};
|
|
294606
294614
|
|
|
294607
294615
|
export type AfterLoadEvent = {
|
|
294608
|
-
event:
|
|
294616
|
+
event: ${type}LoadEvent
|
|
294609
294617
|
data: AfterLoadData
|
|
294610
294618
|
input: ${queries.filter((q) => q.variableDefinitions?.length).length ? "LoadInput" : "{}"}
|
|
294611
294619
|
};
|
|
@@ -294617,15 +294625,15 @@ function internal_append_afterLoad(queries) {
|
|
|
294617
294625
|
return [name2, name2 + "$result"].join(": ");
|
|
294618
294626
|
}).join(";\n ")}`;
|
|
294619
294627
|
}
|
|
294620
|
-
function append_beforeLoad(beforeLoad) {
|
|
294628
|
+
function append_beforeLoad(beforeLoad, type) {
|
|
294621
294629
|
return beforeLoad ? `
|
|
294622
|
-
export type BeforeLoadEvent =
|
|
294623
|
-
type BeforeLoadReturn = ReturnType<typeof import('
|
|
294630
|
+
export type BeforeLoadEvent = ${type}LoadEvent;
|
|
294631
|
+
type BeforeLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').beforeLoad>>;
|
|
294624
294632
|
` : "";
|
|
294625
294633
|
}
|
|
294626
|
-
function append_onError(onError, hasLoadInput) {
|
|
294634
|
+
function append_onError(onError, type, hasLoadInput) {
|
|
294627
294635
|
return onError ? `
|
|
294628
|
-
type OnErrorReturn = ReturnType<typeof import('
|
|
294636
|
+
type OnErrorReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').onError>>;
|
|
294629
294637
|
export type OnErrorEvent = { event: Kit.LoadEvent, input: ${hasLoadInput ? "LoadInput" : "{}"}, error: Error | Error[] };
|
|
294630
294638
|
` : "";
|
|
294631
294639
|
}
|
|
@@ -294774,8 +294782,6 @@ async function queryStore({ config: config3, plugin_root }, doc) {
|
|
|
294774
294782
|
const storeData = `${statement}
|
|
294775
294783
|
import artifact from '$houdini/artifacts/${artifactName}'
|
|
294776
294784
|
|
|
294777
|
-
// create the query store
|
|
294778
|
-
|
|
294779
294785
|
export class ${storeName} extends ${store_class} {
|
|
294780
294786
|
constructor() {
|
|
294781
294787
|
super({
|
|
@@ -294805,16 +294811,78 @@ export default ${globalStoreName}
|
|
|
294805
294811
|
const typeDefs = `import type { ${_input}, ${_data}, ${store_class}, QueryStoreFetchParams} from '$houdini'
|
|
294806
294812
|
|
|
294807
294813
|
export declare class ${storeName} extends ${store_class}<${_data}, ${_input}> {
|
|
294814
|
+
/**
|
|
294815
|
+
* ### Route Loads
|
|
294816
|
+
* In a route's load function, manually instantiating a store can be used to look at the result:
|
|
294817
|
+
*
|
|
294818
|
+
* \`\`\`js
|
|
294819
|
+
* export async function load(event) {
|
|
294820
|
+
* const store = new ${storeName}Store()
|
|
294821
|
+
* const { data } = await store.fetch({event})
|
|
294822
|
+
* console.log('do something with', data)
|
|
294823
|
+
*
|
|
294824
|
+
* return {
|
|
294825
|
+
* ${storeName}: store,
|
|
294826
|
+
* }
|
|
294827
|
+
* }
|
|
294828
|
+
*
|
|
294829
|
+
* \`\`\`
|
|
294830
|
+
*
|
|
294831
|
+
* ### Client Side Loading
|
|
294832
|
+
* When performing a client-side only fetch, the best practice to use a store _manually_ is to do the following:
|
|
294833
|
+
*
|
|
294834
|
+
* \`\`\`js
|
|
294835
|
+
* const store = new ${storeName}Store()
|
|
294836
|
+
*
|
|
294837
|
+
* $: browser && store.fetch({ variables });
|
|
294838
|
+
* \`\`\`
|
|
294839
|
+
*/
|
|
294808
294840
|
constructor() {
|
|
294809
294841
|
// @ts-ignore
|
|
294810
294842
|
super({})
|
|
294811
294843
|
}
|
|
294812
294844
|
}
|
|
294813
294845
|
|
|
294814
|
-
|
|
294815
|
-
|
|
294846
|
+
/**
|
|
294847
|
+
* ### Manual Loads
|
|
294848
|
+
* Usually your load function will look like this:
|
|
294849
|
+
*
|
|
294850
|
+
* \`\`\`js
|
|
294851
|
+
* import { load_${artifactName} } from '$houdini';
|
|
294852
|
+
* import type { PageLoad } from './$types';
|
|
294853
|
+
*
|
|
294854
|
+
* export const load: PageLoad = async (event) => {
|
|
294855
|
+
* const variables = {
|
|
294856
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
294857
|
+
* };
|
|
294858
|
+
*
|
|
294859
|
+
* return await load_${artifactName}({ event, variables });
|
|
294860
|
+
* };
|
|
294861
|
+
* \`\`\`
|
|
294862
|
+
*
|
|
294863
|
+
* ### Multiple stores to load
|
|
294864
|
+
* You can trigger them in parallel with \`loadAll\` function
|
|
294865
|
+
*
|
|
294866
|
+
* \`\`\`js
|
|
294867
|
+
* import { loadAll, load_${artifactName} } from '$houdini';
|
|
294868
|
+
* import type { PageLoad } from './$types';
|
|
294869
|
+
*
|
|
294870
|
+
* export const load: PageLoad = async (event) => {
|
|
294871
|
+
* const variables = {
|
|
294872
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
294873
|
+
* };
|
|
294874
|
+
*
|
|
294875
|
+
* return await await loadAll(
|
|
294876
|
+
* load_${artifactName}({ event, variables }),
|
|
294877
|
+
* // load_ANOTHER_STORE
|
|
294878
|
+
* );
|
|
294879
|
+
* };
|
|
294880
|
+
* \`\`\`
|
|
294881
|
+
*/
|
|
294816
294882
|
export declare const load_${artifactName}: (params: QueryStoreFetchParams<${_data}, ${_input}>) => Promise<{${artifactName}: ${storeName}}>
|
|
294817
294883
|
|
|
294884
|
+
export const ${globalStoreName}: ${storeName}
|
|
294885
|
+
|
|
294818
294886
|
export default ${storeName}
|
|
294819
294887
|
`;
|
|
294820
294888
|
await Promise.all([
|
package/build/test-esm/index.js
CHANGED
|
@@ -294490,6 +294490,24 @@ async function svelteKitGenerator(framework2, { config: config3 }) {
|
|
|
294490
294490
|
config3,
|
|
294491
294491
|
uniquePageQueries
|
|
294492
294492
|
);
|
|
294493
|
+
const layout_append_beforeLoad = append_beforeLoad(beforeLayoutLoad, "Layout");
|
|
294494
|
+
const page_append_beforeLoad = append_beforeLoad(beforePageLoad, "Page");
|
|
294495
|
+
const layout_append_afterLoad = append_afterLoad(
|
|
294496
|
+
afterLayoutLoad,
|
|
294497
|
+
"Layout",
|
|
294498
|
+
layoutQueries
|
|
294499
|
+
);
|
|
294500
|
+
const page_append_afterLoad = append_afterLoad(afterPageLoad, "Page", pageQueries);
|
|
294501
|
+
const layout_append_onError = append_onError(
|
|
294502
|
+
onLayoutError,
|
|
294503
|
+
"Layout",
|
|
294504
|
+
layoutQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294505
|
+
);
|
|
294506
|
+
const page_append_onError = append_onError(
|
|
294507
|
+
onPageError,
|
|
294508
|
+
"Page",
|
|
294509
|
+
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294510
|
+
);
|
|
294493
294511
|
const splitString = skTypeString.split("\n\n");
|
|
294494
294512
|
let typeImports = splitString[0];
|
|
294495
294513
|
let utilityTypes = splitString[1];
|
|
@@ -294512,17 +294530,7 @@ import type { ${functionImportsToBring.join(
|
|
|
294512
294530
|
const layoutParams = `${layoutQueries.length > 0 && !utilityTypes.includes("LayoutParams") ? "\ntype LayoutParams = LayoutLoadEvent['params'];" : ""}`;
|
|
294513
294531
|
const pageParams = `${pageQueries.length > 0 && !utilityTypes.includes("PageParams") ? "\ntype PageParams = PageLoadEvent['params'];" : ""}`;
|
|
294514
294532
|
utilityTypes = utilityTypes.concat(layoutParams).concat(pageParams).replaceAll(/\$types\.js/gm, "$houdini");
|
|
294515
|
-
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(
|
|
294516
|
-
append_onError(
|
|
294517
|
-
onPageError,
|
|
294518
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294519
|
-
)
|
|
294520
|
-
).concat(
|
|
294521
|
-
append_onError(
|
|
294522
|
-
onLayoutError,
|
|
294523
|
-
pageQueries.filter((x4) => x4.variableDefinitions?.length).length > 0
|
|
294524
|
-
)
|
|
294525
|
-
).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
294533
|
+
typeExports = typeExports.concat(append_loadInput(layoutQueries)).concat(append_loadInput(pageQueries)).concat(layout_append_beforeLoad).concat(page_append_beforeLoad).concat(layout_append_afterLoad).concat(page_append_afterLoad).concat(layout_append_onError).concat(page_append_onError).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).replace(
|
|
294526
294534
|
/(?<=LayoutData = )([\s\S]*?)(?=;)/,
|
|
294527
294535
|
`Expand<$1 & { ${layoutQueries.map((query) => {
|
|
294528
294536
|
const name2 = query.name.value;
|
|
@@ -294586,15 +294594,15 @@ type LoadInput = { ${queries.filter((query) => query.variableDefinitions?.length
|
|
|
294586
294594
|
return [name2, name2 + "$input"].join(": ");
|
|
294587
294595
|
}).join("; ")} };` : ""}`;
|
|
294588
294596
|
}
|
|
294589
|
-
function append_afterLoad(
|
|
294597
|
+
function append_afterLoad(afterLoad, type, queries) {
|
|
294590
294598
|
return afterLoad ? `
|
|
294591
|
-
type AfterLoadReturn = ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad
|
|
294599
|
+
type AfterLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad>>;
|
|
294592
294600
|
type AfterLoadData = {
|
|
294593
294601
|
${internal_append_afterLoad(queries)}
|
|
294594
294602
|
};
|
|
294595
294603
|
|
|
294596
294604
|
export type AfterLoadEvent = {
|
|
294597
|
-
event:
|
|
294605
|
+
event: ${type}LoadEvent
|
|
294598
294606
|
data: AfterLoadData
|
|
294599
294607
|
input: ${queries.filter((q) => q.variableDefinitions?.length).length ? "LoadInput" : "{}"}
|
|
294600
294608
|
};
|
|
@@ -294606,15 +294614,15 @@ function internal_append_afterLoad(queries) {
|
|
|
294606
294614
|
return [name2, name2 + "$result"].join(": ");
|
|
294607
294615
|
}).join(";\n ")}`;
|
|
294608
294616
|
}
|
|
294609
|
-
function append_beforeLoad(beforeLoad) {
|
|
294617
|
+
function append_beforeLoad(beforeLoad, type) {
|
|
294610
294618
|
return beforeLoad ? `
|
|
294611
|
-
export type BeforeLoadEvent =
|
|
294612
|
-
type BeforeLoadReturn = ReturnType<typeof import('
|
|
294619
|
+
export type BeforeLoadEvent = ${type}LoadEvent;
|
|
294620
|
+
type BeforeLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').beforeLoad>>;
|
|
294613
294621
|
` : "";
|
|
294614
294622
|
}
|
|
294615
|
-
function append_onError(onError, hasLoadInput) {
|
|
294623
|
+
function append_onError(onError, type, hasLoadInput) {
|
|
294616
294624
|
return onError ? `
|
|
294617
|
-
type OnErrorReturn = ReturnType<typeof import('
|
|
294625
|
+
type OnErrorReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').onError>>;
|
|
294618
294626
|
export type OnErrorEvent = { event: Kit.LoadEvent, input: ${hasLoadInput ? "LoadInput" : "{}"}, error: Error | Error[] };
|
|
294619
294627
|
` : "";
|
|
294620
294628
|
}
|
|
@@ -294763,8 +294771,6 @@ async function queryStore({ config: config3, plugin_root }, doc) {
|
|
|
294763
294771
|
const storeData = `${statement}
|
|
294764
294772
|
import artifact from '$houdini/artifacts/${artifactName}'
|
|
294765
294773
|
|
|
294766
|
-
// create the query store
|
|
294767
|
-
|
|
294768
294774
|
export class ${storeName} extends ${store_class} {
|
|
294769
294775
|
constructor() {
|
|
294770
294776
|
super({
|
|
@@ -294794,16 +294800,78 @@ export default ${globalStoreName}
|
|
|
294794
294800
|
const typeDefs = `import type { ${_input}, ${_data}, ${store_class}, QueryStoreFetchParams} from '$houdini'
|
|
294795
294801
|
|
|
294796
294802
|
export declare class ${storeName} extends ${store_class}<${_data}, ${_input}> {
|
|
294803
|
+
/**
|
|
294804
|
+
* ### Route Loads
|
|
294805
|
+
* In a route's load function, manually instantiating a store can be used to look at the result:
|
|
294806
|
+
*
|
|
294807
|
+
* \`\`\`js
|
|
294808
|
+
* export async function load(event) {
|
|
294809
|
+
* const store = new ${storeName}Store()
|
|
294810
|
+
* const { data } = await store.fetch({event})
|
|
294811
|
+
* console.log('do something with', data)
|
|
294812
|
+
*
|
|
294813
|
+
* return {
|
|
294814
|
+
* ${storeName}: store,
|
|
294815
|
+
* }
|
|
294816
|
+
* }
|
|
294817
|
+
*
|
|
294818
|
+
* \`\`\`
|
|
294819
|
+
*
|
|
294820
|
+
* ### Client Side Loading
|
|
294821
|
+
* When performing a client-side only fetch, the best practice to use a store _manually_ is to do the following:
|
|
294822
|
+
*
|
|
294823
|
+
* \`\`\`js
|
|
294824
|
+
* const store = new ${storeName}Store()
|
|
294825
|
+
*
|
|
294826
|
+
* $: browser && store.fetch({ variables });
|
|
294827
|
+
* \`\`\`
|
|
294828
|
+
*/
|
|
294797
294829
|
constructor() {
|
|
294798
294830
|
// @ts-ignore
|
|
294799
294831
|
super({})
|
|
294800
294832
|
}
|
|
294801
294833
|
}
|
|
294802
294834
|
|
|
294803
|
-
|
|
294804
|
-
|
|
294835
|
+
/**
|
|
294836
|
+
* ### Manual Loads
|
|
294837
|
+
* Usually your load function will look like this:
|
|
294838
|
+
*
|
|
294839
|
+
* \`\`\`js
|
|
294840
|
+
* import { load_${artifactName} } from '$houdini';
|
|
294841
|
+
* import type { PageLoad } from './$types';
|
|
294842
|
+
*
|
|
294843
|
+
* export const load: PageLoad = async (event) => {
|
|
294844
|
+
* const variables = {
|
|
294845
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
294846
|
+
* };
|
|
294847
|
+
*
|
|
294848
|
+
* return await load_${artifactName}({ event, variables });
|
|
294849
|
+
* };
|
|
294850
|
+
* \`\`\`
|
|
294851
|
+
*
|
|
294852
|
+
* ### Multiple stores to load
|
|
294853
|
+
* You can trigger them in parallel with \`loadAll\` function
|
|
294854
|
+
*
|
|
294855
|
+
* \`\`\`js
|
|
294856
|
+
* import { loadAll, load_${artifactName} } from '$houdini';
|
|
294857
|
+
* import type { PageLoad } from './$types';
|
|
294858
|
+
*
|
|
294859
|
+
* export const load: PageLoad = async (event) => {
|
|
294860
|
+
* const variables = {
|
|
294861
|
+
* id: // Something like: event.url.searchParams.get('id')
|
|
294862
|
+
* };
|
|
294863
|
+
*
|
|
294864
|
+
* return await await loadAll(
|
|
294865
|
+
* load_${artifactName}({ event, variables }),
|
|
294866
|
+
* // load_ANOTHER_STORE
|
|
294867
|
+
* );
|
|
294868
|
+
* };
|
|
294869
|
+
* \`\`\`
|
|
294870
|
+
*/
|
|
294805
294871
|
export declare const load_${artifactName}: (params: QueryStoreFetchParams<${_data}, ${_input}>) => Promise<{${artifactName}: ${storeName}}>
|
|
294806
294872
|
|
|
294873
|
+
export const ${globalStoreName}: ${storeName}
|
|
294874
|
+
|
|
294807
294875
|
export default ${storeName}
|
|
294808
294876
|
`;
|
|
294809
294877
|
await Promise.all([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini-svelte",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.13",
|
|
4
4
|
"description": "The svelte plugin for houdini",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"ast-types": "^0.15.1",
|
|
24
24
|
"estree-walker": "^3.0.1",
|
|
25
25
|
"graphql": "^15.8.0",
|
|
26
|
-
"houdini": "^0.17.11",
|
|
27
26
|
"minimatch": "^5.1.0",
|
|
28
27
|
"recast": "^0.21.5",
|
|
29
|
-
"svelte": "^3.52.0"
|
|
28
|
+
"svelte": "^3.52.0",
|
|
29
|
+
"houdini": "^0.17.13"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/minimatch": "^5.1.2",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"vitest": "^0.23.4",
|
|
34
|
+
"scripts": "^1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"graphql": "^14.0.0 || ^15.0.0"
|