Created
June 23, 2019 19:35
-
-
Save ssaumyaranjan7/4a76ea44b73e303ef2a3a023fb53ad90 to your computer and use it in GitHub Desktop.
This is the resolver files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imported the employee model from the models directory | |
const models = require(`../models/index`); | |
const employeeResolvers = { | |
Query: { | |
/** | |
* This method will return an array of employees according to the query | |
*/ | |
employees: (root, args, context, info) => { | |
/** | |
* This will find all the employees from the employees collection | |
*/ | |
return models.employee.find({}) | |
}, | |
/** | |
* This method will find an employee details with respect to an ID. | |
*/ | |
employee: (root, { id }, context, info) => { | |
return models.employee.findById(id) | |
}, | |
}, | |
Mutation: { | |
/** | |
* This method will create an employee with parameters from the arguments | |
*/ | |
signUp: (root, args, context, info) => { | |
return models.employee.create(args) | |
}, | |
/** | |
* this method will update an employee data with respect to an id | |
*/ | |
update: (root, { id, firstName, lastName, email, password }, context, info) => { | |
let updateInfo = {}; | |
return models.employee.findById(id).then((newEmployee) => { | |
firstName ? newEmployee.firstName = firstName: ""; | |
lastName ? newEmployee.lastName = firstName: ""; | |
email ? newEmployee.email = email: ""; | |
password ? newEmployee.password = password: ""; | |
return newEmployee.save() | |
}) | |
}, | |
/** | |
* this method will delete an employee with respect to an ID | |
*/ | |
delete: (root, { id }, context, info) => { | |
return models.employee.findByIdAndRemove(id) | |
} | |
} | |
} | |
module.exports = employeeResolvers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imported both the resolvers for indexing | |
const messageResolvers = require(`./message.resolvers`); | |
const employeeResolvers = require(`./employee.resolvers`); | |
// Added all the resolvers into an array. | |
const resolvers = [messageResolvers, employeeResolvers] ; | |
// exported resolvers as a object. | |
module.exports = { resolvers }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const messageResolvers = { | |
Query: { | |
hello: () => 'Hello world' | |
} | |
} | |
module.exports = messageResolvers ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment