Filtering list predicates that contain a certain value/object

Hi all

I would like to run a query against an object that has a list predicate and want to receive only results that contain (or not contain) a certain value. I looked at the in filter function, but that does not work on the predicate.

Example type:

type MyLabel {
    name: String! @id @search(by: [exact, trigram])
    objects: [ MyObject ] @hasInverse(field: matches)
}

type MyObject { 
    name: String! @id @search(by: [term])
    labels: [ MyLabel ] @hasInverse(field: objects)
}

lets say I have two Labels with the names foo and bar and I want to filter all MyObjects that are not labelled with foo.

I tried a query like

query {
   queryMyObject(filter: {name: {regexp: "/^trials/i"}}) @cascade {
       labels(filter: {not: {name: { eq: "foo" } } }) {
            label
       }
   }
}

This gives me all objects with a name that starts with trials and with labels other than foo. However, I want to get only the objects that don’t have label foo in their labels list at all and not just remove foo from the labels list. The in function works in the other direction and is therefore no option, either.

I would like to do something like the following.

query {
   queryMyObject(filter: {name: {regexp: "/^trials/i"}}) @cascade {
       labels(filter: {not: {name: { contains: "foo" } } }) {
            label
       }
   }
}

This obviously does not work.

I feel a bit at a loss here and wonder what would be a smart solution to retrieve all MyObjects that don’t contain a certain label in a list predicate. While the positive case without not is trivial, the inverse appears to be impossible.

Thank you for your advise and better query strategies

Christian.

Hi @phish108,

Looks like there’s a two way, multi-inverse edge in your schema – maybe. I think the schema you presented is incomplete/incorrect? There’s no field matches in the MyObject type.

Can you update this post with a corrected schema and maybe a few records so that I can investigate a solution?

I will say that it’s most likely a case for custom DQL as the GraphQL API generation does not create query endpoints for every possible permutation of connected query filters.

Hi @matthewmcneely

It took me a while because I was busy with other tasks.

It was a mere typo in the schema. It should have read:

I tried to dumb the problem down to a minimal GraphQL schema, while being close to my actual logic.

Here are some Labels:

[
    {
       "name": "foo",
       "objects": ["moo", "boo"] 
    },
    {
       "name": "bar",
       "objects": ["trials mar", "moo"] 
    },
    {
       "name": "baz",
       "objects": ["trials mar", "boo"] 
    }
]

… and some Objects:

[
    {
       "name": "moo",
       "labels": ["foo", "bar"] 
    },
    {
       "name": "trials mar",
       "labels": ["baz","bar"] 
    },
    {
       "name": "boo",
       "labels": ["foo", "baz"] 
    },
    {
       "name": "car",
       "labels": ["bar"] 
    }
]

So the objective is to get all objects that do NOT have the label foo without specifying the assigned labels directly. With the example data I am looking for the objects trials mar and car. With the full query from the original post should yield only trials mar.

While a solution in DQL is suboptimal, I went that route but I got lost. Using DQL, I initially I thought of taking all objects in associated with the label foo and then use not(uid_in()), but it did not work. I then thought about using edge attributes, but these are unavailable to GraphQL.