GraphQL: "Non-nullable field was not present in result" on identically named fields under interface

Moved from GitHub dgraph/5516

Posted by CosmicPangolin:

What version of Dgraph are you using?

2020.03.1

Have you tried reproducing the issue with the latest release?

Yah

What is the hardware spec (RAM, OS)?

GCloud 8GB VM

Steps to reproduce the issue (command/config used to run Dgraph).

Consider the following schema:

type User {
     id: ID!
}

interface Things {
    id: ID!
    name: String!
}

type Stuff {
    id: ID!
    things: [Things!]
}

type ThingOne implements Things {
    creator: User!
}

type ThingTwo implements Things {
    creator: User!
}

type ThingThree implements Things {
    randomField: Int!
}

And, for Stuff containing some Things, a query of the form:

query {
     getStuff(id: "1337") {
          things {
               ...on ThingOne { creator {id} }
               ...on ThingTwo { creator {id} }
               ...on ThingThree { randomField }
          }
     }
}

Expected behaviour and actual result.

This query fails with “Non-nullable field was not present in result” for one of the creator fields. This seems to only be the case when fields share the same name, types share the same interface, but field is not in interface.

abhimanyusinghgaur commented :

Hi @CosmicPangolin,

This is most probably related to: #4878, as you have defined a User type which is also the name of the type which dgraph uses for storing ACL users and as you report that the problem is with creator fields which is of type User. We have a fix coming up for that.

Also, your query seems incomplete. As creator is of type User, it should have a selection set like this:

query {
     getStuff(id: "1337") {
          things {
               ...on ThingOne { creator { id } }
               ...on ThingTwo { creator { id } }
               ...on ThingThree { randomField }
          }
     }
}

But, please also update the issue description with the initial mutations you ran in order for us to reproduce this error.
And would be great if you could confirm whether or not you tried dgraph with ACL before performing the query/mutation.

abhimanyusinghgaur commented :

Linking another similar issue: #5366.

CosmicPangolin commented :

@abhimanyusinghgaur

I can confirm that, in my case, this has nothing to do with the type User. I renamed model/schema to Human and the same error persists. I am not using ACL.

Non-nullable field 'creator' (type Human!) was not present in result from Dgraph. GraphQL error propagation triggered.: Undefined location

abhimanyusinghgaur commented :

Thanks @CosmicPangolin.

This is a bug regarding fragment handling with interface implementations.

It has been fixed with this PR and is available in master. Will be part of release v20.7.2.