Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
I cannot get findByIdAndUpdate to actually update anything in my database using GraphQl and Mongo

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')
    }
})
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!