Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// - - - - - - 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 }
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 }
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) => {
module.exports = (config) => {
const mongoose = require('mongoose')
const {
composeWithMongoose
} = require('graphql-compose-mongoose')
const Authen = genModel(config)
const AuthenTC = composeWithMongoose(Authen)
return {
Authen,
AuthenTC
};
}
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'),
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',
}
)
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)
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 }
}
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'),
export function composeWithMongoose(
model: Class,
opts?: any
): ObjectTypeComposer {
return _composeWithMongoose(model, { schemaComposer, ...opts });
}
export function convertSchemaToGraphQL(