Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add abortController to query and mutation args #1426

Merged
merged 4 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tender-cows-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'houdini-svelte': patch
'houdini-react': patch
'houdini': patch
---

Add abortController argument to query and mutation handles
3 changes: 3 additions & 0 deletions packages/houdini-react/src/runtime/hooks/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type MutationHandler<_Result, _Input, _Optimistic extends GraphQLObject>
metadata?: App.Metadata
fetch?: typeof globalThis.fetch
optimisticResponse?: _Optimistic
abortController?: AbortController
}) => Promise<QueryResult<_Result, _Input>>

export function useMutation<
Expand All @@ -39,12 +40,14 @@ export function useMutation<
metadata,
fetch,
variables,
abortController,
...mutationConfig
}) =>
observer.send({
variables,
metadata,
session,
abortController,
stuff: {
...mutationConfig,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/houdini-svelte/src/runtime/stores/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class MutationStore<
metadata,
fetch,
event,
abortController,
...mutationConfig
}: {
// @ts-ignore
Expand All @@ -44,6 +45,7 @@ export class MutationStore<
fetch: context.fetch,
metadata,
session: context.session,
abortController,
stuff: {
...mutationConfig,
},
Expand All @@ -53,4 +55,5 @@ export class MutationStore<

export type MutationConfig<_Result, _Input, _Optimistic> = {
optimisticResponse?: _Optimistic
abortController?: AbortController
}
1 change: 1 addition & 0 deletions packages/houdini-svelte/src/runtime/stores/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
5 changes: 5 additions & 0 deletions packages/houdini/src/runtime/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = (
Expand Down
Loading