maaft
February 26, 2021, 10:44am
1
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.
1 Like
maaft
April 9, 2021, 1:49pm
3
Hi, has someone had time to have a look here?
rajas
(Rajas Vanjape)
April 9, 2021, 2:41pm
4
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.
3 Likes
maaft
April 9, 2021, 3:14pm
6
I guess yes, this looks like exactly what I asked for!
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"
},
{},
{},
{},
{}
]
denis111
(Denis Kalgushkin)
July 1, 2021, 4:41pm
7
It would be useful for any filter, like:
query something($name: String!, $type: String!) {
querySomeInterface(filter: {
name: $name
and: {
__typename: $type
}
}) {
...
}
}
1 Like
maaft
July 2, 2021, 6:44am
8
Hi @denis111 !
You could just use queryImplementation
in that case. If you want to “filter” mutliple implementations, you could either do this:
query {
queryImplementation1(filter: {... }) { ... }
queryImplementation2(filter: { ... }) { ... }
}
or this:
query {
querySomeInterface(filter: { ... }) {
... on Implementation1 { ... }
... on Implementation2 { ... }
}
}
denis111
(Denis Kalgushkin)
July 2, 2021, 7:06am
9
Thanks @maaft . That’s true but I can’t pass type name as query parameter such way. In DQL I can filter by dgraph.type without a problem.
2 Likes
kolmez
(Kadir Olmez)
September 26, 2021, 5:55pm
10
Is this added in the latest release?
Update: Just tried this and it seems this isn’t available in the current release (v21.03). Correct me if I’m wrong…
2 Likes