nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.37k stars 439 forks source link

Mutation transaction seem not work #2546

Closed namttdh closed 7 months ago

namttdh commented 7 months ago

Describe the bug I try using tranasction with Lighouse but it seem it not working

lighthouse.php

 'transactional_mutations' => true,

My Schema

type Order {
    "Unique primary key."
    id: ID!

    ...

    orderBill: OrderBill @hasOne

  ...
}

type OrderBill {
    id: ID!

    ....

    order: Order @belongsTo

    created_at: DateTime!

    updated_at: DateTime!
}

extend type Mutation @guard {
    createOrder(createOrderInput: OrderInput @spread): Order! @create
}

input OrderInput {
    orderBill: AddressOrderInput!
}
input OrderAddressInput {
    id: ID
    name: String
    phone: String
    address_1: String
    address_2: String
    city: String
    postcode: String
    state: String
    country: String
}

input AddressOrderInput {
    create: OrderAddressInput
}

Query Run

mutation Mutation($createOrderInput: OrderInput) {
  createOrder(createOrderInput: $createOrderInput) {
    code  
    }
    orderBill {
      address_1
    }   
  }
}

Variable:

{
  "createOrderInput": {
    "orderBill": {
      "create": {
        "address_2": "test",
        "address_1": "test",
        "city": "test",
        "country": "test",
        "name": "test",
        "phone": "test",
        "postcode": "test",
        "state": "test"
      }
    }
  }
}

Error when run (i remove fields deleted_at to make this error) and was expect order not insert to database. But it still insert to postgres.

"debugMessage": "SQLSTATE[42703]: Undefined column: 7 ERROR:  column order_bills.deleted_at does not exist\nLINE 1: ...bills\" where \"order_bills\".\"order_id\" in ($1) and \"order_bil...\n                                                             ^ (Connection: pgsql, SQL: select * from \"order_bills\" where \"order_bills\".\"order_id\" in (9bdc0de0-b9b0-4421-a67b-1594a46a4207) and \"order_bills\".\"deleted_at\" is null)",

Lighthouse Version Laravel 10.10 PHP-lighouse 6.36

spawnia commented 7 months ago

The error you show happens during execution of the selection, not the root field. I explained this behaviour better in https://github.com/nuwave/lighthouse/commit/c6748470694afb08ac424afa1308282519a9bd03.

namttdh commented 7 months ago

@spawnia any change we can make it for nested?

Because base on that https://lighthouse-php.com/master/eloquent/nested-mutations.html#partial-failure it should to to work like i expected.

Or else what case does transaction work?

spawnia commented 7 months ago

I am saying there is an error when getting the result. Try removing the orderBills field from the selection.

namttdh commented 7 months ago

@spawnia, ahh, i see, that work now. Thank you!