Dgraph returns empty string for __typename when coupled with aggregate edge

Report a GraphQL Bug

What edition and version of Dgraph are you using?

Edition:

  • SlashGraphQL
  • Dgraph (community edition/Dgraph Cloud)

If you are using the community edition or enterprise edition of Dgraph, please list the version:

Dgraph Version: v20.11.2-rc1-16-g4d041a3a

Have you tried reproducing the issue with the latest release?

N/A

Steps to reproduce the issue (paste the query/schema if possible)

Create a type with a *:many edge. query the type and ask for the edge aggregate count and the __typename.

{
  queryContact {
    friendsAggregate { count }
    __typename
  }
}

Full examples in thread below.

Expected behaviour and actual result.

Dgraph returns "" for the __typename field for a node.

UPDATE

Here is how to duplicate this very easily and shows where the fault may lie in the query rewriter.

Schema:

type Contact {
  id: ID!
  friends: [Contact]
}

Mutation:

mutation {
  addContact(input: [{},{}]) { numUids }
}

Query without aggregate edge:

{
  queryContact {
    id
    friends { id }
    __typename
  }
}

Results have:

"__typename": "Contact"

Query with aggregate edge:

{
  queryContact {
    id
    friends { id }
    friendsAggregate { count }
    __typename
  }
}

Results will have:

"__typename": ""

I am using slash and there is no way that I know of to see the logs to see how the rewriter translated these two different queries to DQL to maybe help find the error.

@graphql This causes some really weird bugs in my application because Apollo Client depends upon this typename to properly cache results. Can we prioritize this bug?

Accepting this as I have managed to reproduce this on a different issue. @hardik I agree with @amaster507 - we should prioritize this bugfix

2 Likes

Hi @amaster507 ,

I have managed to reproduce this on the given version. This bug was introduced along with introducing aggregate fields to GraphQL and is present in 20.11. The bug is in the way DQL result is parsed and converted into GraphQL result.

We have managed to RCA this bug and a fix will soon be pushed to 20.11.

Current workaround to avoid __typename from returning empty string is to have the __typename field before the aggregate field in the query.

The following query will return __typename result properly.

{
  queryContact {
    id
    friends { id }
    __typename
    friendsAggregate { count }
  }
}

Thanks to the JSON changes by @abhimanyusinghgaur , this bug is not present in 21.03 and master.

1 Like

ah, thanks for the work around, I can manually define as the first field instead of depending on apollo client to append it.

1 Like

This has been fixed and will be part of next 20.11 release. Related PR: Fix(GraphQL): Fix __typename result along with aggregate fields by vmrajas · Pull Request #7687 · dgraph-io/dgraph · GitHub

1 Like