Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add subentities support #189

Merged
merged 1 commit into from
Jan 19, 2023
Merged

feat: add subentities support #189

merged 1 commit into from
Jan 19, 2023

Conversation

Sekhmet
Copy link
Contributor

@Sekhmet Sekhmet commented Jan 18, 2023

Summary

Closes #166

This PR adds @derivedFrom directive support that can be used to create 1-n queries.

Test plan

Add a field on some entity that references other entity for example:

type Space {
  id: String!
  proposals: [Proposal]! @derivedFrom(field: "space")
}

type Proposal {
  id: String!
  space: Space
}

This will cause proposals to become available as part of Space schema resulting in this query to database (table name is derived from type used, column name is the field argument from directive):

SELECT * FROM proposals WHERE space IN (space.id)

Now such queries can be used:

{
  spaces {
    id
    proposals {
      id
      tx
      title
      strategies
    }
  }
}

You can test it against this branch on sx-api (extra changes due to event parsing): https://github.com/snapshot-labs/sx-api/tree/sekhmet/subentities

@Sekhmet Sekhmet requested a review from bonustrack January 18, 2023 15:16
@Sekhmet Sekhmet self-assigned this Jan 18, 2023
Copy link
Contributor

@bonustrack bonustrack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK. If we always return all the entries it may take too long to resolve or become unusable, ideally we should limit the results and allow custom query like root operation example:

{ 
  spaces {
    name
    proposals (first: 10, orderBy: end) {
      title
    }
  }
}

But this can be solved in future, this PR is already a great step.

@Sekhmet Sekhmet merged commit db3c5c4 into master Jan 19, 2023
@Sekhmet Sekhmet deleted the sekhmet/subentities branch January 19, 2023 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Add subentities array support
2 participants