Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mutation with list of strings Variable "$_v0_data" got invalid value Graphql Node.js

Tags:

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

like image 912
Mo Hajr Avatar asked Nov 04 '18 17:11

Mo Hajr


1 Answers

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
    )
}
like image 154
Mo Hajr Avatar answered Oct 11 '22 14:10

Mo Hajr