Run Apollo request to React console only (no queryData and lifecycle)

I use Apollo extensively in a fairly large React application I'm building and ran into the same limitation several times.

I want to execute the query on component mounts only, so that changing this subthreshold component will not trigger the query again. I also really want to keep the container template where I declare my request in the container, wrap my component and forget about it, so that my component itself stays clean of any Apollo stuff. So far, I could do this by creating my own high level Apollo component that takes a component, a query and its parameters, and returns a new component that will automatically fire queryData on componentDidMount. Here is the code . Then I use it like this:apolloQueryHOC(MyComponent, queryOptions);

But on a new component, I started to implement paging, and this approach just doesn't work / gets too ugly for the complex paging logic I have implemented. Thing is, it works like a charm when I use Apollo's basic container approach. But it works on every route / support change.

So my question is, is there a way to run a "container" request on mount only, other than using withApollo

, etc.

+3


source to share


1 answer


Ah, the problem is I was handling auth in middleware, so my request had "as a token" and the token was retrieved from indexedDB and added to the request in middleware, overriding "". Thus, the result of the request stored in the Apollo repository (with the corresponding token as a parameter) never matched the request with '' as the token, causing Apollo to query the server again and again.



+2


source







All Articles