Apollo-client: Query on Condition

Created on 27 Sep 2020  路  5Comments  路  Source: apollographql/apollo-client

I am using @apollo/react-hooks and I wanted to know if there is a way to conditionally trigger or prevent a query?

There are many use cases I have, one of it is server sider rendering, where I can set my props on the server with, but even if I redirect before, the component is rendered and the query hook is called.

It would be nice to have a flag that tells the hook to not fetch data.

Most helpful comment

@JayMGurav works perfectly well in V2. I gave up trying to update to V3 - too many really basic things not working.

All 5 comments

Also skip option

Agree with @dmt0 - I make extensive use of the skip option to conditionally fire queries using apollo hooks. Great for waiting until other things are loaded etc to prevent wasteful queries.

@michael-watson @dmt0 there is a problems with using skip though that queries actually takes place but are later nullified at the client, so one only "pretends " not to query Here are the details

@JayMGurav works perfectly well in V2. I gave up trying to update to V3 - too many really basic things not working.

Was this page helpful?
0 / 5 - 0 ratings