Skip to content

Commit

Permalink
Add default mutation key
Browse files Browse the repository at this point in the history
  • Loading branch information
b-nijhuis-innovadis committed Dec 2, 2024
1 parent 1fb9c4a commit ca83687
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/query/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export const getQueryErrorType = (
export const getHooksOptionImplementation = (
isRequestOptions: boolean,
httpClient: OutputHttpClient,
mutationOptionsFnName: string,
mutator?: GeneratorMutator,
) => {
const options =
Expand All @@ -349,13 +350,14 @@ export const getHooksOptionImplementation = (
: ', fetch: fetchOptions';

return isRequestOptions
? `const {mutation: mutationOptions${
? `const mutationKey = ['${mutationOptionsFnName}'];
const {mutation: mutationOptions${
!mutator
? options
: mutator?.hasSecondArg
? ', request: requestOptions'
: ''
}} = options ?? {};`
}} = options ? options.mutation?.mutationKey ? options : {...options, mutation: {...options.mutation, mutationKey}} : {mutation: { mutationKey, }};`
: '';
};

Expand Down
1 change: 1 addition & 0 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@ const generateQueryHook = async (
const hooksOptionImplementation = getHooksOptionImplementation(
isRequestOptions,
httpClient,
mutationOptionsFnName,
mutator,
);
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
Expand Down

0 comments on commit ca83687

Please sign in to comment.