2.0.1 • Published 1 year ago
@urql/storybook-addon v2.0.1
Urql Storybook Addon
Create fixtures to model all the states of your GraphQL requests with Urql.
Installation
npm i @urql/storybook-addon
Usage
Add the decorator in your preview file at .storybook/preview
import { addDecorator } from '@storybook/react';
import { urqlDecorator } from '@urql/storybook-addon';
addDecorator(urqlDecorator);
Mock states by using the urql
parameter on your stories.
export const MyStory: Story = () => <Users />;
MyStory.parameters = {
urql: () => ({ data: { user: { id: 1234, name: 'Steve' } } }),
};
Examples
Fetching state
Setting a query in an infinitely fetching state.
MyStory.parameters = {
urql: () => new Promise(() => {}),
};
Error state
Returning an error for a query.
MyStory.parameters = {
urql: () => ({ errors: ['Some error'] }),
};
Single response
Returning data for a query (single request).
MyStory.parameters = {
urql: () => ({ data: { user: { id: 1234, name: 'Steve' } } }),
};
Multiple queries
Returning data for multiple queries (conditional response).
MyStory.parameters = {
urql: op => {
if (getQueryName(op.query) === 'GetUser') {
return { data: { user: { id: 1234, name: 'Steve' } } };
}
if (getQueryName(op.query) === 'GetFeed') {
return { data: { feed: [{ id: 1, title: 'Fake news' }] } };
}
},
};
0.0.0-canary-20230316005237
1 year ago
0.0.0-canary-20230316002801
1 year ago
0.0.0-canary-20230315232322
1 year ago
0.0.0-canary-20230316141844
1 year ago
0.0.0-canary-20230316141328
1 year ago
0.0.0-canary-20230316140157
1 year ago
0.0.0-canary-20230315191111
1 year ago
0.0.0-canary-20230316004530
1 year ago
0.0.0-canary-20230316090234
1 year ago
0.0.0-canary-20230316141110
1 year ago
2.0.1
2 years ago
2.0.0
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3-beta.4
4 years ago
1.0.3
4 years ago
1.0.3-beta.3
4 years ago
1.0.3-beta.2
4 years ago
1.0.3-beta.1
4 years ago
1.0.3-beta.0
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0-beta.4
4 years ago
1.0.0-beta.3
4 years ago
1.0.0-beta.2
4 years ago
1.0.0-beta.1
4 years ago
1.0.0-beta.0
4 years ago
1.0.0
4 years ago