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

feat(exchanges): add binding for @urql/exchange-request-policy #247

Merged
merged 1 commit into from
Jan 5, 2021

Conversation

parkerziegler
Copy link
Contributor

This PR adds a binding for @urql/exchange-request-policy. This was a relatively low cost effort to bind, so I thought it made sense to lump it in with the retryExchange before 3.3.0 goes out.

Similar to the binding for @urql/exchange-retry, our binding here exposes a make function to turn optional parameters into a typed Reason record. This function is called makeRequestPolicyExchangeOptions to keep the nomenclature consistent. An example of the new API in action:

open ReasonUrql

let shouldUpgrade = (operation: Types.operation) =>
  operation.context.requestPolicy !== #CacheOnly

let requestPolicyExchangeOptions = Client.Exchanges.makeRequestPolicyExchangeOptions(
  ~shouldUpgrade,
  ~ttl=2000,
  (),
)

let client = Client.make(
  ~url="http://localhost:3000",
  ~exchanges=[
    Client.Exchanges.dedupExchange,
    Client.Exchanges.cacheExchange,
    Client.Exchanges.requestPolicyExchange(requestPolicyExchangeOptions),
    Client.Exchanges.fetchExchange
  ],
  ()
)

Fairly straightforward from what I can tell, but would appreciate any feedback all the same!

@parkerziegler parkerziegler requested a review from kitten January 4, 2021 04:22
@parkerziegler parkerziegler merged commit 9b6337e into main Jan 5, 2021
@parkerziegler parkerziegler deleted the feat/add-request-policy-exchange branch January 5, 2021 16:14
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

Successfully merging this pull request may close these issues.

1 participant