0

I want to change the url from what is set in the context. Here I want to use useQuery, when using Query I successfully set a new url client, as follows.

const onlineDocumentServiceClient = new ApolloClient({
  uri: process.env.REACT_APP_GQL_ODS
});

<Query query={QUERY} client={onlineDocumentServiceClient}>

I do not understand what if using useQuery can I do as Query does. I found it in https://www.apollographql.com/docs/react/data/queries/#executing-queries-manually the use of query can also be set by the client

1 Answer 1

4

You just pass it in as an option:

const { data, loading, refetch } = useQuery(MY_QUERY, { client: myClient });
Sign up to request clarification or add additional context in comments.

7 Comments

But why is that looping so much? if not using the client option, it's not looping.
Not sure what you mean?
I mean, there are repeated requests like ibb.co/fY3y2XP. Whereas if I don't use "client" but the code is like this "const { data, loading, refetch } = useQuery(MY_QUERY)" it doesn't repeat the request.
The request will be run every time the function component is called. If you don't pass in the client, where is the client coming from? The only other way would be to use an ApolloProvider, in which case you don't need to pass the client in at all unless it's a different client.
In my case, backend there are 2 different urls. 1 I put it on index.js (ApolloProvider), and other url (less accessible) I want to implement in useQuery directly. Are there any tips for my problem?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.