From e7088923a5f525d8c08addc42ca6b278308fc230 Mon Sep 17 00:00:00 2001 From: Alec Aivazis Date: Fri, 24 Jan 2025 17:46:07 -0800 Subject: [PATCH 1/4] add abortController to query and mutation args --- packages/houdini-svelte/src/runtime/stores/mutation.ts | 3 +++ packages/houdini-svelte/src/runtime/stores/query.ts | 1 + packages/houdini-svelte/src/runtime/types.ts | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/packages/houdini-svelte/src/runtime/stores/mutation.ts b/packages/houdini-svelte/src/runtime/stores/mutation.ts index 92dac62382..0752e5d92d 100644 --- a/packages/houdini-svelte/src/runtime/stores/mutation.ts +++ b/packages/houdini-svelte/src/runtime/stores/mutation.ts @@ -23,6 +23,7 @@ export class MutationStore< metadata, fetch, event, + abortController: abort, ...mutationConfig }: { // @ts-ignore @@ -44,6 +45,7 @@ export class MutationStore< fetch: context.fetch, metadata, session: context.session, + abortController: abort, stuff: { ...mutationConfig, }, @@ -53,4 +55,5 @@ export class MutationStore< export type MutationConfig<_Result, _Input, _Optimistic> = { optimisticResponse?: _Optimistic + abortController?: AbortController } diff --git a/packages/houdini-svelte/src/runtime/stores/query.ts b/packages/houdini-svelte/src/runtime/stores/query.ts index 2e91733f04..983cb62ca0 100644 --- a/packages/houdini-svelte/src/runtime/stores/query.ts +++ b/packages/houdini-svelte/src/runtime/stores/query.ts @@ -182,6 +182,7 @@ This will result in duplicate queries. If you are trying to ensure there is alwa // if the CacheOnly request doesn't give us anything, // don't update the store silenceEcho: true, + abortController: params.abortController, }) } diff --git a/packages/houdini-svelte/src/runtime/types.ts b/packages/houdini-svelte/src/runtime/types.ts index f23b62f658..602b1c6709 100644 --- a/packages/houdini-svelte/src/runtime/types.ts +++ b/packages/houdini-svelte/src/runtime/types.ts @@ -83,6 +83,11 @@ type FetchGlobalParams<_Data extends GraphQLObject, _Input> = FetchParams<_Input * A function to call after the fetch happens (whether fake or not) */ then?: (val: _Data | null) => void | Promise + + /** + * An abort controller to abort the request + */ + abortController?: AbortController } export type LoadEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams< From 127cd102609d0b8fb6f84ea4bd14027f24211252 Mon Sep 17 00:00:00 2001 From: Alec Aivazis Date: Fri, 24 Jan 2025 17:51:28 -0800 Subject: [PATCH 2/4] add abort controller to react bindings --- packages/houdini-react/src/runtime/hooks/useMutation.ts | 3 +++ packages/houdini-svelte/src/runtime/types.ts | 5 ----- packages/houdini/src/runtime/lib/types.ts | 5 +++++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/houdini-react/src/runtime/hooks/useMutation.ts b/packages/houdini-react/src/runtime/hooks/useMutation.ts index 7f269e1fa6..bf1199f713 100644 --- a/packages/houdini-react/src/runtime/hooks/useMutation.ts +++ b/packages/houdini-react/src/runtime/hooks/useMutation.ts @@ -14,6 +14,7 @@ export type MutationHandler<_Result, _Input, _Optimistic extends GraphQLObject> metadata?: App.Metadata fetch?: typeof globalThis.fetch optimisticResponse?: _Optimistic + abortController?: AbortController }) => Promise> export function useMutation< @@ -39,12 +40,14 @@ export function useMutation< metadata, fetch, variables, + abortController, ...mutationConfig }) => observer.send({ variables, metadata, session, + abortController, stuff: { ...mutationConfig, }, diff --git a/packages/houdini-svelte/src/runtime/types.ts b/packages/houdini-svelte/src/runtime/types.ts index 602b1c6709..f23b62f658 100644 --- a/packages/houdini-svelte/src/runtime/types.ts +++ b/packages/houdini-svelte/src/runtime/types.ts @@ -83,11 +83,6 @@ type FetchGlobalParams<_Data extends GraphQLObject, _Input> = FetchParams<_Input * A function to call after the fetch happens (whether fake or not) */ then?: (val: _Data | null) => void | Promise - - /** - * An abort controller to abort the request - */ - abortController?: AbortController } export type LoadEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams< diff --git a/packages/houdini/src/runtime/lib/types.ts b/packages/houdini/src/runtime/lib/types.ts index abdde2f6e0..6906ed5ee8 100644 --- a/packages/houdini/src/runtime/lib/types.ts +++ b/packages/houdini/src/runtime/lib/types.ts @@ -317,6 +317,11 @@ export type FetchParams<_Input> = { */ // @ts-ignore metadata?: App.Metadata + + /** + * An abort controller to abort the operation + */ + abortController?: AbortController } export type FetchFn<_Data extends GraphQLObject, _Input = any> = ( From 8d4e76bc066336d10d9d3af97852401e04349439 Mon Sep 17 00:00:00 2001 From: Alec Aivazis Date: Fri, 24 Jan 2025 19:59:46 -0800 Subject: [PATCH 3/4] remove unnecessary rename --- packages/houdini-svelte/src/runtime/stores/mutation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/houdini-svelte/src/runtime/stores/mutation.ts b/packages/houdini-svelte/src/runtime/stores/mutation.ts index 0752e5d92d..ea5c0a5b12 100644 --- a/packages/houdini-svelte/src/runtime/stores/mutation.ts +++ b/packages/houdini-svelte/src/runtime/stores/mutation.ts @@ -23,7 +23,7 @@ export class MutationStore< metadata, fetch, event, - abortController: abort, + abortController, ...mutationConfig }: { // @ts-ignore @@ -45,7 +45,7 @@ export class MutationStore< fetch: context.fetch, metadata, session: context.session, - abortController: abort, + abortController, stuff: { ...mutationConfig, }, From 5f7f89777db3fe550184d7e020c8f2fb4f52ea4b Mon Sep 17 00:00:00 2001 From: Alec Aivazis Date: Fri, 24 Jan 2025 20:32:01 -0800 Subject: [PATCH 4/4] changeset --- .changeset/tender-cows-unite.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/tender-cows-unite.md diff --git a/.changeset/tender-cows-unite.md b/.changeset/tender-cows-unite.md new file mode 100644 index 0000000000..63ffcc446e --- /dev/null +++ b/.changeset/tender-cows-unite.md @@ -0,0 +1,7 @@ +--- +'houdini-svelte': patch +'houdini-react': patch +'houdini': patch +--- + +Add abortController argument to query and mutation handles