trailpack-graphql
v0.9.1
Published
GraphQL Support for Trails
Downloads
7
Readme
trailpack-graphql
This is a draft proposal
This trailpack provides a Relay-compatible GraphQL implementation for Trails.
Install
$ npm install --save trailpack-graphql
Configure
// config/main.js
module.exports = {
packs: [
// ... other trailpacks
require('trailpack-graphql')
]
}
Usage
Define Models
User
model
class User extends Model {
static schema () {
return graphql`
type User {
id: ID!
email: String!
age: Int
role: Role!
}
type Query {
user (email: String): User
allUsers (): [User]
}
`
}
static resolver () {
return {
user ({ email }) {
// find user by email
}
}
}
}
Role
model
class Role extends Model {
static schema () {
return graphql`
type Role {
name: String!
users: [User]
}
type Query {
userRoles (id: ID!): [Role]
}
`
}
static resolver () {
userRoles ({ userId }) {
// select roles from role where role.user_id = userId
}
}
}
References
Spec and Schema
- https://facebook.github.io/graphql/
- https://github.com/graphql/graphql-js
- https://www.reindex.io/blog/building-a-graphql-server-with-node-js-and-sql/
Querying
- http://graphql.org/docs/queries/
- https://facebook.github.io/relay/docs/graphql-connections.html#content
- https://github.com/graphql/graphql-relay-js
Mutations
- https://facebook.github.io/relay/docs/graphql-mutations.html#content
- https://medium.com/@HurricaneJames/graphql-mutations-fb3ad5ae73c4#.cntgoeljn