Skip to content

Commit

Permalink
feat(swr): add swrMutationOptions property to output.override.swr (
Browse files Browse the repository at this point in the history
  • Loading branch information
soartec-lab authored Feb 18, 2024
1 parent fa0e354 commit d5ccc8c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
24 changes: 24 additions & 0 deletions docs/src/pages/reference/configuration/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,30 @@ module.exports = {
};
```

##### swrMutationOptions

Type: `Object`.

Use to override the `useSWRMutation` options. Check available options [here](https://swr.vercel.app/docs/mutation#useswrmutation-parameters)

Example:

```js
module.exports = {
petstore: {
output: {
override: {
swr: {
swrMutationOptions: {
revalidate: true,
},
},
},
},
},
};
```

#### mock

Type: `Object`.
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export type SwrOptions = {
options?: any;
useInfinite?: boolean;
swrOptions?: any;
swrMutationOptions?: any;
};

export type InputTransformerFn = (spec: OpenAPIObject) => OpenAPIObject;
Expand Down
4 changes: 2 additions & 2 deletions packages/swr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ ${doc}export const ${camel(`use-${operationName}`)} = <TError = ${errorType}>(
});
const ${queryResultVarName} = useSWRMutation(swrKey, swrFn, ${
swrOptions.options
swrOptions.swrMutationOptions
? `{
${stringify(swrOptions.options)?.slice(1, -1)}
${stringify(swrOptions.swrMutationOptions)?.slice(1, -1)}
...swrOptions
}`
: 'swrOptions'
Expand Down
3 changes: 3 additions & 0 deletions tests/configs/swr.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ export default defineConfig({
swrOptions: {
dedupingInterval: 10000,
},
swrMutationOptions: {
revalidate: true,
},
},
},
},
Expand Down

0 comments on commit d5ccc8c

Please sign in to comment.