Joystream / hydra

A Substrate indexing framework
49 stars 44 forks source link

Deeply nested variants #396

Open Lezek123 opened 3 years ago

Lezek123 commented 3 years ago

Moved from: https://github.com/Joystream/joystream/pull/2345#issuecomment-838429476

Deeply nested variant types

There seems to be an issue with querying deeply nested varaint types, let's assume we have a following schema:

type ApplicationStatusPending @variant {
  # No additional information needed
  _phantom: Int
}

type ApplicationStatusAccepted @variant {
  "Related OpeningFilled event"
  openingFilledEvent: OpeningFilledEvent!
}

type ApplicationStatusRejected @variant {
  "Related OpeningFilled event"
  openingFilledEvent: OpeningFilledEvent!
}

type ApplicationStatusCancelled @variant {
  "Related OpeningCanceled event"
  openingCanceledEvent: OpeningCanceledEvent!
}

type ApplicationStatusWithdrawn @variant {
  "Related ApplicationWithdrawn event"
  applicationWithdrawnEvent: ApplicationWithdrawnEvent!
}

union WorkingGroupApplicationStatus =
    ApplicationStatusPending
  | ApplicationStatusAccepted
  | ApplicationStatusRejected
  | ApplicationStatusWithdrawn
  | ApplicationStatusCancelled

type WorkingGroupApplication @entity {
  "Application id ({workingGroupName}-{applicationId})"
  id: ID!

  "Related working group opening"
  opening: WorkingGroupOpening!

  "Current application status"
  status: WorkingGroupApplicationStatus!
  # ...

type WorkingGroupOpening @entity {
  "Opening id ({workingGroupName}-{openingId})"
  id: ID!

  "List of opening applications"
  applications: [WorkingGroupApplication!] @derivedFrom(field: "opening")

  # ...
}

When I'm executing the following query:

query {
    workingGroupApplications {
        id
        opening {
            id
        }
        status {
            __typename
            ...on ApplicationStatusAccepted {
                openingFilledEvent {
                 id
                }
            }
        }
    }
}

I'm getting some results like:

{
  "data": {
    "workingGroupApplications": [
      {
        "id": "contentDirectoryWorkingGroup-0",
        "opening": {
          "id": "contentDirectoryWorkingGroup-0"
        },
        "status": {
          "__typename": "ApplicationStatusAccepted",
          "openingFilledEvent": {
            "id": "-69-UePHPb"
          }
        }
      },
     # ...

But if I add one more level of nesting, by querying applications in a specific opening:

query {
    workingGroupOpeningByUniqueInput(where: { id: "contentDirectoryWorkingGroup-0" }) {
        applications {
            id
            opening {
                id
            }
            status {
                __typename
                ...on ApplicationStatusAccepted {
                    openingFilledEvent {
                        id
                    }
                }
            }
        }
    }
}

I get:

{
  "data": {
    "workingGroupOpeningByUniqueInput": {
      "applications": [
        {
          "id": "contentDirectoryWorkingGroup-0",
          "opening": {
            "id": "contentDirectoryWorkingGroup-0"
          },
          "status": {
            "__typename": "ApplicationStatusAccepted",
            "openingFilledEvent": null
          }
        }
      ]
    }
  }
}

Notice the openingFilledEvent is null in this case

dzhelezov commented 3 years ago

@metin This issue will be probably resolved if we integrate the following upstream warthog change to the fork we're using https://github.com/goldcaddy77/warthog/commit/5e137ced2a386509ac449e44562cd375699da6a4

Separate issue for that: https://github.com/Joystream/hydra/issues/411