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

feat(swr): add swrOptions property to output.override.swr #1223

Merged

Conversation

soartec-lab
Copy link
Collaborator

@soartec-lab soartec-lab commented Feb 17, 2024

Status

READY

Description

As of v6.24.0, the 'swr' client now generates 'useSWRInfinite' and 'useSWRMutation' hooks. Therefore, since output.override.swr.options cannot be used in common for each hook, we will separate the options for each hook. First, this PR adds an option.to extend only useSwr.

Related PRs

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

  1. check generated hooks in tests

tests/generated/swr/petstore-override-swr/endpoints.ts:

/**
 * @summary Info for a specific pet
 */
export const useShowPetById = <TError = AxiosError<Error>>(
  petId: string, options?: { swr?:SWRConfiguration<Awaited<ReturnType<typeof showPetById>>, TError> & { swrKey?: Key, enabled?: boolean }, axios?: AxiosRequestConfig }
) => {
  const {swr: swrOptions, axios: axiosOptions} = options ?? {}

  const isEnabled = swrOptions?.enabled !== false && !!(petId)
  const swrKey = swrOptions?.swrKey ?? (() => isEnabled ? getShowPetByIdKey(petId) : null);
  const swrFn = () => showPetById(petId, axiosOptions);

  const query = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(swrKey, swrFn, {
     dedupingInterval: 10000, 
    ...swrOptions
  })

  return {
    swrKey,
    ...query
  }
}

@melloware melloware merged commit 74ef879 into anymaniax:master Feb 17, 2024
2 checks passed
@soartec-lab soartec-lab added the enhancement New feature or request label Feb 18, 2024
@soartec-lab soartec-lab added this to the 6.25.0 milestone Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants