Gathering detailed insights and metrics for storybook-addon-apollo-client
Gathering detailed insights and metrics for storybook-addon-apollo-client
Gathering detailed insights and metrics for storybook-addon-apollo-client
Gathering detailed insights and metrics for storybook-addon-apollo-client
npm install storybook-addon-apollo-client
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
74 Stars
131 Commits
19 Forks
6 Watching
9 Branches
9 Contributors
Updated on 27 Nov 2024
TypeScript (65.6%)
JavaScript (34.25%)
HTML (0.15%)
Cumulative downloads
Total Downloads
Last day
6.9%
16,702
Compared to previous day
Last week
1.8%
79,538
Compared to previous week
Last month
6.9%
348,722
Compared to previous month
Last year
-4.2%
4,148,815
Compared to previous year
1
35
Use Apollo Client in your Storybook stories.
due to how MockedProvider works in Apollo, you will have to hard refresh when visiting sub stories (visiting stories that exist in the same file) to get the expected results, please upvote my comment here to see if we can get this fixed: https://github.com/apollographql/apollo-client/issues/9738#issuecomment-1606316338
pnpm
1pnpm add -D storybook-addon-apollo-client
yarn
1yarn add -D storybook-addon-apollo-client
npm
1npm install -D storybook-addon-apollo-client
Add the addon to your configuration in .storybook/main.ts
1export default { 2 ...config, 3 addons: [ 4 ...yourAddons 5 "storybook-addon-apollo-client", 6 ], 7};
globalMocks
key to favor compositionpreview.ts
1import { MockedProvider } from "@apollo/client/testing"; // Use for Apollo Version 3+ 2// import { MockedProvider } from "@apollo/react-testing"; // Use for Apollo Version < 3 3 4export const preview = { 5 parameters: { 6 apolloClient: { 7 MockedProvider, 8 globalMocks: [ 9 // whatever mocks you want here 10 ], 11 }, 12 }, 13};
preview.ts
1// Whatever you want here, but not Apollo Client related
component.stories.ts
1import type { Meta } from "@storybook/react"; 2import { globalMocks } from "./globalMocks"; 3import { otherMocks } from "./otherMocks"; 4import { YourComponent, YOUR_QUERY } from "./component"; 5 6export const meta: Meta<typeof DisplayLocation> = { 7 component: YourComponent, 8 parameters: { 9 apolloClient: { 10 mocks: [ 11 ...globalMocks, 12 ...otherMocks, 13 { 14 request: { 15 query: YOUR_QUERY, 16 }, 17 result: { 18 data: { 19 // your data here 20 }, 21 }, 22 }, 23 ], 24 }, 25 }, 26};
In previous versions, we had a decorator called withApolloClient
this is no longer nesscessary. If you're upgrading from this API here are the following changes that you'll need to make:
1import DashboardPage, { DashboardPageQuery } from "."; 2 3export default { 4 title: "My Story", 5}; 6 7export const Example = () => <DashboardPage />; 8 9Example.parameters = { 10 apolloClient: { 11 mocks: [ 12 { 13 request: { 14 query: DashboardPageQuery, 15 }, 16 result: { 17 data: { 18 viewer: null, 19 }, 20 }, 21 }, 22 ], 23 }, 24};
Read more about the options available for MockedProvider at https://www.apollographql.com/docs/react/development-testing/testing
In Storybook, click "Show Addons" and navigate to the "Apollo Client" tab.
To see real world usage of how to use this addon, check out the example app:
https://github.com/lifeiscontent/realworld
You can use the delay
parameter to simulate loading state.
1import DashboardPage, { DashboardPageQuery } from "."; 2 3export default { 4 title: "My Story", 5}; 6 7export const Example = () => <DashboardPage />; 8 9Example.parameters = { 10 apolloClient: { 11 mocks: [ 12 { 13 // Use `delay` parameter to increase loading time 14 delay: 1000, 15 request: { 16 query: DashboardPageQuery, 17 }, 18 result: { 19 data: {}, 20 }, 21 }, 22 ], 23 }, 24};
You can use the error
parameter to create error state.
1import DashboardPage, { DashboardPageQuery } from "."; 2 3export default { 4 title: "My Story", 5}; 6 7export const Example = () => <DashboardPage />; 8 9Example.parameters = { 10 apolloClient: { 11 mocks: [ 12 { 13 request: { 14 query: DashboardPageQuery, 15 }, 16 error: new ApolloError("This is a mock network error"), 17 }, 18 ], 19 }, 20};
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More@storybook/addon-controls
Interact with component inputs dynamically in the Storybook UI
@storybook/addon-toolbars
Create your own toolbar items that control story rendering
@storybook/addon-backgrounds
Switch backgrounds to view components in different settings
@storybook/addon-actions
Get UI feedback when an action is performed on an interactive element