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

Relay client-side fetch requests to the server using the Storybook channel API #331

Merged
merged 8 commits into from
Sep 6, 2024

Conversation

ghengeveld
Copy link
Member

@ghengeveld ghengeveld commented Jul 16, 2024

Fixes #312

This adds a ChannelFetch utility and useChannelFetch hook. ChannelFetch listens for messages on the serverChannel, performs fetch requests, and sends back a message with the response. The goal is relay client-side requests to the server, in order to avoid polluting the network request log in DevTools.

A useChannelFetch hook is included, which returns a fetch compatible function. This fetch replacement is passed to the URQL Client so all GraphQL requests will happen over the channel. Requests time out after 30 seconds (if they haven't already). The signal property is supported by means of a dedicated abort message.

📦 Published PR as canary version: 1.9.0--canary.331.67b13f2.0

✨ Test out this PR locally via:

npm install @chromatic-com/storybook@1.9.0--canary.331.67b13f2.0
# or 
yarn add @chromatic-com/storybook@1.9.0--canary.331.67b13f2.0

Copy link
Member

@ndelangen ndelangen left a comment

Choose a reason for hiding this comment

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

I did not test it, but the code look great to me!

@ghengeveld ghengeveld added release Auto: Create a `latest` release when merged minor Auto: Increment the minor version when merged labels Aug 20, 2024
@ghengeveld ghengeveld merged commit f0c702f into main Sep 6, 2024
8 checks passed
@ghengeveld ghengeveld deleted the 312-api-channel-proxy branch September 6, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Auto: Increment the minor version when merged release Auto: Create a `latest` release when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API requests should happen server-side and support a proxy agent
2 participants