Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

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

Open
asci opened this issue Jan 14, 2018 · 4 comments
Open

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

asci opened this issue Jan 14, 2018 · 4 comments
Assignees
Labels
ac-local-state-ready feature New addition or enhancement to existing solutions

Comments

@asci
Copy link

asci commented Jan 14, 2018

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
Copy link
Author

asci commented Jan 14, 2018

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?

@peggyrayzis
Copy link
Member

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?

@fbartho
Copy link
Contributor

fbartho commented Jan 17, 2018

@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?

@asci
Copy link
Author

asci commented Jan 18, 2018

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ac-local-state-ready feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

4 participants