Skip to content

feat(react-query): Add client parameter to queryKey and remove options parameter #1979

Open
@jeiea

Description

@jeiea

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestopenapi-fetchRelevant to the openapi-fetch library

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions