Filter Posting List by ID

Hi all,

It would be really useful to be able to filter a Posting List by an ID, as you can do for the root query level.

E.g. in the friends node below.

me (id: <uid>) {
    name
    friends (id: <uid>) {
        name
    }
}

At the moment, it doesn’t throw an error if I try and run this, but it will also not filter anything (returning the entire PL as if I had not added a filter at all).

Use Case

  1. Check if a particular friend exists or not, so I can say whether they are friends, and if they do exist return their details.
  2. Check if a user has the correct level of permissions.

Not sure if there is another way to achieve this functionality, I’d welcome any comment. Either way, I think adding a feature to allow filtering of a PL by ID would be useful.

2 Likes

I’ve been playing around a little more with this. I can actually get this to work with var (albeit a bit awkwardly).

{
  var (id: <uid>) {
    A as _uid_
  }

  me (id: <uid>) {
    name
    hasFriend: count(friends @filter(var(A))) 
    friends @filter(var(A)) {
      name
    }
  }
}

I think <uid> should be made into a first-class filter object. So I could write:

{
  me (id: <uid>) {
    name
    hasFriend: count(friends @filter(<uid>)) 
    friends @filter(<uid>) {
      name
    }
  }
}

We could even make it so that @filter(<uid>) always returns a list/array, whereas (id: <uid>) returns an object.

We could potentially have a uid function, which can be used for the purposes of filtering, or even at the root, instead of id: <uid>. If you think this is useful, feel free to file a Github issue, and we’ll get to it.

That sounds like a good idea, and a function might allow the user to enter multiple uid and probably help the parser. I’ve raised the GitHub issue.

I think it would be useful to keep the distinction between a filter which always returns a list/array of items and an ID which returns an object?

Also, I like the idea of using a @filter at root - I’ve created a separate thread to discuss thinking behind that (Why differentiate between root and sub-nodes?).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.