Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Add custom exchange example #32

Merged
merged 2 commits into from
Feb 14, 2020
Merged

Conversation

0xRAG
Copy link
Contributor

@0xRAG 0xRAG commented Feb 12, 2020

Summary

This PR adds an example of creating and using a custom exchange with next-urql. All the custom exchange currently does is switch the endpoint url when running in the browser. Hopefully this serves as a good reference for issues like #16!

I'd like to add a component to visualize this change :)

@0xRAG 0xRAG requested a review from parkerziegler February 12, 2020 19:52
@0xRAG 0xRAG changed the title Add initial custom exchange example Add custom exchange example Feb 12, 2020
Comment on lines +23 to +29
(ssrExchange: SSRExchange) => [
dedupExchange,
urlExchange,
cacheExchange,
ssrExchange,
fetchExchange,
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Hellz yes, love seeing mergExchanges getting used! :chefs-kiss:

Comment on lines +4 to +17
export const urlExchange = ({ forward }: ExchangeInput) => {
return (operations$: Source<Operation>) => {
return pipe(
operations$,
map(op => {
if (process.browser) {
op.context.url = 'https://metaphysics-production.artsy.net/';
}
return op;
}),
forward,
);
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job getting this exchange working! Looks great!

Copy link
Contributor

@parkerziegler parkerziegler left a comment

Choose a reason for hiding this comment

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

Looks awesome @ryan-gilb! Thanks for contributing this – feel free to merge whenever.

@parkerziegler parkerziegler merged commit 1ad4fc0 into master Feb 14, 2020
@parkerziegler parkerziegler deleted the add-example-with-custom-exchange branch February 14, 2020 00:28
@parkerziegler
Copy link
Contributor

Just merged anyway 😄 We can add a simple component to pretty print the clientOptions used for each operation if you like, but that can happen in a separate PR!

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

Successfully merging this pull request may close these issues.

2 participants