Can query node as child but not as parent. Node possibly deleted but still present in GraphQL on edge

Report a GraphQL Bug

What edition and version of Dgraph are you using?

Edition:

  • Dgraph Cloud formerly Slash GraphQL
  • Dgraph (community edition/Dgraph Cloud)

If you are using the community edition or enterprise edition of Dgraph, please list the version:

Dgraph Version: v20.11.2-rc1-16-g4d041a3a

Have you tried reproducing the issue with the latest release?

NA

Steps to reproduce the issue (paste the query/schema if possible)

interface Tag {
  id: ID!
  slug: String
  name: String
  # ...
}
type RelationshipCategory implements Tag {
  usedIn: [Relationship] @hasInverse(field: "type")
  # ...
}
type Relationship {
  id: ID!
  name: String
  type: RelationshipCategory!
  # ...
  of: Contact
  to: Contact
}
type Contact {
  id: ID!
  firstName: String
  # ...
  relationshipsTo: [Relationship] @hasInverse(field: "of")
  relationshipsOf: [Relationship] @hasInverse(field: "to")
}
query {
  queryRelationship(filter: { id: ["0x240013"] }) {
    __typename
    id
  }
  getRelationshipCategory(id: "0x225f22") {
    id
    usedIn(filter: {id:["0x240013"]}) {
      __typename
      id
    }
  }
}

Expected behaviour and actual result.

Expected: To see node with uid of 0x240013 in queryRelationship if it exists such as the following

{
  "data": {
    "queryRelationship": [
      {
        "__typename": "Relationship",
        "id": "0x240013"
      }
    ],
    "getRelationshipCategory": {
      "id": "0x225f22",
      "usedIn": [
        {
          "__typename": "Relationship",
          "id": "0x240013"
        }
      ]
    }
  },
  // ...

Actual: Doesn’t return node 0x240013 in queryRelationship response :x: :confused:

{
  "data": {
    "queryRelationship": [],
    "getRelationshipCategory": {
      "id": "0x225f22",
      "usedIn": [
        {
          "__typename": "Relationship",
          "id": "0x240013"
        }
      ]
    }
  },
  // ...

DQL query:

{
  node(func: uid(0x240013)) {
    uid
    expand(_all_)
  }
}

Returns:

{
  "data": {
    "node": [
      {
        "uid": "0x240013"
      }
    ]
  },
  // ...

Notice no dgraph.type, and no other predicates for this node, which leads me to believe it was a node that was deleted but an edge to it still remains possibly??

I fixed these by running this upsert:

upsert {
  query {
    var(func:uid(0x225f22)) {
    	parentID as uid
    	RelationshipCategory.usedIn @filter(NOT has(dgraph.type)) {
      	  children as uid
    	}
    }
  }
  mutation {
    delete {
      uid(parentID) <RelationshipCategory.usedIn> uid(children) .
    }
  }
}

I am going to leave this open as it poses a bug in the GraphQL API returning a node that does not have a type. Logistically speaking the node does not have anything and really doesn’t exist other than being an endpoint of edges.

I will see if this comes back later on, but I think I may have introduced these empty nodes myself with a bad DQL mutation once upon a time.

@graphql can you look into this from the perspective that nodes on an edge shouldn’t be returned if they don’t have the correct type.