How to use the graphql-compose-mongoose.composeWithMongoose function in graphql-compose-mongoose

To help you get started, we’ve selected a few graphql-compose-mongoose 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 / UserSchema.js View on Github external
// - - - - - - Plugins - - - - - -
// User roles
const role = require('mongoose-role')
UserSchema.plugin(role, {
  roles: ['public', 'user', 'admin'],
  accessLevels: {
    'public': ['public', 'user', 'admin'],
    'anon': ['public'],
    'user': ['user', 'admin'],
    'admin': ['admin']
  }
})

const User = mongoose.model('User', UserSchema)
const UserTC = composeWithMongoose(User)

module.exports = { User, UserTC }
github rabbotio / nap / examples / schema-minimal / UserSchema.js View on Github external
const role = require('mongoose-role')
UserSchema.plugin(role, {
  roles: ['public', 'user', 'admin'],
  accessLevels: {
    'public': ['public', 'user', 'admin'],
    'anon': ['public'],
    'user': ['user', 'admin'],
    'admin': ['admin']
  }
})

// Auto timestamps
const timestamps = require('mongoose-timestamp')
UserSchema.plugin(timestamps);
const User = mongoose.model('User', UserSchema)
const UserTC = composeWithMongoose(User)

const Authen = mongoose.model('Authen', AuthenSchema)
module.exports = { User, UserTC, Authen }
github Lambda-IT / chestnutJS / server / src / schema.ts View on Github external
Object.keys(store.models).forEach(key => {
        const mongooseModel = store.models[key] as any; // mongooseModel
        const modelName = camelcase(key);
        const modelComposition = composeWithMongoose(mongooseModel, {}); // Mongoose to GraphQL

        compositions[modelName] = modelComposition;

        Object.keys(mongooseModel.schema.paths)
            .filter(k => k !== '__v')
            .forEach(p => {
                const property = mongooseModel.schema.paths[p];

                if (property.instance === 'String') {
                    modelComposition.setResolver(
                        'findMany',
                        modelComposition.getResolver('findMany').addFilterArg({
                            name: property.path + '_regex',
                            type: 'String',
                            description: 'Search by regExp',
                            query: (rawQuery, value) => {
github rabbotio / nap / fcm / server / Schema.Authen.js View on Github external
module.exports = (config) => {
  const mongoose = require('mongoose')
  const {
    composeWithMongoose
  } = require('graphql-compose-mongoose')

  const Authen = genModel(config)
  const AuthenTC = composeWithMongoose(Authen)

  return {
    Authen,
    AuthenTC
  };
}
github Traversal-Labs / starfleet / bin / createGQL.js View on Github external
const createGQL = (model, modelName) => {
  const ModelTC = composeWithMongoose(model, customizationOptions);

  schemaComposer.Query.addFields({
	[modelName+"ById"] : ModelTC.getResolver('findById'),
	[modelName+"ByIds"] : ModelTC.getResolver('findByIds'),
	[modelName+"One"] : ModelTC.getResolver('findOne'),
	[modelName+"Many"] : ModelTC.getResolver('findMany'),
	[modelName+"Count"] : ModelTC.getResolver('count'),
	[modelName+"Connection"] : ModelTC.getResolver('connection'),
	[modelName+"Pagination"] : ModelTC.getResolver('pagination'),
  });

  schemaComposer.Mutation.addFields({
	[modelName+"CreateOne"] : ModelTC.getResolver('createOne'),
	[modelName+"CreateMany"] : ModelTC.getResolver('createMany'),
	[modelName+"UpdateById"] : ModelTC.getResolver('updateById'),
	[modelName+"UpdateOne"] : ModelTC.getResolver('updateOne'),
github watscho / express-graphql-mongodb-boilerplate / src / module / auth / types.js View on Github external
const { schemaComposer } = require('graphql-compose')
const { composeWithMongoose } = require('graphql-compose-mongoose')

const UserModel = require('@app/module/auth/user')

const UserTC = composeWithMongoose(UserModel)
  .removeField('password')

const userAccountTC = UserTC.getFieldTC('account')

userAccountTC.getFieldTC('verification')
  .removeField(['token', 'expiresIn'])

userAccountTC.removeField('resetPassword')

schemaComposer.createObjectTC({
  name: 'AccessToken',
  fields: { accessToken: 'String!' }
})

schemaComposer.createEnumTC({
  name: 'Locale',
github rabbotio / nap / server / graphql / models / User.js View on Github external
}
  )

  const role = require('mongoose-role')
  UserSchema.plugin(role, {
    roles: ['public', 'user', 'admin'],
    accessLevels: {
      'public': ['public', 'user', 'admin'],
      'anon': ['public'],
      'user': ['user', 'admin'],
      'admin': ['admin']
    }
  })

  const User = mongoose.model('User', UserSchema)
  const UserTC = composeWithMongoose(User)

  UserTC.addFields({
    isLinkedWithFacebook: {
      type: 'Boolean!',
      resolve: (source) => {
        if (source.facebook && !source.facebook.isUnlink) {
          return true
        }
        return false
      },
      projection: { facebook: true }
    }
  })

  const Provider = mongoose.model('Provider', ProviderSchema)
github rabbotio / nap / server / graphql / models / Authen.js View on Github external
loggedInWith: String,
    loggedOutAt: Date,
    sessionToken: String,
    accessToken: String
  }

  const AuthenSchema = new mongoose.Schema(
    Object.assign(
      buildMongooseSchema(AuthenSchemaObject, extendedSchema)
    ), {
      timestamps: true
    }
  )

  const Authen = mongoose.model('Authen', AuthenSchema)
  const AuthenTC = composeWithMongoose(Authen)

  return { Authen, AuthenTC, model: Authen, typeComposer: AuthenTC }
}
github Traversal-Labs / starfleet / bin / passingGQL.js View on Github external
const passingGQL = (model, modelName) => {
	const ModelTC = composeWithMongoose(model, customizationOptions);

	schemaComposer.Query.addFields({
	[modelName+"ById"] : ModelTC.getResolver('findById'),
	[modelName+"ByIds"] : ModelTC.getResolver('findByIds'),
	[modelName+"One"] : ModelTC.getResolver('findOne'),
	[modelName+"Many"] : ModelTC.getResolver('findMany'),
	[modelName+"Count"] : ModelTC.getResolver('count'),
	[modelName+"Connection"] : ModelTC.getResolver('connection'),
	[modelName+"Pagination"] : ModelTC.getResolver('pagination'),
	});

	schemaComposer.Mutation.addFields({
	[modelName+"CreateOne"] : ModelTC.getResolver('createOne'),
	[modelName+"CreateMany"] : ModelTC.getResolver('createMany'),
	[modelName+"UpdateById"] : ModelTC.getResolver('updateById'),
	[modelName+"UpdateOne"] : ModelTC.getResolver('updateOne'),
github graphql-compose / graphql-compose-examples / examples / user / schemaComposer.js View on Github external
export function composeWithMongoose(
  model: Class,
  opts?: any
): ObjectTypeComposer {
  return _composeWithMongoose(model, { schemaComposer, ...opts });
}
export function convertSchemaToGraphQL(