laravel-lighthouse

Lighthouse nested delete mutation is not worked


I have tried to nested delete mutation. But it is not worked.

But i dont know why it is not worked.

I have table A and B.

One data of A can have a lot of data of B

So inside of A model, i write relation like below.

public function bRelation(): HasMany
{
    return $this->hasMany('App\Models\A', 'A_id', 'id');
}

This is not real, but abbreviated version of my schema.

extend type Mutation {
    createA(input: AInput@spread):   A@create
    updateA(input: AInput@spread):   A@update
    deleteA(input: AInput! @spread): A@delete    
}

input AInput{
    id: ID
    bRelation : bRelationInput
}

input bRelationInput{
    create: [bInput]
    update: [bInput]
    delete: [ID!]
}

input bInput {
    id: ID
}

I first used postman like below.

enter image description here

Data which id is 35 of table A is deleted. But table b data is not deleted.

Even i changed schema and data like below. result is same. b data is not deleted

input bRelationInput{
    create: [bInput]
    update: [bInput]
    delete: Boolean
}

enter image description here

What did i do wrong..??


Solution

  • You can just pass the id like below and the relation will be deleted!

    input bRelationInput {
    
    delete: ID