I have set up a graphql schema where one of the fields ('items') is a list of objects which are a Union Type i.e. the list items can be one of two object types (in this case they are called 'packageOfferItem' and 'tileItem').
var searchResultItemType = new graphql.GraphQLUnionType({
name: 'SearchResultItems',
types: [ packageOfferItem, tileItem ],
resolveType: function (value) {
if (value.type === 'packageOffer') {
return packageOfferItem;
} else if (value.type === 'tile') {
return tileItem;
} else {
return null;
}
}
});
var searchResultItemsType = new graphql.GraphQLList(searchResultItemType);
The items field is then of type searchResultItemsType.
In my tests I have a query which requests data from items filed using the notation:
{
items {
...on packageOfferItem {
id
}
}
}
In my test I get an error [Error: Unknown type "packageOfferItem".] message: 'Unknown type "packageOfferItem".' } ]
Where is this error coming from?? packageOfferItem is a graphql NamedType so I don't understand why there is an error in the query response.
Introspection of the schema does not throw any errors so the schema itself is syntactically valid.