Adding GetClone method

This commit is contained in:
Matias committed 2019-02-22 10:17:41 -03:00
1 parent 9e9c5e5bb8
commit 70519177bf
4 files changed
+1559 -1382

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
import { GraphQLNonNull, GraphQLID } from 'graphql'
import { OperationsError } from '../../errors'
import { GetClonesType } from '../types'
import { Clone } from '../../models'
import logger from '../../config/logger'
import mongoose from 'mongoose'
import { isDefined } from '../../config/utils'
const args = {
cloneId: { type: new GraphQLNonNull(GraphQLID) }
}
const resolve = async(parent, { cloneId }, context) => {
logger.debug('Get Clone -> Entering Fuction.')
try {
if (mongoose.Types.ObjectId.isValid(cloneId)) {
let existingClone = await Clone.findOne({
_id: cloneId
})
if (isDefined(existingClone)) {
return {
id: cloneId,
teamId: existingClone.teamId,
botId: existingClone.botId
}
} else {
throw new Error('Clone not found.')
}
} else {
throw new Error('Invalid Clone ID.')
}
return clones
} catch (err) {
logger.error('Get Clone error: %s', err.stack)
throw new OperationsError('There has been an error getting the clone. ' + err.message)
}
}
const GetClones = {
getClone: {
type: GetClonesType,
args,
resolve
}
}
export default GetClones
+3 -1
View File
@@ -2,13 +2,15 @@ import { GraphQLObjectType } from 'graphql'
import ListClones from './ListClones'
import HistoryClones from './HistoryClones'
import GetClones from './GetClones'
import GetClone from './GetClone'
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: Object.assign(
ListClones,
HistoryClones,
GetClones
GetClones,
GetClone
)
})