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
screeningResults {
... on DowJonesScreeningResult {
source
matchScore
names
title
timeCreated
timeLastEdited
}
... on DanishPEPListScreeningResult {
source
matchScore
isCurrentlyPEP
names
timeCreated
timeLastEdited
}
... on EUSanctionsListScreeningResult {
source
matchScore
names
birthDates
timeCreated
timeLastEdited
}
}
timeCreated
timeLastEdited
}
}
variables {
id: <ID>,
}
The screenings field can return either a
DowJonesScreeningResult
,
DanishPEPListScreeningResult
or a
EUSanctionsListScreeningResult
.
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