2.0.1 • Published 2 years 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
2 years ago
0.0.0-canary-20230316002801
2 years ago
0.0.0-canary-20230315232322
2 years ago
0.0.0-canary-20230316141844
2 years ago
0.0.0-canary-20230316141328
2 years ago
0.0.0-canary-20230316140157
2 years ago
0.0.0-canary-20230315191111
2 years ago
0.0.0-canary-20230316004530
2 years ago
0.0.0-canary-20230316090234
2 years ago
0.0.0-canary-20230316141110
2 years ago
2.0.1
3 years ago
2.0.0
3 years ago
1.0.9
3 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3-beta.4
5 years ago
1.0.3
5 years ago
1.0.3-beta.3
5 years ago
1.0.3-beta.2
5 years ago
1.0.3-beta.1
5 years ago
1.0.3-beta.0
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0-beta.4
5 years ago
1.0.0-beta.3
5 years ago
1.0.0-beta.2
5 years ago
1.0.0-beta.1
5 years ago
1.0.0-beta.0
5 years ago
1.0.0
5 years ago