Skip to content

#40 Add support for exchanges.#41

Merged
parkerziegler merged 2 commits intov1from
task/add-support-for-exchanges
Apr 11, 2019
Merged

#40 Add support for exchanges.#41
parkerziegler merged 2 commits intov1from
task/add-support-for-exchanges

Conversation

@parkerziegler
Copy link
Copy Markdown
Contributor

@parkerziegler parkerziegler commented Apr 7, 2019

This PR adds support for exchanges 🎉, addressing #40. The bulk of the work went into typing all of the API surface that underpins exchanges, i.e. operation, operationResult, operationType, operationContext, exchangeInput, and exchangeIO, but that was made much easier by urql's TS defs.

A note on the architecture here – you'll see that UrqlExchanges is a module defined within UrqlClient. There's a reason for this. Exchanges accept exchangeInput as their single parameter, which is an object composed of forward (a function for forwarding operations to the next exchange) and client (the client instance, in this case of type UrqlClient.t). Because of this pairing between the types for exchanges and the type t of the client, the modules have to be co-located or we get the cyclic dependency of death error.

For example, if UrqlExchanges was its own module our dependency graph would look like:

  • UrqlExchanges.exchangeInput references UrqlClient.t.
  • UrqlClient references UrqlExchanges.exchange as part of its config options.
  • Cyclic dependency error :rip:

Co-locating makes sense here though, because exchanges are really only used by the client. If other folks have other organizational strategies, I'd love to hear them!

@parkerziegler parkerziegler marked this pull request as ready for review April 9, 2019 16:10
maxHeight(px(200)),
overflow(`auto),
minWidth(px(300)),
maxWidth(px(500))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add a refmt pre-commit hook in soon to catch things like this!

@parkerziegler parkerziegler force-pushed the task/add-support-for-exchanges branch from db5ec38 to fa60962 Compare April 9, 2019 16:12
];

Client.executeQuery(~client, ~query=queryRequest)
|> Wonka.subscribe((. response) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll flesh this example out more a bit later on. Right now, it just kicks off a mutation every 5 seconds so you can see the debugExchange working in the console.

"codecov": "^3.3.0",
"coveralls": "^3.0.2",
"graphql": "^14.1.1",
"codecov": "3.2.0",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still messing around trying to get Codecov working. I think it might be too messed up on the current project, so we'll retry with a new token when v1 is in a mergeable state.

[@bs.module "urql"] external dedupExchange: exchange = "";
[@bs.module "urql"] external fallbackExchangeIO: exchangeIO = "";
[@bs.module "urql"] external fetchExchange: exchange = "";
[@bs.module "urql"] external subscriptionExchange: exchange = "";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking more closely, subscriptionExchange may differ slightly in API from the other exchanges. I'll circle back to these bindings in the next PR, which'll add tests!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that is a factory that takes some extra options

@parkerziegler parkerziegler merged commit 8142737 into v1 Apr 11, 2019
@parkerziegler parkerziegler deleted the task/add-support-for-exchanges branch April 11, 2019 00:29
@parkerziegler parkerziegler mentioned this pull request Apr 13, 2019
5 tasks
parkerziegler added a commit that referenced this pull request May 2, 2019
* #40 Add support for exchanges.

* Add example for debugExchange. Support composeExchanges.
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.

2 participants