Installations
npm install storybook-addon-apollo-client
Developer
lifeiscontent
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
No
Node Version
18.20.2
NPM Version
10.5.0
Statistics
74 Stars
131 Commits
19 Forks
6 Watching
9 Branches
9 Contributors
Updated on 27 Nov 2024
Languages
TypeScript (65.6%)
JavaScript (34.25%)
HTML (0.15%)
Total Downloads
Cumulative downloads
Total Downloads
12,587,672
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
35
Storybook Addon Apollo Client
Use Apollo Client in your Storybook stories.
Versions
- If you're using Apollo Client 2.x and Storybook 5.x use version 1.x
- If you're using Apollo Client 2.x or 3.x and Storybook 6.x use version 4.x
- If you're using Apollo Client 2.x or 3.x and Storybook 7.x use version 5.x
- If you're using Apollo Client 2.x or 3.x and Storybook 8.x use version 7.x
Known issues
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
Install
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};
7.0 Features
- removed
globalMocks
key to favor composition
Migrate from 5.x+ to 7.x
Example of < 7.x
preview.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};
Example of 7.x
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};
Upgrading from a previous version below 6.x
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:
- remove all code referencing the deprecated withApolloClient decorator.
- follow install instructions
Writing your stories with queries
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
Usage
In Storybook, click "Show Addons" and navigate to the "Apollo Client" tab.
Example App
To see real world usage of how to use this addon, check out the example app:
https://github.com/lifeiscontent/realworld
Loading State
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};
Error State
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/lifeiscontent/storybook-addon-apollo-client/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/lifeiscontent/storybook-addon-apollo-client/release.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:22
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
- Warn: branch protection not enabled for branch '3.x'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Reason
15 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-4wx3-54gh-9fr9
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.6
/10
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 MoreOther packages similar to storybook-addon-apollo-client
@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