git init
npm init
touch .babelrc
npm install --save babel-preset-node5
touch db.js
npm install --save sequelize pg pg-hstore
npm install --save lodash faker
touch config/config.json
babel-node db.js
psql graphql_sequelize master
\d
select * from containers;
select * from sections;
Note: sections table has a containerId column due to association
npm install --save graphql
npm install --save react react-dom
Define Root Query (GraphQL checks to find shape of data to return) and whose fields function returns Public API Methods and Args that may be restricted
https://github.com/graphql/express-graphql
npm install --save express express-graphql graphiql
npm install --save react react-dom
babel-node server.js
{
containers {
id
data {
field1
field2
field3
}
}
}
{
sections {
id
}
}
Run Combined (Bi-directional) Query fields (benefit of GraphQL is Batches Requests from frontend) not being limited to independent endpoints like in RESTful API that only serves static data structures
{
containers {
id
data {
field1
field2
field3
}
sections {
id
}
}
}
{
sections {
id
container {
id
data {
field1
field2
field3
}
sections {
id
container {
id
}
}
}
}
}
http://localhost:3000/graphql?query={sections{id,container{id}}}
curl -X POST http://localhost:3000/graphql \
-H "Content-Type: application/graphql" \
-d '{ containers { id, sections { id } } }'
mutation addContainer {
addContainer(id: "TestContainer") {
id
}
}