How to use the graphql-compose.ComposeStorage function in graphql-compose

To help you get started, we’ve selected a few graphql-compose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rabbotio / nap / examples / schema-graphql-compose / user / index.js View on Github external
/*
An exmple for `graphql-compose`.
*/

// SINGLE SCHEMA ON SERVER
// const { GQC } = require('graphql-compose')

// MULTI SCHEMA MODE IN ONE SERVER
// create new GQC from ComposeStorage
const { ComposeStorage } = require('graphql-compose')
const GQC = new ComposeStorage()

const { UserTC } = require('./UserSchema')

// create GraphQL Schema with all available resolvers for User Type
GQC.rootQuery().addFields({
  userById: UserTC.getResolver('findById'),
  userByIds: UserTC.getResolver('findByIds'),
  userOne: UserTC.getResolver('findOne'),
  userMany: UserTC.getResolver('findMany'),
  userTotal: UserTC.getResolver('count'),
  userConnection: UserTC.getResolver('connection'),
})

GQC.rootMutation().addFields({
  userCreate: UserTC.getResolver('createOne'),
  userUpdateById: UserTC.getResolver('updateById'),
github rabbotio / nap / graphql / northwind / graphqlSchema.js View on Github external
var _graphqlCompose = require('graphql-compose');



var _graphqlComposeRelay = require('graphql-compose-relay');var _graphqlComposeRelay2 = _interopRequireDefault(_graphqlComposeRelay);

var _category = require('./models/category');
var _cutomer = require('./models/cutomer');
var _employee = require('./models/employee');
var _order = require('./models/order');
var _product = require('./models/product');
var _region = require('./models/region');
var _shipper = require('./models/shipper');
var _supplier = require('./models/supplier');
var _allowOnlyForLocalhost = require('./auth/allowOnlyForLocalhost');var _allowOnlyForLocalhost2 = _interopRequireDefault(_allowOnlyForLocalhost);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var GQC = new _graphqlCompose.ComposeStorage();

(0, _graphqlComposeRelay2.default)(GQC.rootQuery());

var ViewerTC = GQC.get('Viewer');
GQC.rootQuery().addFields({
  viewer: {
    type: ViewerTC.getType(),
    description: 'Data under client context',
    resolve: function resolve() {return {};} } });



var fields = {
  category: _category.CategoryTC.getResolver('findOne'),
  categoryList: _category.CategoryTC.getResolver('findMany'),
github rabbotio / nap / graphql / userForRelay / graphqlSchema.js View on Github external
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _graphqlCompose = require('graphql-compose');
var _graphqlComposeRelay = require('graphql-compose-relay');var _graphqlComposeRelay2 = _interopRequireDefault(_graphqlComposeRelay);
var _user = require('./models/user');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}







var GQC = new _graphqlCompose.ComposeStorage();

var RootQueryTC = GQC.rootQuery();
(0, _graphqlComposeRelay2.default)(RootQueryTC);

RootQueryTC.addFields({
  userById: _user.UserTC.getResolver('findById'),
  userByIds: _user.UserTC.getResolver('findByIds'),
  userOne: _user.UserTC.getResolver('findOne'),
  userMany: _user.UserTC.getResolver('findMany'),
  userTotal: _user.UserTC.getResolver('count'),
  userConnection: _user.UserTC.getResolver('connection') });


GQC.rootMutation().addFields({
  userCreate: _user.UserTC.getResolver('createOne'),
  userUpdateById: _user.UserTC.getResolver('updateById'),
github rabbotio / nap / graphql / user / graphqlSchema.js View on Github external
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _user = require('./models/user');






var _graphqlCompose = require('graphql-compose');
var GQC = new _graphqlCompose.ComposeStorage();


GQC.rootQuery().addFields({
  userById: _user.UserTC.getResolver('findById'),
  userByIds: _user.UserTC.getResolver('findByIds'),
  userOne: _user.UserTC.getResolver('findOne'),
  userMany: _user.UserTC.getResolver('findMany'),
  userTotal: _user.UserTC.getResolver('count'),
  userConnection: _user.UserTC.getResolver('connection') });


GQC.rootMutation().addFields({
  userCreate: _user.UserTC.getResolver('createOne'),
  userUpdateById: _user.UserTC.getResolver('updateById'),
  userUpdateOne: _user.UserTC.getResolver('updateOne'),
  userUpdateMany: _user.UserTC.getResolver('updateMany'),
github rabbotio / nap / server / graphql / index.js View on Github external
module.exports.buildSchema = () => {
  let authenChannel
  async function loginMiddleware({ rp }, next) {
    const authen = await next()
    authenChannel.publish('login', { Authen_Id: authen._id.toString(), User_Id: authen.userId.toString(), Installation_Id: authen.installationId.toString() })
  }

  async function logoutMiddleware({ rp }, next) {
    const authen = await next()
    authenChannel.publish('logout', { Authen_Id: authen._id.toString(), User_Id: authen.userId.toString(), Installation_Id: authen.installationId.toString() })
  }

  const { ComposeStorage } = require('graphql-compose')
  const GQC = new ComposeStorage()
  const models = require('./models')()
  require('./composers')(models)
  const { onError } = require('../errors')

  const userAccess = (resolvers) => {
    Object.keys(resolvers).forEach((k) => {
      resolvers[k] = resolvers[k].wrapResolve(next => (rp) => {
        if (!rp.context.nap.session) {
          onError(rp.context)('No session found')
          return null
        }

        return next(rp)
      })
    })
    return resolvers