laravel-lighthouse

How can i insert multiple data on same mutation in Laravel Lighthouse?


Can i insert multi on same mutation?

I wonder this is exist or not.

This is my Schema

type Test {
    id: ID
    name: String
    msg: String
}

input testInput {
    name: String
    msg: String
}

type Mutation {
    createTest(input: [testInput]): [Test] @create
}

This is my mutation query

mutation{
    createTest(input: [
        {id:1,  name: "test", msg:"hahaha",},
        {id:2, name: "test2", msg:"hahahaa" }
    ]) {
        id
        name
        msg
    }
}

Solution

  • You can use a custom mutation:

    php artisan lighthouse:mutation CreateTest
    

    If you want something reusable, you might want to implement a custom field resolver directive. Look into the implementation of @create for an idea on how that can be done.