mlipscombe/postgraphile-plugin-nested-mutations

Nested mutation not working (connectById)

brendanmckenzie opened this issue · 9 comments

When I run this mutation, the entity is updated correctly. PropertyId on the QuoteDay entity is set to the specified value.

  updateQuoteDay(
    input: {
      patch: {
        propertyToPropertyId: {
          connectById: { id: "36e59cbe-5900-4b94-a5e7-e0ffcdfcf40d" }
        }
      }
      id: "a8a63915-52b7-4295-92b3-a0cd31ff63df"
    }
  ) {
    clientMutationId
  }

However, if I run this mutation nested, the entity is not updated correctly. PropertyId on the QuoteDay entity remains unchanged.

  updateQuote(
    input: {
      patch: {
        quoteDaysUsingId: {
          updateById: {
            patch: {
              propertyToPropertyId: {
                connectById: { id: "36e59cbe-5900-4b94-a5e7-e0ffcdfcf40d" }
              }
            }
            id: "a8a63915-52b7-4295-92b3-a0cd31ff63df"
          }
        }
      }
      id: "259795ae-af62-4d19-a12e-dc59513af43c"
    }
  ) {
    clientMutationId
  }

Interestingly, if I specify an invalid UUID (with additional characters) in the example that does not work, GraphQL does not complain. If I specify an invalid UUID in the example that does work, GraphQL does complain.

It might be worth noting that patching other properties on "Quote_Day" works as expected in both scenarios.

Further investigation shows that this works on create but not on updateById

I had a crack at debugging this and found that in pgNestedTableUpdate the propertyToPropertyId type fields are not handled, propertyId is processed, but not propertyToPropertyId as elsewhere. It appears they only work at a higher level in the mutation.

I will attempt to track this down and see if I can implement this functionality recursively.

Another example of where this does/doesn't work.

{
  "quoteFinanceLineItemsUsingId": {
    "create": [
      {
        "supplierToSupplierId": {
          "connectById": { // this works as expected
            "id": "e86ce9eb-88f3-4d38-aadd-716b22189497"
          }
        }
      }
    ],
    "updateById": [
      {
        "id": "6b52c1f9-92fe-488a-9c6f-2824e90141ee",
        "patch": {
          "supplierToSupplierId": {
            "connectById": { // this does not work, it is ignored
              "id": "1e6e589a-3f4c-44be-8fb6-a7c422fbd961"
            }
          }
        }
      }
    ]
  }
}

I've also encountered this issue. Thanks for raising as it saved me a lot of time debugging.

@brendanmckenzie are you able provide an example schema to create a test case so I can work out a fix?

Certainly!

I've created this Gist with the schema, the working mutation, and the mutation that's not working.

And this is what I threw together to test with (though CLI probably would have been easier in hindsight).

Hello, Any update on this? I have a similar issue where the update doesn't work with multiple nested object...
In my case I have this structure:

media { id }
gallery { id }
gallery_item { id, gallery_id, media_id }

When I try to update a media from the gallery mutation it doesn't work.

Just stumbled across this myself... Any progress?