• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build React forms based on GraphQL APIs.

<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.

More Repositories

1

spotify-graphql

GraphQL schema for Spotify WebAPI — TypeScript / Node.js (v6)
TypeScript
266
star
2

graphql-to-json-schema

GraphQL Schema to JSON Schema
TypeScript
196
star
3

attr_bitwise

Bitwise attribute for ruby class and Rails model
Ruby
68
star
4

spotify-api-graphql-console

Spotify Web API GraphQL console.
TypeScript
30
star
5

spotify-graphql-examples

Examples in TypeScript and Node.js (v6) for spotify-graphql NPM package
27
star
6

graphql-mesh-docs-first-gateway

Example API services for https://www.graphql-mesh.com/docs
TypeScript
21
star
7

typescript-npm-module-bootstrap

TypeScript NPM module bootstrap
JavaScript
17
star
8

functional-json-schema

Build a JSON Schema with functions
TypeScript
11
star
9

spotify-fetch-my-playlists

Allow you to get a JSON dump of your Spotify playlists
TypeScript
7
star
10

algolia-graphql-schema

Generate a GraphQL Schema from an Algolia index
JavaScript
6
star
11

loopback-talk-chat-app

Demo of this talk https://slides.com/charlypoly-1/loopback
JavaScript
4
star
12

generator-yui3

YUI3 project scaffolder
JavaScript
4
star
13

cosmiconfig-typescript-swc-loader

Fast TypeScript config file handler for cosmiconfig using SWC
TypeScript
3
star
14

debugging-decorators

TypeScript useful debugging decorators
TypeScript
2
star
15

generic-graphql

Generic GraphQL Wrapper for Rest API
2
star
16

mood

Mood tracker, vision clearer
Ruby
2
star
17

redux-hydrate

Hydrate framework for Redux
2
star
18

til.engineering

💡 today i learned - web software engineering
JavaScript
2
star
19

spotify-oauth-workflow

Spotify Web API Express Server (with scopes selection step)
HTML
2
star
20

checkboxtable

1
star
21

insults_filter_service

Insults filter service
Ruby
1
star
22

Lucien

Your music theory trainer
TypeScript
1
star
23

spotify-backup

1
star