// GraphQL
import {
    GraphQLID,
    GraphQLString
} from 'graphql';
// RethinkDB
import r from 'rethinkdb';
// Constants
import { DB_HOST, DB_PORT } from '../../constants/configurations.js';

let BugTagMutation = {
	'createBugTag': {
		type: GraphQLString,
		description: 'create a bug tag',
        args: {
			data: {
				type: GraphQLString,
				description: 'new bug data'
			}
		},
		resolve: async (root, { data }) => {
			let connection = null,
				query = null,
				result = null;
			try {
				let tag = JSON.parse(data);
				if(tag.tag_name == ''){
					return false;
				}
				query = r.db('work_genius').table('bugtags').filter({tag_name:tag.tag_name}).coerceTo('array');
				connection = await r.connect({ host: DB_HOST, port: DB_PORT });
				result = await query.run(connection);
				if(result && result.length > 0){
					return false;
				}
				query = r.db('work_genius').table('bugtags').insert(tag);
				await query.run(connection);
				await connection.close();
			} catch (err) {
				return false;
			}
			return true;
		}
	}

};

export default BugTagMutation;
@@ -829,37 +829,57 @@
 0)%7B%0A%09%09%09%09%09return 
-false
+'Fail to update bug tag!'
 ;%0A%09%09%09%09%7D%0A%09%09%09%09quer
@@ -1029,34 +1029,80 @@
 urn 
-false;%0A%09%09%09%7D%0A%09%09%09return true
+'Fail to update bug tag!';%0A%09%09%09%7D%0A%09%09%09return 'Update bug tag successfully!'
 ;%0A%09%09

return success message after update bug tag