# Using unions and interfaces and end up with non-nullable field not present

**URL:** <https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680>\
**Category:** GraphQL\
**Tags:** area:interface\
**Created:** [September 28, 2021, 3:52pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680 "2021-09-28T15:52:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lumi](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@lumi](https://discuss.dgraph.io/u/lumi)\
**Post date:** [September 28, 2021, 3:52pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/1 "2021-09-28T15:52:51Z")

</div>

Hello,

I’m wondering if what i came across is a normal behaviour or a bug. Let’s say I have the following schema:

```auto
interface EntityInBoxInterface {
    id: ID!
    name: String! @search(by: [term])
}
 
type Object implements EntityInBoxInterface {
    data: String
}
 
type Face implements EntityInBoxInterface {
    data: String
    nose: Int! @search # nose position or something like that
}
 
union EntityInBox = Object | Face
 
type Box
{
    id: ID!
    entity: EntityInBox!
    x0: Float! @search
    y0: Float! @search
    x1: Float! @search
    y1: Float! @search
}

```

Field ‘nose’ is non nullable in type ‘Face’. However, the below mutation (without ‘nose’) works:

```auto
curl --request POST \
  --url http://localhost:8080/graphql \
  --header 'Content-Type: application/json' \
  --data '{"query":"mutation {\n addBox ( input: {\n x0: 1.0, x1: 2.0, y0: 3.0, y1: 4.0, entity: { faceRef: { name: \"someface\"} }\n })\n {numUids}\n}"}'

```

and I end up with the ‘Face’ node without ‘nose’. Then the below query

```auto
curl --request POST
     --url localhost:8080/graphql
     --header 'Content-Type: application/json'
     --data '{"query":"query {\n queryFace(first:10)\n {\n id\n nose\n }\n}"}' | python3 -m json.tool

```

returns the error message - “Non-nullable field ‘nose’ (type Int!) was not present in result from Dgraph. GraphQL error propagation triggered.”  
Is it meant to work like this?

i’m running dgraph locally in a docker using the following command:

```auto
sudo docker run -it -d -p 8080:8080 dgraph/standalone:master

```

Regards

---

<div class="post-metadata">

**Author:** ![Poolshark](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/poolshark/32/10074_2.png) [@Poolshark](https://discuss.dgraph.io/u/Poolshark)\
**Post date:** [September 29, 2021, 5:12pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/2 "2021-09-29T17:12:17Z")

</div>

Hi! I would say this **is** the expected behaviour. In your mutation you only pass the field `name` in your field `entity` which is of **union type** `EntityInBox`. Since `nose` is missing your typename resolves to type **Object** instead of **Face**.

But I could be mistaken of course!

---

<div class="post-metadata">

**Author:** ![lumi](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@lumi](https://discuss.dgraph.io/u/lumi)\
**Post date:** [September 29, 2021, 7:11pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/3 "2021-09-29T19:11:22Z")

</div>

Thanks for reply!

but i really think that the mutation creates a node of type ‘Face’. Basically because the following aggregateFace query returns count 1

```auto
curl --request POST --url localhost:8080/graphql --header 'Content-Type: application/json' --data '{"query":"query {\n aggregateFace(filter:{})\n {count}\n}"}' | python3 -m json.tool

```

i’m new to graphql so could be that i’m not getting it at all…

---

<div class="post-metadata">

**Author:** ![Poolshark](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/poolshark/32/10074_2.png) [@Poolshark](https://discuss.dgraph.io/u/Poolshark)\
**Post date:** [September 30, 2021, 3:51pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/4 "2021-09-30T15:51:38Z")

</div>

I’m not sure about this. I think it creates both, the Object AND the Face node since there is a union type. Try to query **Box** and resolve for `__typename`, I’d be curious what that would be?

---

<div class="post-metadata">

**Author:** ![lumi](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@lumi](https://discuss.dgraph.io/u/lumi)\
**Post date:** [September 30, 2021, 4:26pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/5 "2021-09-30T16:26:44Z")

</div>

I did query it with \_\_typename. The entity in the box type is indeed ‘Face’. Also i ran aggregateObject and it shows count 0.

---

<div class="post-metadata">

**Author:** ![Poolshark](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/poolshark/32/10074_2.png) [@Poolshark](https://discuss.dgraph.io/u/Poolshark)\
**Post date:** [October 8, 2021, 11:18pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/6 "2021-10-08T23:18:03Z")

</div>

So I guess the problem is that the mutation with `faceRef` should have failed in the first place since the field `nose` is mandatory. I guess the **input type** for the mutation **addBox** (and especially `faceRef`) does say otherwise?

---

<div class="post-metadata">

**Author:** ![lumi](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@lumi](https://discuss.dgraph.io/u/lumi)\
**Post date:** [October 11, 2021, 2:27pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/7 "2021-10-11T14:27:26Z")

</div>

correct. The mutation should fail as some mandatory fields are not being provided. But it all seems to work i.e. nodes get created. Not sure what you mean by ‘input type for the mutation’ ? How do you want me to modify the above queries to see that ?

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [October 12, 2021, 12:21am UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/8 "2021-10-12T00:21:57Z")

</div>

I don’t think you need to modify anything, I think the [@core-devs](https://discuss.dgraph.io/groups/core-devs) need to confirm this bug and add it to their list to fix.

---

<div class="post-metadata">

**Author:** ![pshaddel](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pshaddel/32/11584_2.png) [@pshaddel](https://discuss.dgraph.io/u/pshaddel)\
**Post date:** [October 12, 2021, 1:08pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/9 "2021-10-12T13:08:29Z")

</div>

I was encountered another bug related to union but it was ignored.

> **[Cannot query after deleting an entity that is used in a union type](https://discuss.dgraph.io/t/cannot-query-after-deleting-an-entity-that-is-used-in-a-union-type/15483)**
>
> 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: ▶...

---

<div class="post-metadata">

**Author:** ![Poolshark](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/poolshark/32/10074_2.png) [@Poolshark](https://discuss.dgraph.io/u/Poolshark)\
**Post date:** [October 12, 2021, 1:20pm UTC](https://discuss.dgraph.io/t/using-unions-and-interfaces-and-end-up-with-non-nullable-field-not-present/15680/10 "2021-10-12T13:20:00Z")

</div>

You cannot alter the schema which gets generated by Dgraph but you could check the **input type** which gets created by Dgraph. Just use the explorer tab in the GraphQL area on **Dgraph Cloud** and look for the **Query Name**. Then I guess you input type is called something like `AddBoxInput`. Click on it and check the fields.

It seems like @pshaddel has encountered a similar problem and it seems like a bug! Maybe you should consider submitting a ticket to the support team for that!
