This trailpack provides a Relay-compatible GraphQL implementation for Trails.
$ npm install --save trailpack-graphql
// config/main.js
module.exports = {
packs: [
// ... other trailpacks
require('trailpack-graphql')
]
}
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
}
}
}
}
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
}
}
}
-
Spec and Schema
-
Querying
-
Mutations