5

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

4
  • please add the code for the mutation Commented Nov 4, 2018 at 19:21
  • @Peter Added it. Commented Nov 5, 2018 at 6:53
  • Did you change your mutation schema recently? Did you prisma deploy? It seems like the type JobCreatetagsInput is not expecting this String type. Commented Nov 7, 2018 at 1:35
  • @Elfayer No, it's not changed at all and if I tried Prisma deploy the schema is up to date, and about this is the JobCreatetagsInput , input JobCreatetagsInput { set: [String!] } Commented Nov 7, 2018 at 9:12

1 Answer 1

4

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
    )
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for sharing, works as a charm is not clear about this in the doc.
@Merlyn007 glad it helped ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.