Can't fully delete an edge between nodes

I’m getting unexpected results where one query shows that I deleted an edge, but another query shows that I didn’t.

Here’s what I did:

  1. Created a Post with two [Tags]
  2. Remove one of the tags on the Post
  3. Get the individual Post, proving that the tag has been removed
  4. Get the individual Tag that was removed, proving that it no longer has a relationship with the Post
  5. Get Posts filtering by the deleted tag, and see that the Post the Tag was removed from is still showing up in search results for the Tag that it used to have. (!?)

How do I make it so that the Post no longer shows up when filtering Posts by the Tag that was removed from it?

The schema is like this:

type Post {
  id: ID! 
  title: String!
  Tags: [Tag] @hasInverse(field: Posts)
}
type Tag {
  text: String! @id @search
  Posts: [Discussion] @hasInverse(field: Tags)
}

First the Post was updated to have Tags:

mutation {
  updatePost( 
    input: {
      filter: {
        id: ["0xfffd8d6aa9da05e8"]
      },
      set: {
        title: "Updated title",
        Tags: [{
          text: "random-tag"
        },{
          text: "new-tag"
        }]
      },
    }) {
    post {
      id
      title
      Tags {
        text
      }
    }
  }
}

Then new-tag was removed:

mutation {
  updatePost( 
    input: {
      filter: {
        id: ["0xfffd8d6aa9da05e8"]
      },
      remove: {
        Tags: [{ 
          text: "new-tag"
        }]
      }
    }) {
    post {
      title
      Tags {
        text
      }
    }
  }
}

When getting the Post by ID, it’s confirmed that new-tag is no longer there:

query {
  getDiscussion(id: "0xfffd8d6aa9da05e8") {
    title
    Author {
      username
    }
    Tags {
      text
    }
  }
}

Response:

"data": {
    "getPost": {
      "title": "Updated title",
      "Tags": [
        {
          "text": "random-tag"
        }
      ]
    }

And when getting the tag new-tag, it’s confirmed that it’s no longer connected to the Post:

query {
  getTag (text: "new-tag"){
    text
    Posts {
      id
      title
      Tags {
        text
      }
    }
  }
}

Response:

"data": {
    "getTag": {
      "text": "new-tag",
      "Posts": []
    }
  }

That seems like the edge has been removed, but it hasn’t really. Because when I filter Posts based on Tags, the Post the tag was removed from still shows up in search results for that tag:

query {
  queryPost @cascade(fields: ["Tags"]){
    id
    title
    Tags ( 
      filter: {
        text: {
          anyofterms: "new-tag"
        }
      }
    ){
      text
    }
  }
}

Response:

"queryDiscussion": [
      {
        "id": "0xfffd8d6aa9da05e8",
        "title": "Updated title",
        "Tags": [
          {
            "text": "random-tag"
          }
        ]
      }
    ]

How can I get the Post to stop showing in results for the tag it used to have?

I believe this snippet is your problem.

This anyofterms also matches random-tag you may want a eq instead of term match here

1 Like

Thank you! That was the problem.

It looks like hyphens are delimiters for anyofterms in addition to spaces. Is there an updated reference that documents which characters are delimiters for anyofterms? The docs say that only spaces are delimiters: https://dgraph.io/docs/query-language/functions/#anyofterms

The exact match would be great if I wanted to search by just one tag at a time. I had hoped that using anyofterms would allow me to search for items that have either of multiple tags, so that if I searched for two tags, I would get results with at least one of them.

Edit: Docs PR is here. Docs(GraphQL): Say that spaces aren't the only delimiter for anyofterms by catherineluse · Pull Request #260 · dgrap

1 Like

I believe any non alpha character is a delimiter of sorts. I know periods . can act as a delimiter as well. I have seen it before here in discuss as an issue.

instead of anyofterms how about using in? filter: { text: { in: ["new-tag","random-tag"] } }