Wrap your React Storybook stories with Apollo Client.
React | React Native | Vue | Angular | |
---|---|---|---|---|
Apollo Client V2 | Coming Soon | |||
Apollo Client V1 | X | X | X |
graphql-tools
http://dev.apollodata.com/tools/graphql-tools/mocking.htmlTake this:
import React from "react";
import { Query } from "react-apollo";
import gql from "graphql-tag";
import { storiesOf } from "@storybook/react";
const userQuery = gql`
query getUser = {
currentUser {
name
lastAction {
message
}
avatar
city
}
}
`;
function CurrentUser() {
return (
<Query query={userQuery}>
{({ loading, data }) => {
const user = data && data.currentUser;
if (loading) {
return <h1>Loading one second please!</h1>;
}
return (
<div>
<img src={user.avatar} />
<h1>
{user.name}
from {user.city}
said "{user.lastAction.message}"{" "}
</h1>
</div>
);
}}
</Query>
);
}
storiesOf("Apollo Client", module).add("Current User", () => {
return <CurrentUser />;
});
To Render this:
For Apollo Client 2.x (React)
yarn add apollo-storybook-react -D
npm install apollo-storybook-react --save-dev
import React from "react";
import { Query } from "react-apollo";
import gql from "graphql-tag";
import { storiesOf } from "@storybook/react";
import apolloStorybookDecorator from "apollo-storybook-react";
const typeDefs = `
type Query {
helloWorld: String
}
schema {
query: Query
}
`;
const mocks = {
Query: () => {
return {
helloWorld: () => {
return "Hello from Apollo!!";
}
};
}
};
function HelloWorld() {
return (
<Query
query={gql`
query hello {
helloWorld
}
`}
>
{({ loading, data }) => {
const hello = data && data.helloWorld;
if (loading) {
return <h1>Loading one second please!</h1>;
}
return <h1>{hello}</h1>;
}}
</Query>
);
}
storiesOf("Apollo Storybook Decorator", module)
.addDecorator(
apolloStorybookDecorator({
typeDefs,
mocks
})
)
.add("Hello World Test", () => {
return <HelloWorld />;
});
You can add the decorator at a per story basis:
storiesOf("Apollo Client", module).addDecorator(
apolloStorybookDecorator({
typeDefs,
mocks
})
);
or you can add it to all stories, head to your storybook config.js
import { configure, addDecorator } from "@storybook/react";
import apolloStorybookDecorator from "apollo-storybook-react";
import typeDefs from "../wherever/your/typeDefs/live";
import mocks from "../wherever/your/mocks/live";
addDecorator(
apolloStorybookDecorator({
typeDefs,
mocks
})
);
function loadStories() {
// stories...
}
configure(loadStories, module);
type DecoratorType = {
//string representing your graphql schema, if you use tools like `babel-plugin-inline-import` you can import this from a .graphql file
typeDefs: string | Array<string>,
// object that resolves the keys of your graphql schema
mocks: Object,
apolloClientOptions?: Object,
apolloLinkOptions?: Object,
// optional typeResolvers for complex mocking
typeResolvers?: Object,
// optional context
context?: Object,
// optional root value
rootValue?: Object,
// optional resolver validation options, see: https://git.io/fALf4
resolverValidationOptions?: Object
};
This option gets passed directly to makeExecutableSchema
of graphql-tools
, as described at https://git.io/fALf4. This allows you to override requireResolversForResolveType
and other validation flags:
storiesOf("Apollo Client", module).addDecorator(
apolloStorybookDecorator({
typeDefs,
mocks,
resolverValidationOptions: {
requireResolversForResolveType: false
}
})
);
This repo is split up using the lerna
monorepo module.
To get started, clone this repo and run the following command:
$ yarn # install node deps
$ lerna bootstrap
To run the project's examples, run:
Current storybook is enabled in apollo-storybook-react
and apollo-storybook-v1
$ yarn storybookReact
or for v1
$ yarn storybookV1
Storybook 是 UI 组件的开发环境,它允许开发者浏览组件库,查看每个组件的不同状态,以及交互地开发和测试组件。 Storybook 在 app 之外运行,这允许开发者独立地开发 UI 组件,这可以提高组件的重用性、可测试性和开发速度。所以可以快速构建,而不必担心应用程序特定的依赖关系。 特点: 附带了许多组件设计、文档、测试、交互性等内容 易于使用的 API 使它易于配置和扩展,甚至被扩展到支持移动的本地开发
⚠️ This is the documentation for v1. Please check the "v0"-Branch for the documentation of older versions. ⚠️ Storybook Design Token Addon Display design token documentation generated from your styles
ember-cli-storybook �� Ember storybook adapter Compatibility Ember.js v3.16 or above Ember CLI v2.13 or above Node.js v10 or above Installation ember install @storybook/ember-cli-storybook Usage This
错误提示如下: storybook 版本
Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。 Swoft 基于 Apollo 提供的 API,在之上进行封装,使之能在 Swoft 中快速使用。 安装 swoft/whoops 作为一个额外的扩展组件,需要手动安装: Composer 安装 com
Apollo以ActiveMQ原型为基础,是一个更快、更可靠、更易于维护的消息代理工具。Apache称Apollo为最快、最强健的 STOMP(Streaming Text Orientated Message Protocol,流文本定向消息协议)服务器。 Apollo的特性如下: 支持Stomp 1.0和Stomp 1.1协议 主题和队列 队列浏览器 主题持久订阅 镜像队列 可靠的消息传递 消