Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can you create an exchange that delays the pipeline until a promise is resolved #327

Closed
richtera opened this issue Jun 30, 2019 · 2 comments

Comments

@richtera
Copy link

Ref #326

Any guidance how to write an exchange that suspends all fetch requests until a promise has been resolved?
I played around with this for a few hours.
Essentially I was unable to delay operations in the pipe until the token was available. I tried to subscribe to the original data and then sending it back out using a makeSubject. However due to the key tracking the requests ended up being marked as completed as they were removed from the original pipe.

@richtera
Copy link
Author

As a reference this is the fetch clone I created to delay requests through fetchOptions returning a promise:
https://gist.github.com/richtera/ec539df29d129136f38f4365ae8a6895

@kitten
Copy link
Member

kitten commented Jul 23, 2019

You could also create a contextExchange (similar to apollo-link-context, if I'm not mistaken) that allows you to change every operation's context as part of the exchange pipeline. If you put this exchange just before the fetchExchange you don't even have to modify our exchange to make this work. https://gist.github.com/kitten/df34c06e56d6fb0d04159e26f3e12506

We might actually ship this exchange as part of urql or a secondary @urql/ package in the future.

(I haven't tested it but just quickly jotted down the idea of how it'd work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants