15

In my query, I use a blend of remote and local properties. The local properties have different values depending on:

  1. The remote properties
  2. The current unix timestamp

The local resolvers computes the local state according to these rules. Now, I face a scenario whereby I need to forego useQuery and use Apollo Client's query for enhanced flexibility.

Other than structural differences (e.g. useQuery accepts two parameters, whereas client.query takes only one parameter - the options objects), is it safe to use one over the other?

I identified at least one difference not described in the docs. When I call client.query multiple times, the local resolvers are run only once, at the beginning. With useQuery, the data always gets recomputed and it has different values (as per #2 above).

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
  • 2
    `useQuery`, like the `Query` component and the `graphql` HOC, uses `watchQuery` under the hood. `query` just runs your query and returns the result, while `watchQuery` also subscribes to subsequent changes to the cache. – Daniel Rearden Nov 02 '19 at 18:54
  • Thanks @DanielRearden, but I don't think this explains the difference I found. If the cache is indeed updated after running `client.query`, when I call it the 2nd time it should reflect the cached modified by the resolvers. I understand why `watchQuery` syncs this correctly, but I don't understand why `client.query` doesn't run the resolvers, even if I call it on an interval basis. – Paul Razvan Berg Nov 02 '19 at 23:20
  • Unfortunately, I'm not familiar enough with how the more recent versions of `apollo-client` handle local state internally to give a full answer. Just hoping to nudge you onto the right track. – Daniel Rearden Nov 03 '19 at 00:16

0 Answers0