Build React forms based on GraphQL APIs.
Build React forms based on GraphQL APIs.
apollo-codegen (globally)react@^15 react-apollo@^15Optionally
typescript@^2.8.4yarn add react-apollo-formpackage.json, at the scripts section :{
"scripts": {
"react-apollo-form": "react-apollo-form fetch-mutations "
}
}
This script will generated 3 files needed by ``:
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
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({
// tslint:disable-next-line:no-any
client: client as any,
jsonSchema,
theme: applicationFormTheme
});
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:
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
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
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:
render propsSee graphql-2-json-schema package.
No open issues yet, or sync has not completed.