hydra icon indicating copy to clipboard operation
hydra copied to clipboard

feat(hydra-cli): add subclass filtering support for interfaces

Open dzhelezov opened this issue 3 years ago • 0 comments

affects: @joystream/hydra-cli, @joystream/hydra-e2e-tests

this lays out a ground work for #438 Solution 1. This commit adds support for primitive fields on subclasses and adds an e2e-test for it.

In particular, it already supports queries of the form

query getLatestMembershipEvents($memberId) {
  events(
    where: {
        type_in: [MembershipBoughtEvent, MemberProfileUpdatedEvent, MemberAccountsUpdatedEvent],
        membershipBoughtEvent: { newMemberId: $memberId },
        memberProfileUpdatedEvent: { memberId: $memberId },
        memberAccountsUpdatedEvent: { memberId: $memberId }
    },
    limit: 5,
    orderBy: [inBlock_DESC, indexInBlock_DESC]
  ) {
    ... on MembershipBoughtEvent {
      ...MembershipBoughtEventFields
    }
    ... on MemberProfileUpdatedEvent {
      ...MemberProfileUpdatedEventFields
    }
    ... on MemberAccountsUpdatedEvent {
      ...MemberAccountsUpdatedEventFields
    }
  }
}

but does not allow

where: {
    type_in: [
        OpeningFilledEvent,
        # ...
    ],
    openingFilledEvent: {
        hiredWorkers_some: { id: $workerId }
        # ...
    }
}

The latter require a better support for joins which is now a bit hacky and implemented in hydra-cli/src/templates/entities/service.ts.mst Indeed this part should be moved to the warthog library (together with all the tweaks introduced in hydra-cli/src/templates/graphql-server/src/WarthogBaseService.ts.mst

dzhelezov avatar Jun 30 '21 16:06 dzhelezov