Skip to content

Commit

Permalink
Fix generated types referencing onError, afterLoad and beforeLoad (#768)
Browse files Browse the repository at this point in the history
* Fix generated types referencing onError, afterLoad and beforeLoad

* Use consts for function names
  • Loading branch information
thokra authored Dec 15, 2022
1 parent df7800f commit b359ff0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-plums-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini-svelte': patch
---

Fix generated types referencing onError, afterLoad and beforeLoad
6 changes: 3 additions & 3 deletions packages/houdini-svelte/src/plugin/codegen/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function append_afterLoad(
) {
return afterLoad
? `
type AfterLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').afterLoad>>;
type AfterLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').${houdini_after_load_fn}>>;
type AfterLoadData = {
${internal_append_afterLoad(queries)}
};
Expand Down Expand Up @@ -326,15 +326,15 @@ function append_beforeLoad(beforeLoad: boolean, type: 'Layout' | 'Page') {
return beforeLoad
? `
export type BeforeLoadEvent = ${type}LoadEvent;
type BeforeLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').beforeLoad>>;
type BeforeLoadReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').${houdini_before_load_fn}>>;
`
: ''
}

function append_onError(onError: boolean, type: 'Layout' | 'Page', hasLoadInput: boolean) {
return onError
? `
type OnErrorReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').onError>>;
type OnErrorReturn = Awaited<ReturnType<typeof import('./+${type.toLowerCase()}').${houdini_on_error_fn}>>;
export type OnErrorEvent = { event: Kit.LoadEvent, input: ${
hasLoadInput ? 'LoadInput' : '{}'
}, error: Error | Error[] };
Expand Down
12 changes: 6 additions & 6 deletions packages/houdini-svelte/src/plugin/codegen/routes/kit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ test('generates types for layout onError', async function () {
MyPageLoad1Query: MyPageLoad1Query$input;
};
type OnErrorReturn = Awaited<ReturnType<typeof import("./+layout").onError>>;
type OnErrorReturn = Awaited<ReturnType<typeof import("./+layout")._houdini_onError>>;
export type OnErrorEvent = {
event: Kit.LoadEvent;
Expand Down Expand Up @@ -574,7 +574,7 @@ test('generates types for page onError', async function () {
MyPageLoad1Query: MyPageLoad1Query$input;
};
type OnErrorReturn = Awaited<ReturnType<typeof import("./+page").onError>>;
type OnErrorReturn = Awaited<ReturnType<typeof import("./+page")._houdini_onError>>;
export type OnErrorEvent = {
event: Kit.LoadEvent;
Expand Down Expand Up @@ -688,7 +688,7 @@ test('generates types for layout beforeLoad', async function () {
};
export type BeforeLoadEvent = LayoutLoadEvent;
type BeforeLoadReturn = Awaited<ReturnType<typeof import("./+layout").beforeLoad>>;
type BeforeLoadReturn = Awaited<ReturnType<typeof import("./+layout")._houdini_beforeLoad>>;
export type MyPageLoad1QueryVariables = VariableFunction<LayoutParams, MyPageLoad1Query$input>;
`)
})
Expand Down Expand Up @@ -795,7 +795,7 @@ test('generates types for page beforeLoad', async function () {
};
export type BeforeLoadEvent = PageLoadEvent;
type BeforeLoadReturn = Awaited<ReturnType<typeof import("./+page").beforeLoad>>;
type BeforeLoadReturn = Awaited<ReturnType<typeof import("./+page")._houdini_beforeLoad>>;
export type MyPageLoad1QueryVariables = VariableFunction<PageParams, MyPageLoad1Query$input>;
`)
})
Expand Down Expand Up @@ -901,7 +901,7 @@ test('generates types for layout afterLoad', async function () {
MyPageLoad1Query: MyPageLoad1Query$input;
};
type AfterLoadReturn = Awaited<ReturnType<typeof import("./+layout").afterLoad>>;
type AfterLoadReturn = Awaited<ReturnType<typeof import("./+layout")._houdini_afterLoad>>;
type AfterLoadData = {
MyPageLoad1Query: MyPageLoad1Query$result;
Expand Down Expand Up @@ -1019,7 +1019,7 @@ test('generates types for page afterLoad', async function () {
MyPageLoad1Query: MyPageLoad1Query$input;
};
type AfterLoadReturn = Awaited<ReturnType<typeof import("./+page").afterLoad>>;
type AfterLoadReturn = Awaited<ReturnType<typeof import("./+page")._houdini_afterLoad>>;
type AfterLoadData = {
MyPageLoad1Query: MyPageLoad1Query$result;
Expand Down

0 comments on commit b359ff0

Please sign in to comment.