I want to create a model (let’s call it Link
) with a polymorphic reference any model, i.e. has a link: StreamID!
field. With this, it’s easy to pick up these links on any target model with a @relationFrom(model: "Link", property: "link")
directive.
What I’m wondering is if it’s possible to follow the outgoing relation on Link
somehow?
A little code example here to illustrate what I mean:
type Link
@createModel(accountRelation: LIST, description: "Link to things")
{
source: DID! @documentAccount
targetID: StreamID!
# not possible because no generic type exists
target: Any! @relationDocument(property: "targetID")
# maybe possible with union support, but needs to be changed every time a
# new type of target needs to be linked
target2: (Union Target = A | B | C)! @relationDocument(property: "targetID")
}
type MyType
@createModel(accountRelation: LIST, description: "A thing"
{
# easy peasy
incomingLinks: [Link] @relationFrom(model: "Link", property: "targetID")
}
Below is an example of where the query stops short. Since the targetID
field in the linkIndex
query is typed StreamID
there is no type to traverse into (no known fields). One can re-use the resulting streamID
in a second round-trip in a node(id: xyz) { ...on MyType }
and match it on the expected type, or try them all and see what returns. Is there no way of combining these?
# Is there a way of connecting the lower node() query with the upper one
# to continue traversal?
query {
linkIndex(first: 10) {
edges {
node {
targetID
}
}
}
node(id: "TARGET ID GOES HERE") {
... on MyType {
title
}
...on OtherType {
cid
}
}
So,
a) Is it impossible to traverse a StreamID
typed field?
b) If so, is there workaround (without having to do additional round trips) to resolve polymorphic links?