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(react-query): Add client parameter to queryKey and remove options parameter #1979

Open
1 task done
jeiea opened this issue Oct 30, 2024 · 0 comments
Open
1 task done
Assignees
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library

Comments

@jeiea
Copy link

jeiea commented Oct 30, 2024

Description

I'm referring to these lines.

Add client parameter to queryKey

Currently, the implementation 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.

... and remove options parameter

Currently queryOptions spreads the options parameter in the last argument. It might be cleaner to make this the library user's responsibility, as shown in the following examples, which yield the same result but simplify the implementation:

const queryOptions1 = client.queryOptions('get', '/', {}, { enabled: false } )
const queryOptions2 = { ...client.queryOptions('get', '/', {}), enabled: false }

Proposal

The title summarizes the changes.

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library
Projects
Status: No status
3 participants