Neverending Package Mountain
    Have ideas to improve npm?Join in the discussion! »

    trailpack-graphql

    0.9.1 • Public • Published

    trailpack-graphql

    NPM version Build status Dependency Status Code Climate

    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

    Install

    npm i trailpack-graphql

    DownloadsWeekly Downloads

    0

    Version

    0.9.1

    License

    MIT

    Last publish

    Collaborators

    • avatar