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

Allow passing a custom client instance. #446

Closed
wants to merge 3 commits into from
Closed

Allow passing a custom client instance. #446

wants to merge 3 commits into from

Conversation

fubhy
Copy link

@fubhy fubhy commented Oct 9, 2019

Resolve #429

Hi there. Apparently this came up with another user too: #429

I had the same need so instead of continuing to roll a custom useQuery hook I thought I'd write a quick PR.

src/hooks/useQuery.ts Outdated Show resolved Hide resolved
src/context.ts Outdated Show resolved Hide resolved
src/context.ts Outdated Show resolved Hide resolved
@@ -33,7 +35,7 @@ export const useQuery = <T = any, V = object>(
args: UseQueryArgs<V>
): UseQueryResponse<T> => {
const unsubscribe = useRef(noop);
const client = useClient();
const client = useClient(args.client);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh before I forget 😅 let’s get this added to the other hooks as well.

useSubscription will just need another arg, just like useQuery. For useMutation we can probably use an optional second argument.

@kitten
Copy link
Member

kitten commented Jan 20, 2020

Apologies for keeping this around for so long! I think for now we won't end up merging this, sorry! 😞

Mainly we're concerned that this will A) make not a lot of sense as a natural evolution of the hook, and B) be an irreversible API change that is not inline with React.

I'll post another comment in the issue.

@kitten kitten closed this Jan 20, 2020
@ptbrowne
Copy link

I also stumbled upon this problem and ended up having to wrap my component into another urql.Provider to support this usecase. This is not ideal as it means the children hierarchy of the wrapped component has a different provider, and this might be unexpected for the children (in my case it's fine, the component is very small and its children do not use useQuery).

It would be much simpler if useQuery and consorts could accept a client parameter.

@kitten Can you expand on why this would not be natural for this hook and why it would not be inline with React ?

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.

Multiple clients / instances?
4 participants