Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 1.14 KB

README.md

File metadata and controls

59 lines (46 loc) · 1.14 KB

Simple proof-of-concept experiment showing how to build forms from a graph.cool schema.

We followed the example project with Apollo.

Project built with create-react-app.

Basic idea

1) Define a type with Graph.Cool

type User @model {
  id: ID! @isUnique
  name: String!
  surname: String!
  posts: [Post!]! @relation(name: "UserPosts")
}

type Post @model {
  id: ID! @isUnique
  title: String!
  content: String!
  author: User! @relation(name: "UserPosts")
}

2) Read Graph.Cool schema with introspection

import {
  introspectionQuery
} from 'graphql';

import { graphql, gql } from 'react-apollo'

graphql( gql(introspectionQuery) )((props) => {
  const {
    data: {
      loading,
      __schema // graph.cool schema
    }
  } = props;
  return (
    ...  
  )
});

3) Build form with apollo-redux-form

import {
  apolloForm
} from '@fundflow/apollo-redux-form';

CreatePostForm = apolloForm(createPost, {
  schema, // <-- schema read at step 2
});