Skip to content

Instantly share code, notes, and snippets.

@afbelardi
Last active March 15, 2023 20:31
Show Gist options
  • Save afbelardi/f23bd52ffac9659c09aa1cc1bd7525cf to your computer and use it in GitHub Desktop.
Save afbelardi/f23bd52ffac9659c09aa1cc1bd7525cf to your computer and use it in GitHub Desktop.
Register and update users using GraphQL queries
export const resolvers = {
Query: {},
Mutation: {
loginUser: async (_, _args) => {
const username = _args.username;
const password = _args.password;
const version = "internal";
return axios
.post("https://xxxxxxxxxx.com/login", {
username,
password,
version,
})
.then((res) => res.data)
.catch(function (error) {
console.error(error);
});
},
registerUser: async (_, _args) => {
const username = _args.username;
const password = _args.password;
const phoneNumber = _args.phoneNumber;
const email = _args.email;
const firstName = _args.firstName;
const lastName = _args.lastName;
const photo = _args.photo;
const version = "internal";
return axios
.post("https://xxxxxxxxxxxx.com/register", {
username,
password,
phoneNumber,
email,
firstName,
lastName,
photo,
version,
})
.then((res) => res.data)
.catch(function (error) {
console.error(error);
});
},
updateUser: async (_source, _args) => {
const id = _args._id;
const token = _args.token;
const firstName = _args.firstName;
const lastName = _args.lastName;
const birthday = _args.birthday;
const username = _args.username;
const password = _args.password;
const email = _args.email;
const phoneNumber = _args.phoneNumber;
const version = "internal";
return axios
.put(
`https://xxxxxxxxxxxx.com/users/update/${username}/`,
{
phoneNumber,
firstName,
lastName,
email,
birthday,
password,
version,
},
{
headers: {
Authorization: `Bearer ${token}`,
},
},
)
.then((res) => res.data)
.catch(function (error) {
console.error(error);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment