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

137
Views
GraphQL mutation type thows error when try to set type

I got this error: "Mutation fields must be an object with field names as keys or a function which returns such an object." I try to add user but I don't know how to make this work.

const mutation = new GraphQLObjectType({
    name: "Mutation",
    fileds: {
        addUser: {
            type: UserType,
            args: {
                firstName: { type: new GraphQLNonNull(GraphQLString) },
                age: { type: new GraphQLNonNull(GraphQLInt) },
                companyId: { type: GraphQLString }
            },
            resolve(parentValue, { firstName, age }) {
                return axios.post("http://localhost:3000/users", { firstName, age }).then(r => r.data);
            }
        }
    }
})

UserType is defined as follows:

const UserType = new GraphQLObjectType({
    name: "User",
    fields: {
        id: { type: GraphQLString },
        firstName: { type: GraphQLString },
        age: { type: GraphQLInt },
        company: {
            type: CompanyType,
            resolve(parentValue, args) {
                return axios.get("http://localhost:3000/companies/" + parentValue.companyId).then(res => res.data)
            }
        }
    }
})
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You have a typo: "fileds" should be "fields".

about 4 years ago · Santiago Gelvez Report
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!