Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created September 10, 2019 09:51
Show Gist options
  • Save tkssharma/7101c3ce5f64fbfe6004212807f7c2a2 to your computer and use it in GitHub Desktop.
Save tkssharma/7101c3ce5f64fbfe6004212807f7c2a2 to your computer and use it in GitHub Desktop.
const resolvers = {
Query: {
users: (parent, args, { dbContext }) => {
return userController.getAllUsers(dbContext);
},
user: (parent, { email }, { dbContext }) => {
return userController.getUserByEmail(dbContext, email);
},
me: (parent, args, { me }) => me,
},
Mutation: {
// eslint-disable-next-line camelcase
register: (parent, { name, first_name, last_name, username, email, password }, { dbContext }) => {
const user = {
name,
first_name,
last_name,
email,
username,
password,
is_active: true,
};
return userController
.registerUser(dbContext, user)
.then(() => Response.successMessage())
.catch(err => {
if (err.ErrorID === 1001) {
return new ApolloError('user already exists in system', '1001');
}
return new ApolloError('user already exists in system', '1001');
});
},
login: (parent, { email, password }, { dbContext }) => {
const authPayload = {
email,
password,
};
return userController
.loginUser(dbContext, authPayload)
.then(token => Response.loginMessage(token))
.catch(err => {
return new ApolloError('user email, password not valid', '1001', err);
});
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment