Adding GetClone method
This commit is contained in:
1 parent
9e9c5e5bb8
commit
70519177bf
4 files changed
+1559
-1382
No files matched your search
Generated
+1494
-1368
File diff suppressed because it is too large.
Load diff
+13
-13
@@ -10,20 +10,20 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"nodemon": "^1.18.10"
|
||||
"babel-cli": "6.26.0",
|
||||
"babel-preset-env": "1.7.0",
|
||||
"babel-preset-stage-2": "6.24.1",
|
||||
"nodemon": "1.18.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"cors": "^2.8.4",
|
||||
"dotenv": "^6.0.0",
|
||||
"express": "^4.16.3",
|
||||
"express-graphql": "^0.6.12",
|
||||
"graphql": "^14.0.0",
|
||||
"kubernetes-client": "^6.5.1",
|
||||
"mongoose": "^5.2.12",
|
||||
"winston": "^3.1.0"
|
||||
"axios": "0.18.0",
|
||||
"cors": "2.8.4",
|
||||
"dotenv": "6.0.0",
|
||||
"express": "4.16.3",
|
||||
"express-graphql": "0.6.12",
|
||||
"graphql": "14.0.0",
|
||||
"kubernetes-client": "6.5.1",
|
||||
"mongoose": "5.2.12",
|
||||
"winston": "3.1.0"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user