Skip to content

feat(openapi-react-query): add prefixQueryKey option #2357

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jeiea
Copy link

@jeiea jeiea commented Jun 14, 2025

Background

Close #1979.

Current openapi-react-query has a potential issue because useQuery calls from different clients are assigned the same key, even though they're querying different endpoints.

For example:

import { default as createFetchClient } from 'openapi-fetch'
import createClient from 'openapi-react-query'

const client1 = createClient(createFetchClient({ baseUrl: 'https://api1.example.com' }))
const client2 = createClient(createFetchClient({ baseUrl: 'https://api2.example.com' }))

function useSomething() {
  return [client1.useQuery('get', '/a'), client2.useQuery('get', '/a')]
}

Here, both queries receive the same key, even though they are querying different sources.

This try to resolve the problem.

Changes

  • Added a prefixQueryKey parameter to differentiate cache identities.

How to Review

  • I haven't changed the documentation, but if you think it's necessary, please comment.
  • I got the comment about prefixQueryKey's type, and I ended up using unknown type.
    See packages/openapi-react-query/test/index.test.tsx:270, and feel free to leave a comment if you have any other thoughts.

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@jeiea jeiea requested a review from a team as a code owner June 14, 2025 16:58
@jeiea jeiea requested a review from htunnicliff June 14, 2025 16:58
Copy link

netlify bot commented Jun 14, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 1f048dc

Copy link

changeset-bot bot commented Jun 14, 2025

🦋 Changeset detected

Latest commit: 1f048dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-react-query Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(react-query): Add client parameter to queryKey and remove options parameter
1 participant