项目作者: Fundflow

项目描述 :
Redux forms powered by Apollo
高级语言: TypeScript
项目地址: git://github.com/Fundflow/apollo-redux-form.git
创建时间: 2017-03-03T14:12:11Z
项目社区:https://github.com/Fundflow/apollo-redux-form

开源协议:MIT License

下载


Warning. This project is still WIP. Feedback is welcome.

Apollo ReduxForm

ReduxForm powered by Apollo and GraphQL

Features

  • Build forms from GraphQL mutations
  • Init forms from GraphQL queries
  • Store form state in Redux with ReduxForm
  • Submit forms via Apollo

install

  1. npm install @fundflow/apollo-redux-form

How it works

Forms are built from mutation arguments, automagically.

  1. const query = gql`
  2. mutation createPost($title: String!, $isDraft: Boolean, $views: Int, $average: Float) {
  3. createPost(title: $title, isDraft: $isDraft, views: $views, average: $average) {
  4. id
  5. createdAt
  6. }
  7. }`;
  8. const CreatePostForm = apolloForm(query);
  9. // CreatePostForm is a React component implementing a form with input fields corresponding to the mutation arguments

When submit button is clicked, the GraphQL mutation is executed.

It is possible to pre-fill a form with the results of a GraphQL query.

  1. const query = gql`
  2. query getPost($id: ID) {
  3. getPost(id: $id) {
  4. id title isDraft views average createdAt
  5. }
  6. }`;
  7. const withInit = initForm(query, { variables: { id: '123' } });
  8. const PrefilledUpdatePostForm = withInit(apolloForm( /* ... */));

A quick look

Some user stories powered by React Storybook.

  1. $ npm install
  2. $ npm run compile
  3. $ npm run storybook
  4. // point your browser to http://localhost:6006/

References