Allow filtering on __typename

It would be great if you could allow filtering on __typename.

Given this schema:

interface Foo {
   v: String!
}

type Bar implements Foo {
   b: String!
}

type Baz implements Foo {
   b: String!
}

type Dataset {
   id: String! @id
   foos: [Foo!]!
}

I wan’t to count all instances of Bar and Baz for a given Dataset efficiently without transferring all instances back to the client. Something like the following would work great if filtering __typename would be allowed:

query GetInstanceCountForDataset($datasetID: String!) {
   barCount: getDataset($id: $datasetID) {
                       aggregateFoo(filter: {__typename: {eq: "Bar"} }) {
                          count
                       }
                    }
   bazCount: getDataset($id: $datasetID) {
                       aggregateFoo(filter: {__typename: {eq: "Baz"} }) {
                          count
                       }
                    }
}

I’m aware of that I could just add a datasetID field to Foo, use aggregateBar and filter for the datasetID. But I want to avoid to have these kind of duplicate information in my database.

Hi, has someone had time to have a look here?

Hi @maaft ,

This looks like a valid use case. I am accepting this as a feature request.

We can add a __typename filter to foosAggregate field. This will allow to get count and other aggregates for specific implementing types of interface.

Similar filter won’t be needed for foos field as ... on Baz could be used to filter out Baz.

I hope this satisfies your use case.

1 Like

I guess yes, this looks like exactly what I asked for! :slight_smile:

That’s true, although currently I’ll get empty dicts in the response for every Foo that is not a Baz. But that might be an unrelated issue:

query {
  queryFoo {
    ... on Baz {
      v
      b
    }
  }
}

"data": {
    "queryFoo": [
      {
        "v": "bla"
        "b": "blub"
      },
      {},
      {},
      {},
      {}
    ]