I am working on a proof of concept using Apollo Federation. I am running in to a bit of a snag and I’m not sure how to move forward. I’ll share a bit of my schema across to subgraphs and then explain my desired behaviour, and hopefully someone will be able to help out.
Subgraph 1:
type Offer @key(fields: "referenceId") {
isAvailable: Boolean
partner: String
vertical: PreSelectionVertical
amount: Float
referenceId: String!
}
Subgraph 2:
type OfferCard implements DashboardCard {
id: ID!
title: String!
createdAt: DateTime!
updatedAt: DateTime!
partners: [Offer]!
}
extend type Offer @key(fields: "referenceId") {
referenceId: String! @external
cardCopy: CMSOfferProduct
}
type CMSOfferProduct @key(fields: "id") @key(fields: "referenceId") {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
partner: String!
referenceId: String!
titleCopy: String!
bodyCopy: String!
ctaCopy: String!
}
We have a resolver the returns a list of DashboardCard
objects, our OfferCard
contains a list of referenceId
referencing the offers we would like to render on this card in their preferred order. So in my resolver for OfferCard
we return, essentially:
OfferCard: () => {
return {
...theRestOfOurFields,
partners: [{referenceId: "1"},{referenceId:"2"}
}
}
then in our resolver for Offer
in __resolveReference
we make an API call for the referenceIDs that are received, and return all of the fields if present, or if the offer isn’t available for the current user we return Null
.
The problem is when an offer is not available for the current user, what we are receiving in our GraphQL response is:
products: [{
"referenceId": "1",
"vertical": null,
"partner": null,
"isAvailable": null,
}]
Is it possible to, instead of have all the fields set to null and the referenceId to be defined, to have the whole object be set to null? Or, better yet, have a union on subGraph2 that is a union of two entities that exist on subGraph1 i.e
union OfferResponse = Offer | OfferNotValid`
Hoping someone has a tip for how to resolve this! Thanks.