# storybook-addon-apollo-graphql

> Storybook Apollo Graphql addon Test your Apollo graphql components with an offline gra

Latest version **2.1.0** (published 2018-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install storybook-addon-apollo-graphql
pnpm add storybook-addon-apollo-graphql
yarn add storybook-addon-apollo-graphql
bun add storybook-addon-apollo-graphql
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2018-06-27 |
| First published | 2017-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 410.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Alexandre BODIN |
| Maintainers | alexandrebodin |

## Links

- npm: https://www.npmjs.com/package/storybook-addon-apollo-graphql
- Repository: https://github.com/alexandrebodin/storybook-addon-apollo-graphql
- Homepage: https://github.com/alexandrebodin/storybook-addon-apollo-graphql#readme
- Issues: https://github.com/alexandrebodin/storybook-addon-apollo-graphql/issues
- npm.io page: https://npm.io/package/storybook-addon-apollo-graphql

## Dependencies (10)

- [react](https://npm.io/package/react.md) ^16.3.2
- [graphql](https://npm.io/package/graphql.md) ^0.13.2
- [react-dom](https://npm.io/package/react-dom.md) ^16.3.2
- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.9.2
- [react-apollo](https://npm.io/package/react-apollo.md) ^2.1.4
- [apollo-client](https://npm.io/package/apollo-client.md) ^2.3.1
- [graphql-tools](https://npm.io/package/graphql-tools.md) ^3.0.1
- [apollo-link-schema](https://npm.io/package/apollo-link-schema.md) ^1.1.0
- [react-test-renderer](https://npm.io/package/react-test-renderer.md) ^16.3.2
- [apollo-cache-inmemory](https://npm.io/package/apollo-cache-inmemory.md) ^1.2.1

## Recent versions

- 2.1.0 (latest) — 2018-06-27
- 2.0.0 — 2018-05-16
- 0.1.2 — 2017-06-16
- 0.1.1 — 2017-06-13
- 0.1.0 — 2017-06-13

## README

<p align="center">
    <p align="center">
        <img width="100" src="storybook-apollo.png" alt="logo">
    </p>
    <h3 align="center">Storybook Apollo Graphql addon</h3>
    <p align="center"><em>Test your Apollo graphql components with an offline graphql server</em><p>
    <p align="center">
        <a href="https://www.npmjs.com/package/storybook-addon-apollo-graphql"><img src="https://img.shields.io/npm/dt/storybook-addon-apollo-graphql.svg" alt="Npm download"></a>
        <a href="https://www.npmjs.com/package/storybook-addon-apollo-graphql"><img src="https://img.shields.io/npm/v/storybook-addon-apollo-graphql.svg" alt="Npm version"></a>
        <a href="https://www.npmjs.com/package/storybook-addon-apollo-graphql"><img src="https://img.shields.io/circleci/project/github/alexandrebodin/storybook-addon-apollo-graphql.svg" alt="Circle CI status"></a>
    </p>
</p>

![Addon example](screenshot.png)

## Usage

This library uses `graph-tools` to build a schema and mock it.
For mocking reference read [here](https://www.apollographql.com/docs/graphql-tools/mocking.html#Customizing-mocks)

Create your stories with the `withApolloProvider` API.

```js
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withApolloProvider } from '../../src';
import { gql, graphql } from 'react-apollo';

const Component = ({ data: { random } }) => <div>{random}</div>;
const ComponentWithGraphql = graphql(
  gql`
    {
      random
    }
  `
)(Component);

const typeDefs = `
    type Query {
        random: Int!
    }
`;

const mocks = {
  Query: () => ({
    random: () => Math.floor(Math.random() * 10),
  }),
};

export default () => {
  storiesOf('Random Number', module)
    .addDecorator(withApolloProvider({ typeDefs, mocks }))
    .add('A random number query', () => <ComponentWithGraphql />);
};
```

## Examples

See [Examples here](example/stories)

## Testing

You can clone and run the demo

```sh
$ git clone https://github.com/alexandrebodin/storybook-addon-apollo-graphql storybook-addon-apollo-graphql
$ cd storybook-addon-apollo-graphql
$ yarn install
$ yarn storybook
$ open http://localhost:9009
```

---
_Source: https://npm.io/package/storybook-addon-apollo-graphql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
