GraphQL interfaces and unions — how to design GraphQL schema

David Mráz
Atheros
Published in
6 min readJul 3, 2019

--

Introduction

This article is a part of free GraphQL Language course. To fully understand the content you need to be familiar with basic GraphQL concepts like SDL language, GraphQL document syntax or GraphQL object types and scalars. If you do not have this knowledge, you can take a look at our older articles.

In the GraphQL specification we are able to use two abstract types:

  • interfaces
  • unions

In this article, we will go through the use cases for abstract types and how we can implement them in our GraphQL schema. Using abstract types can greatly improve your GraphQL schema design and simplify your queries and mutations.

What is an interface?

Let’s first define what is an interface in programming. There are various definitions for interfaces, but I found out that the most useful one for understanding GraphQL interfaces is as follows:

The interface is a structure that enforces certain properties on the object or class that implements the corresponding interface

Interfaces are usually needed when we are looking to access a certain group of objects that has to comply with properties defined by the interface. With the…

--

--

David Mráz
Atheros

Founder of https://atheros.ai | Artificial Intelligence | Machine Learning | JavaScript, Python, C++ | Business