Graphql How to re-run local resolvers in React Apollo?

Graphql How to re-run local resolvers in React Apollo?,graphql,apollo,react-apollo,apollo-client,Graphql,Apollo,React Apollo,Apollo Client,In my queries, I use a blend of remote and local properties, like this: foo { bar baz qux @client quux @client { corge grault } } I have resolvers in place for qux and quux, but I'd like to recompute the data once every so often. I thought about writing directly to the cache with cache.writeData and setInterval, but that would a lot of rewriting. Is there a way to run the resolvers again?

In my queries, I use a blend of remote and local properties, like this:

foo {
  bar
  baz
  qux @client
  quux @client {
    corge
    grault
  }
}

I have resolvers in place for

qux
and
quux
, but I'd like to recompute the data once every so often. I thought about writing directly to the cache with
cache.writeData
and
setInterval
, but that would a lot of rewriting.

Is there a way to run the resolvers again?


#1

If you'd like to run the resolvers again on a specific interval, you can pass pollInterval as an option to your graphql HOC or as a prop to your Query component, depending on your implementation. Alternatively, if you would like to requery in response to, for example, a user event, you could invoke the refetch function, which should be accessible via props. For additional info see docs here.


#2

Many thanks. Is it possible to use pollInterval with Hooks?

#3

Update: yes, it's just an option in the configuration object of useQuery.

#4

But now the question is whether there's something I can do to not make a query again, but run the local resolvers?

#5

@PaulBerg - Can you provide a little more detail as to how you're using the local resolvers? For example, are you writing any data to cache? You might be able to just set up another query fooMini that only invokes the local resolvers and just poll or refetch that.

#6

I assembled a CodeSandbox for you. See the queries.js file and notice the paid @client parameter in the GET_STREAM query. Unfortunately I don't think I can move the local state parameters to a different query, because they depend on the remote data.