Joystream / hydra

A Substrate indexing framework
49 stars 45 forks source link

Reverse lookups inspecting unions #187

Open bedeho opened 3 years ago

bedeho commented 3 years ago

How hard would this be to faciliate?


type AnotherPersonInvited @variant {
  invitor: Person! 
}

union InvitationSource = AnotherPersonInvited | Genesis | Sudo | ...

type Person {

 invitedBy: InvitationSource

 invitees: [Person!]! @derivedFrom(field: "invitedBy.AnotherPersonInvited.invitor")

 }
dzhelezov commented 3 years ago

As of today, variant types can't be too complex and reference an entity. At the database level, variant type fields are stored as JSONs in the respective entities columns. Unless we redesign this approach, we'd need to implement some non-trivial manipulation of these non-structured fields and it's hard to enforce PK constraints.

bedeho commented 3 years ago

I thought you said that PostgreSQL had some very simple JSON aware filtering we could use, after all we are allowing such filtering on normal entity member fields that are unions? So isn't it just a matter of turning "invitedBy.AnotherPersonInvited.invitor" into some JSON equivalent and adding this into the WHERE part of whatever SELECT statement is powering the derivedFrom.

An up front nice to have would be that when validating the input schema that the "invitedBy.AnotherPersonInvited.invitor" path actually matches some leaf node in the type tree of InvitationSource which has the correct type Person, and warn the user if not. But this would be the cherry on top.