# Union Types in Schema Via GraphQL API?

**URL:** https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380
**Category:** GraphQL
**Tags:** graphql
**Created:** [April 20, 2020, 2:45pm UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380 "2020-04-20T14:45:50Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![ttlekich](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@ttlekich](https://discuss.dgraph.io/u/ttlekich)
#### Post date: [April 20, 2020, 2:45pm UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/1 "2020-04-20T14:45:50Z")

</div>

I am curious if the new GraphQL API supports union types? I could not seem to find it in the [documentation here](https://graphql.dgraph.io/docs/schema/#Types), but it seems like it has been [mentioned before](http://discuss.hypermode.com/t/union-type-a-type-value-of-multiple-types/5055/3).

Here is an example of a way I’d like to specify the schema (if another strategy is better, please let me know!):

`schema.graphql`

```auto
type A {
    ...other fields
    bs_and_cs: [Thing]
}
 
type B {
   ...fields
}
 
type C {
    ...fields
} 

union Thing = B | C

```

If I have a schema like this (with more specific names of course), and try to post it to a locally running instance with: `curl -X POST localhost:8080/admin/schema -d '@schema.graphql'`, the parser seems to have issues with the union type(s): `couldn't rewrite mutation updateGQLSchema because input:1: Unexpected Name \"C\"\n"`

Thank you!

---

<div class="post-metadata">

### Author: ![ttlekich](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@ttlekich](https://discuss.dgraph.io/u/ttlekich)
#### Post date: [April 20, 2020, 3:22pm UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/2 "2020-04-20T15:22:18Z")

</div>

It seems as though an `interface` type might work for a case where there are similar fields between B and C. Though, a union type might be more ideal.

```auto
interface Thing {
    similar_field: String
}

type A {
    ...other fields
    things: [Thing]
}
 
type B implements Thing {
   ...fields
}
 
type C implements Thing {
    ...fields
} 

```

---

<div class="post-metadata">

### Author: ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)
#### Post date: [April 20, 2020, 4:18pm UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/3 "2020-04-20T16:18:25Z")

</div>

Hey @ttlekich

Union types aren’t supported yet but you can expect support for it soon (sometime next month). Interface types are supported as you would have found out.

---

<div class="post-metadata">

### Author: ![ttlekich](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@ttlekich](https://discuss.dgraph.io/u/ttlekich)
#### Post date: [April 21, 2020, 1:14pm UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/4 "2020-04-21T13:14:19Z")

</div>

@pawan Thank you so much! I figured they might be still being implemented/tested/etc., but thought I would ask just in case I missed something.

---

<div class="post-metadata">

### Author: ![mingsterism](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mingsterism/32/2787_2.png) [@mingsterism](https://discuss.dgraph.io/u/mingsterism)
#### Post date: [April 30, 2020, 10:19am UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/5 "2020-04-30T10:19:19Z")

</div>

Are we able to use @hasInverse with unions?  
@michaelcompton

```auto
type {
    favourites: [Things] @hasInverse(id)
}
union Things = Food | Drink

type Food {
    id: String! @id 
}
type Drink {
    id: String! @id
}

```

thanks  
Ming

---

<div class="post-metadata">

### Author: ![michaelcompton](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/michaelcompton/32/1774_2.png) [@michaelcompton](https://discuss.dgraph.io/u/michaelcompton)
#### Post date: [May 4, 2020, 4:45am UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/6 "2020-05-04T04:45:19Z")

</div>

Hi,

As per discussion above, there’s no unions yet … and no decisions on exactly what will be supported when they arrive.

For interfaces, however, inverses and ids are supported both in the interface and in the implementing types.

---

<div class="post-metadata">

### Author: ![jana](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jana/32/4104_2.png) [@jana](https://discuss.dgraph.io/u/jana)
#### Post date: [July 21, 2020, 4:37pm UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/7 "2020-07-21T16:37:28Z")

</div>

Hi folks, just curious to know any updates on “union”. 🤔  
We are in the process of moving our infrastructure to dgraph and union is one of the last hurdles we have.  
Thank you!

---

<div class="post-metadata">

### Author: ![JatinDevDG](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jatindevdg/32/3417_2.png) [@JatinDevDG](https://discuss.dgraph.io/u/JatinDevDG)
#### Post date: [July 23, 2020, 9:16am UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/8 "2020-07-23T09:16:47Z")

</div>

Hi @jana , Happy to hear that you are moving your infrastructure to Dgraph.  
We will start working on UNION soon and it will be added in at max 6-8 weeks .

---

<div class="post-metadata">

### Author: ![pranaypratyush](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pranaypratyush/32/4264_2.png) [@pranaypratyush](https://discuss.dgraph.io/u/pranaypratyush)
#### Post date: [August 1, 2020, 11:33am UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/9 "2020-08-01T11:33:03Z")

</div>

Anything on unions yet? Eagerly waiting for it.

> [@ttlekich](#):
>
> ```auto
> interface Thing {
> similar_field: String
> }
> 
> type A {
> ...other fields
> things: [Thing]
> }
>  
> type B implements Thing {
> ...fields
> }
>  
> type C implements Thing {
> ...fields
> } 
> 
> ```

Does this work? Is this tested? Can we have nodes of type Thing?

---

<div class="post-metadata">

### Author: ![abhimanyusinghgaur](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/abhimanyusinghgaur/32/2980_2.png) [@abhimanyusinghgaur](https://discuss.dgraph.io/u/abhimanyusinghgaur)
#### Post date: [August 2, 2020, 4:56am UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/10 "2020-08-02T04:56:02Z")

</div>

Please be patient, unions will arrive in a bit.

Yes, interfaces work. You can have the above schema. You can’t create nodes of interface `Thing`, but you can create nodes of type `B` and `C`. Once created, they can behave as nodes of interface `Thing`.

---

<div class="post-metadata">

### Author: ![abhimanyusinghgaur](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/abhimanyusinghgaur/32/2980_2.png) [@abhimanyusinghgaur](https://discuss.dgraph.io/u/abhimanyusinghgaur)
#### Post date: [August 24, 2020, 8:21am UTC](https://discuss.dgraph.io/t/union-types-in-schema-via-graphql-api/6380/11 "2020-08-24T08:21:43Z")

</div>

Hi @ttlekich @mingsterism @jana @pranaypratyush,  
Please have a look at the [RFC for Union Types](http://discuss.hypermode.com/t/rfc-union-types-in-graphql/9581). Hoping to get some feedback.

Thanks
