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
@apollo-mock-operations/storybook-addon
Storybook addon for mocked Apollo client operations
@lpgera/storybook-addon-apollo-client
Use Apollo Client in your Storybook stories.
@xdanangelxoqenpm/ipsam-magnam-error
<div align="center"> <h1> <nobr> <a href="https://storybookjs.github.io/storybook-addon-console"> <img src="https://github.com/storybookjs/storybook-addon-console/raw/master/docs/logo.png" alt="logo" height="140"> </a> <img src="http
npm install storybook-addon-apollo-client
Typescript
Module System
Node Version
NPM Version
TypeScript (67.51%)
JavaScript (32.06%)
MDX (0.42%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
76 Stars
156 Commits
23 Forks
6 Watchers
6 Branches
10 Contributors
Updated on Jun 24, 2025
Latest Version
9.0.0
Package Id
storybook-addon-apollo-client@9.0.0
Unpacked Size
38.28 kB
Size
9.36 kB
File Count
20
NPM Version
10.8.2
Node Version
20.19.2
Published on
Jun 24, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
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
3 existing vulnerabilities detected
Details
Reason
5 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 1/20 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
no effort to earn an OpenSSF best practices badge detected
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
Score
Last Scanned on 2025-07-07
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