Adding GetClones method

This commit is contained in:
mati108@gmail.com committed 2019-02-09 13:29:15 -03:00
1 parent 939183c0d9
commit 767e910187
6 files changed
+93 -3

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import {
GraphQLList,
GraphQLID
} from 'graphql'
import {
OperationsError
} from '../../errors'
import { GetClonesInputType } from '../types/input';
import { GetClonesType } from '../types'
import { Clone } from '../../models'
import logger from '../../config/logger'
import { isDefined } from '../../config/utils'
const args = {
cloneIdList: {type: GetClonesInputType}
}
const resolve = async(parent, { cloneIdList }, context) => {
logger.debug('Get Clones -> Entering Fuction. %j', cloneIdList)
try{
let clones = []
for (var i = 0; i < cloneIdList.cloneIdList.length; i++) {
let existingClone = await Clone.findOne({
_id: cloneIdList.cloneIdList[i]
})
if(isDefined(existingClone)){
clones.push({
id: cloneIdList.cloneIdList[i],
teamId: existingClone.teamId,
botId: existingClone.botId
})
}
}
return clones
} catch (err){
logger.error('Get Clones error: %s', err.stack)
throw new OperationsError('There has been an error getting the clones.')
}
}
const query = {
getClones: {
type: new GraphQLList(GetClonesType),
args,
resolve
}
}
export default query
+3 -1
View File
@@ -4,12 +4,14 @@ import {
import ListClones from './ListClones'
import HistoryClones from './HistoryClones'
import GetClones from './GetClones'
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: Object.assign(
ListClones,
HistoryClones
HistoryClones,
GetClones
)
})
+14
View File
@@ -0,0 +1,14 @@
import {
GraphQLObjectType,
GraphQLID
} from 'graphql'
const GetClonesType = new GraphQLObjectType({
name: 'GetClones',
fields: () => ({
id: {type: GraphQLID},
teamId: {type: GraphQLID},
botId: {type: GraphQLID}
})
})
export default GetClonesType
+3 -1
View File
@@ -1,5 +1,7 @@
import CloneType from './CloneType'
import GetClonesType from './GetClonesType'
export {
CloneType
CloneType,
GetClonesType
}
@@ -0,0 +1,15 @@
import {
GraphQLInputObjectType,
GraphQLList,
GraphQLID
} from 'graphql';
const Type = new GraphQLInputObjectType({
name: 'GetClonesInput',
description: 'Allows to receive a list of clone ids to get information',
fields: () => ({
cloneIdList: { type: new GraphQLList(GraphQLID) }
})
});
export default Type;
+3 -1
View File
@@ -1,5 +1,7 @@
import CloneInputType from './Clone'
import GetClonesInputType from './GetClones'
export {
CloneInputType
CloneInputType,
GetClonesInputType
};