Using the local ElasticGraph test schema, run DEBUG_QUERY=1 bundle exec rake boot_locally. Then run this query:
query {
parts {
total_edge_count
nodes {
__typename
# ... on ElectricalPart {
# voltage
# }
}
}
}
It returns:
{
"data": {
"parts": {
"total_edge_count": 20,
"nodes": []
}
}
}
This is a nonsensical response: it says there are 20 results but none are returned!
If you uncomment the ... on ElectricalPart fragment, it works correctly:
{
"data": {
"parts": {
"total_edge_count": 20,
"nodes": [
{
"__typename": "MechanicalPart"
},
{
"__typename": "MechanicalPart"
},
{
"__typename": "ElectricalPart",
"voltage": 120
},
{
"__typename": "ElectricalPart",
"voltage": 120
},
{
"__typename": "ElectricalPart",
"voltage": 220
},
# ...
]
}
}
}
The DEBUG_QUERY=1 output shows the problem. For the first query, it's this:
[
{
"index": "electrical_parts,mechanical_parts"
},
{
"size": 0,
"track_total_hits": true,
"_source": false
}
]
For the 2nd query, it's this:
[
{
"index": "electrical_parts,mechanical_parts"
},
{
"size": 51,
"sort": [
{
"created_at": {
"order": "desc",
"missing": "_last"
}
},
{
"id": {
"order": "asc",
"missing": "_first"
}
}
],
"track_total_hits": true,
"_source": {
"includes": [
"voltage"
]
}
}
]
Notice the difference in size. I believe it has to do with the fact that no "real" fields are requested (just __typename) which causes ElasticGraph to not ask for any fields on the queried documents (no _source: {includes: [...]}) which in turn makes it ask for size: 0 since it doesn't think it needs any actual documents.
Notably, the query works if you use edges { node { ... } }:
query {
parts {
total_edge_count
edges {
node {
__typename
}
}
}
}
Returns:
{
"data": {
"parts": {
"total_edge_count": 20,
"edges": [
{
"node": {
"__typename": "MechanicalPart"
}
},
{
"node": {
"__typename": "MechanicalPart"
}
},
# ...
]
}
}
}
The logged query shows why it works:
[
{
"index": "electrical_parts,mechanical_parts"
},
{
"size": 51,
"sort": [
{
"created_at": {
"order": "desc",
"missing": "_last"
}
},
{
"id": {
"order": "asc",
"missing": "_first"
}
}
],
"track_total_hits": true,
"_source": {
"includes": [
"__typename"
]
}
}
]
I thought that nodes { ... } and edges { node { ... } } work the same so the fact that they are different here is concerning. We should evaluate if there are any other ways they differ.
It's a problem on concrete types, not just abstract types.
query {
addresses {
total_edge_count
nodes {
__typename
}
}
}
{
"data": {
"addresses": {
"total_edge_count": 10,
"nodes": []
}
}
}
[
{
"index": "addresses"
},
{
"size": 0,
"track_total_hits": true,
"_source": false
}
]
Interestingly, edges { node { __typename } } doesn't fix it here:
query {
addresses {
total_edge_count
edges {
node {
__typename
}
}
}
}
{
"data": {
"addresses": {
"total_edge_count": 10,
"edges": []
}
}
}
[
{
"index": "addresses"
},
{
"size": 0,
"track_total_hits": true,
"_source": false
}
]