outcaste-io / outserv

Blockchain Search with GraphQL APIs
https://manishrjain.com/outserv-graphql-blockchain-search
Other
197 stars 15 forks source link

Deleting an object that is present in a union field but failing to remove the reference to it causes the API to error #45

Open benwoodward opened 2 years ago

benwoodward commented 2 years ago

Example:

union TextContainer = Word | Phrase

type Paragraph {
  id: ID!
  textContainers: [TextContainer]
  words: [Word!] @hasInverse(field: paragraph)
  phrases: [Phrase] @hasInverse(field: paragraph)
}

type Word {
  id: ID!
  text: String! @search(by: [regexp])
  paragraph: Paragraph!
  phrase: Phrase
}

type Phrase {
  id: ID!
  paragraph: Paragraph!
  words: [Word!]! @hasInverse(field: phrase)
}

If I run deletePhrase() to delete one of the Phrase objects referenced in the Paragraph.textContainers union list, then the API returns the following:

{
  "errors": [
    {
      "message": "Non-nullable field 'xid' (type String!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 12,
          "column": 9
        }
      ],
      "path": [
        "paginateParagraphsWithPhrases",
        0,
        "textContainers",
        3,
        "xid"
      ]
    }
  ],
"data": {
    "paginateParagraphsWithPhrases": [
      {
        "id": "0x42024",
        "transcript": {
          "id": "0x41f6a"
        },
        "start": 0.15,
        "end": 4.19,
        "textContainers": [
          {
            "__typename": "Word",
            "xid": "06dd22c3-3f52-4c4b-aa10-dc177f65e9ee",
            "text": "I'm"
          },
          {
            "__typename": "Word",
            "xid": "0174abd9-a708-4b6f-8f08-e6ae8f36c427",
            "text": "I"
          },
          {
            "__typename": "Phrase",
            "words": [
              {
                "xid": "b42505e7-0379-49c1-95de-64f0ff95212f",
                "text": "only"
              },
              {
                "xid": "e5941e95-8078-487b-a750-15e426dcfa0c",
                "text": "joking."
              }
            ]
          },
          null
        ]
      },

Notice that there is a null in the textContainers list. Desired behaviour is for deleting the Phrase to remove it from the list, or at the very least for the API to just ignore null references.

EDIT: The problem I have now is that I have no idea how to remove that null reference from the list. So the data is effectively corrupted as a result of this simple operation.

This is a problem I'm experiencing in 20.03, I'm assuming it's still an issue in Outserv.

manishrjain commented 2 years ago

Outserv is a full rewrite of GraphQL mutations. So, this might not be an issue in Outserv. Can you try this with Outserv?