I am trying to update a User, and I am at a loss! I get no errors in the console, but it is not updating as needed, I am just learning about GraphQl and Mongoose, so any help would be greatly appreciated....
My Mutation in TypeDefs.js is:
type Mutation {
userUpdate(input: UserUpdateInput): User!
}
input UserUpdateInput {
username: String
email: String
firstName: String
lastName: String
images: [ImageInput]
headline: String
}
and my resolver looks like this:
userUpdate: async (parent, args, context) => {
if (context.user) {
return await User.findByIdAndUpdate(context.user._id, args, { new: true });
}
throw new AuthenticationError('Not logged in');
},
My friend end logic in utils/mutations.js is:
export const USER_UPDATE = gql `
mutation userUpdate($input: UserUpdateInput!) {
userUpdate(input: $input) {
_id
username
firstName
lastName
email
images {
url
public_id
}
headline
createdAt
}
}
`
in my React component I have:
const [values, setValues] = useState({
username: '',
firstName: '',
lastName: '',
email: '',
images: [],
headline: '',
});
const {data} = useQuery(PROFILE);
useMemo(()=> {
if (data) {
console.log(data.profile)
setValues({
...values,
username: data.profile.username,
firstName: data.profile.firstName,
lastName: data.profile.lastName,
email: data.profile.email,
images: omitDeep(data.profile.images, ["__typename"]),
headline: data.profile.headline,
});
}
}, [data]);
//mutation
const [userUpdate] = useMutation(USER_UPDATE, {
update: ({ data }) => {
console.log('USER UPDATE MUTATION IN PROFILE', data);
toast.success('Profile updated')
}
})