I have this simple mutation that works fine
type Mutation {
addJob(
url: String!
description: String!
position: String!
company: String!
date: DateTime!
tags: [String!]!
): Job
}
Mutation Resolver
function addJob(parent, args, context, info) {
console.log('Tags => ', args.tags)
// const userId = getUserId(context)
return context.db.mutation.createJob(
{
data: {
position: args.position,
componay: args.company,
date: args.date,
url: args.url,
description: args.description,
tags: args.tags
}
},
info
)
}
however, once I tried to put an array of strings(tags) as you see above I I can't get it to work and I got this error
Error: Variable "$_v0_data" got invalid value { ... , tags: ["devops", "aws"] }; Field "0" is not defined by type JobCreatetagsInput at value.tags.
If I assigned an empty array to tags in the mutation there is no problem, however if I put a single string value ["DevOps"] for example i get the error
The issue was in the resolver function apparently as I found here I have to assign the tags list within an object in the set argument like the code below
function addJob(parent, args, context, info) {
return context.db.mutation.createJob(
{
data: {
position: args.position,
componay: args.company,
date: args.date,
url: args.url,
description: args.description,
tags: { set: args.tags }
}
},
info
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With