1.0.9 • Published 6 years ago

feathersql v1.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

FeathersQL

⚡️ The Feathers and GraphQL Integration.

logo

NPM version

Npm Downloads

queries

Getting Started

You can create a project using feathers-cli. See more details here: https://github.com/feathersjs/cli

Usage Example Projects

With Common JS

https://github.com/hookcompany/feathersql/tree/master/example

With Import/Export and Babel Configuration

https://github.com/hookcompany/feathers-graphql-boilerplate

Installing

Install with npm

$ npm install --save feathersql

Install with Yarn

$ yarn add feathersql

Usage

// services/app1/users/types.gql
const gql = require('graphql-tag');

module.exports = gql`
  input UserFilter {
    id: Any
    name: Any
    birth: Any
    tags: Any
    createdAt: Any
    updatedAt: Any
  }

  input NewUserData {
    name: String!
    birth: Date!
    tags: [String]
  }

  input EditUserData {
    name: String
    birth: Date
    tags: [String]
  }

  input UserUpdateData {
    set: EditUserData
    push: [Any!]
    pull: [Any!]
  }

  type UserQuery @query {
    users(query: UserFilter, sort: Any, limit: Int, skip: Int): [User] @find
    user(id: ID, query: UserFilter): User @get
  }

  type UserMutation @mutation {
    createUser(data: NewUserData!): User @create
    createUsers(data: [NewUserData!]!, sort: Any): [User] @create
    updateUser(id: ID, query: UserFilter, data: UserUpdateData!): User @update
    updateUsers(id: ID, query: UserFilter, data: UserUpdateData!, sort: Any): [User] @update
    patchUser(id: ID, query: UserFilter, data: EditUserData!): User @patch
    patchUsers(id: ID, query: UserFilter, data: EditUserData!, sort: Any): [User] @patch
    removeUser(id: ID, query: UserFilter): User @remove
    removeUsers(id: ID, query: UserFilter, sort: Any): [User] @remove
  }

  type UserSubscription @subscription {
    createUser: [User] @create
    updateUser: [User] @update
    patchUser: [User] @patch
    removeUser: [User] @remove
  }
`;
// services/app1/users/index.js
const types = require('./types');
const hooks = require('./hooks');

module.exports = {
  types,
  hooks,
  modelName: 'User',
  path: '/users',
  filters: {
    CREATED: (payload, args, context) => {
      console.log('users created');
      return true;
    },
    UPDATED: (payload, args, context) => {
      console.log('users updated');
      return true;
    },
    REMOVED: (payload, args, context) => {
      console.log('users removed');
      return true;
    }
  }
};
// services/app1/index.js
const Category = require('./categories');
const Product = require('./products');
const User = require('./users');

module.exports = {
  basePath: '/app1',
  services: [User, Category, Product]
};
// services/index.js
const feathersQL = require('../../../dist');
const models = require('../models');
const app1 = require('./app1');
const app2 = require('./app2');

module.exports = app => {
  feathersQL(models)(app)
    .platform(app1)
    .platform(app2)
    .configure();
};

Configuration

const mongoose = require('mongoose');

module.exports = app => {
  mongoose.connect(app.get('mongodb'));
  mongoose.Promise = global.Promise;
  app.set('mongooseClient', mongoose); // This line is mandatory.
};

Querying

Support

Query
  • eq
  • gt && gte
  • lt && lte
  • in
  • ne && nen
  • exists && not
  • mod
  • regex
  • options
  • size
Sort
  • sort: ["name:desc", "createdAt:asc"]
  • sort: "name:desc createdAt:asc"
  • sort: { name: "desc", createdAt: "asc" }
Limit: Int
Skip: Int

Options

  • mongooseClientVariableName (String) - Mongoose client variable name. ex.: app.set('mongooseClient', mongoose);; default is 'mongooseClient'
  • socketPort (Int) - Subscriptions socket port; default is 5000
  • graphqlEndPoint (String) - GraphQL endpoint; default is '/graphql'
  • subscriptionEndPoint (String) - Subscriptions endpoint; default is '/subscriptions'
  • voyagerEndPoint (String) - Voyager endpoint; default is '/voyager'
  • graphiqlEndPoint (String) - GraphQL IDE endpoint; default is '/graphiql'
  • playgroundEndPoint (String) - Playground(similar to GraphQL IDE) endpoint; default is '/playground'
  • subscription (Bool) - Configure subscriptions; default is true
  • voyager (Bool) - Configure voyager; default is true
  • graphiql (Bool) - Configure GraphQL IDE; default is true
  • playground (Bool) - Configure playground; default is true

Consuming The API

Populate

populate

Subscriptions

subscriptions

License

This project is licensed under the MIT License - see the LICENSE.md file for details.