Abstract Type Interfaces

Learn what interfaces are and how to use them in GraphQL.

We'll cover the following

Using interfaces

GraphQL interfaces are similar to unions, with the key difference that any member type must define a set of included fields. This may remind you of interfaces in other languages.

For search results, we know that we want to access the name field easily. It’s fair to say that a search result should always include a name. It’s a simple constraint and doesn’t require us to add any fields to our :menu_item and :category types. We need to convert our :search_result to an interface and indicate that our types belong to it.

First, we’ll convert our :search_result type to an interface:

Get hands-on with 1200+ tech skills courses.