• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

charlypoly/react-apollo-form: Build React forms based on GraphQL APIs.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

charlypoly/react-apollo-form

开源软件地址(OpenSource Url):

https://github.com/charlypoly/react-apollo-form

开源编程语言(OpenSource Language):

TypeScript 97.9%

开源软件介绍(OpenSource Introduction):

<ApolloForm> https://img.shields.io/circleci/project/github/wittydeveloper/react-apollo-form.svg https://img.shields.io/npm/v/react-apollo-form.svg https://img.shields.io/npm/dt/react-apollo-form.svg

Build React forms based on GraphQL APIs.


The library is currently under active rewriting, please see this ticket for updates


https://s3.eu-west-2.amazonaws.com/github-oss/react-apollo-form/read-me-demo-preview.png


To get started more easily, please read Getting started: build a GraphQL Form in 5 minutes


Pre-requisites

  • apollo-codegen (globally)
  • react@^15
  • react-apollo@^15

Optionally

  • typescript@^2.8.4

Installation

Install package

  • install yarn add react-apollo-form

Add script to your project

  • add to your package.json, at the scripts section :
{
    "scripts": {
        "react-apollo-form": "react-apollo-form fetch-mutations <graphql_endpoint> <outpurDir>"
    }
}

This script will generated 3 files needed by <ApolloForm>:

  • schema.json (GraphQL Introspection Query result as JSON)
  • mutations.d.ts (all available mutations names as TypeScript type definition)
  • apollo-form-json-schema.json (GraphQL Schema as JSON Schema)

Tips: you can change the output directory of theses with the second argument or -o option


Usage

Once the files generated, we can setup a Form.

import * as React from 'react';
import gql from 'graphql-tag';
import { configure } from 'react-apollo-form';
import { client } from './apollo';
import { applicationFormTheme } from './core/forms/themes/application';


const jsonSchema = require('./core/apollo-form-json-schema.json');

export const ApplicationForm = configure<ApolloFormMutationNames>({
    // tslint:disable-next-line:no-any
    client: client as any,
    jsonSchema,
    theme: applicationFormTheme
});

<ApplicationForm
    config={{
        mutation: {
            name: 'create_todo',
            document: gql`mutation {...}`
        }
    }}
    data={{}}
/>

API

ApolloForm is based on the amazing Mozilla library react-jsonschema-form. Most of the questions regarding JSON Schema, validations or rendering are in react-jsonschema-form documentation

To get started more easily, please read Getting started: build a GraphQL Form in 5 minutes

The following subjects are specific to ApolloForm:


Q&A

  • Can I make ApolloForm works with many GraphQL endpoints?

Yes, just setup multiple scripts in your project package.json with one output folder per endpoint, then just configure a "component form" for each endpoint

  • Where can I find some documentation about widgets, fields or theming in general?

Please take a look at the react-jsonschema-form documentation that will answers 90% of the rendering questions. If not, please take a look at Theming


Architecture

General

The idea is to build forms using mutations from the GraphQL API.

ApolloForm is "just" a wrapper around react-jsonschema-form.

It brings some "embed" features:

  • JSON schema generation from GraphQL Schema
  • conditionals forms
  • form rendering customisation with render props
  • build JSON Schema with functions (with functional-json-schema)

GraphQL to JSON Schema

See graphql-2-json-schema package.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ezsystems/ezplatform-graphql: GraphQL server for eZ Platform, the open source Sy ...发布时间:2022-06-22
下一篇:
nordsimon/graphql-client发布时间:2022-06-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap