apollo-link-state icon indicating copy to clipboard operation
apollo-link-state copied to clipboard

Any way to use client local data as an argument for remote request?

Open asci opened this issue 7 years ago • 4 comments

I'm storing locally an id of a search request and want to use it to perform a query to the remote server.

At the moment I see a solution like this:

  • add @client query
  • add withApollo
  • in componentWillReceiveProps check for loading and received data
  • when local data loaded use this.props.client and pass the data from the local query as a variable to query data from remote
  • manage loading with component state

But it doesn't look like the best solution. Any better suggestions?

asci avatar Jan 14 '18 21:01 asci

Okay, I found a better solution, but still not perfect:

  • I can use computed options and return {skip: true} if local data is not yet loaded

But it there a way to have only one query?

asci avatar Jan 14 '18 21:01 asci

There's no way to perform one query today. This is a pretty common use case though, so I do want to find a way to make it easier.

For apollo-link-rest, we've experimented with an @export directive that allows you to export a field name to be used as a variable further down the chain. This isn't really documented yet as we haven't officially released, but you can see it in action here. Would something like that suit your use case?

peggyrayzis avatar Jan 16 '18 17:01 peggyrayzis

@peggyrayzis I think the @export directive working similarly between both link-state & link-rest would be valuable, that way you can make a link-state query that directly funnels into a link-rest query -- all within one call to graphql. Thoughts?

fbartho avatar Jan 17 '18 22:01 fbartho

For me, @export directive looks nice. But the question is which directive to use to mark part of the query to call remote server? something like @remote? How then should it be handled at resolver level?

asci avatar Jan 18 '18 10:01 asci