Skip to main content

Unions & Interfaces

Introduction

In the Penneo KYC API we use unions and interfaces in several places.
We do this to represent multiple datatypes without having separate queries for each one.

One such example is Screenings which can be found on the Person type

Example

query getPersonWithScreenings($id: ID!) {
person(id: $id) {
id
name
timeCreated
timeLastEdited

screeningResults {
... on DowJonesScreeningResult {
source
matchScore

names
title

timeCreated
timeLastEdited
}

... on DanishPEPListScreeningResult {
source
matchScore

names
isCurrentlyPEP
position

timeCreated
timeLastEdited
}

... on EUSanctionsListScreeningResult {
source
matchScore

names
position

timeCreated
timeLastEdited
}
}
}
}

variables {
id: <ID>,
}

The screenings field can return:

They have unique fields and in order to specify which ones for each type, you use the three dots:

This enables the client to use one single query to get all screening results on a person, but still have specific data for the specific types.

They have unique fields and in order to specify which ones for each type, you use the three dots:

... on DanishPEPListScreeningResult

as shown in the example above.

External guide

The Apollo GraphQL project documentation has a good article explaining unions and interfaces in-depth here