feat: new query to get total vp_value#1066
Conversation
|
Original idea was to expose it via the leaderboard object |
Yes thats best way, but looks like we need a query like this for now to use internally |
Hum I forgot about that, that might simplify things actually to do this way. But I'm not sure it would scale well to query SUM of many users vp_value on the fly at once. |
There was a problem hiding this comment.
Pull request overview
This PR adds a new GraphQL query vp_value that retrieves the total VP (voting power) value for a user along with a breakdown by space. It also adds the necessary database schema fields to support this functionality.
Changes:
- Added
vp_valuecolumn to thevotestable withDECIMAL(13,3)type - Updated
scores_total_valuein theproposalstable to useDECIMAL(13,3)type for consistency - Implemented new GraphQL query
vp_valuewith resolver that aggregates VP values per space and returns total values
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/helpers/schema.sql | Adds vp_value field to votes table and updates precision of scores_total_value in proposals table |
| src/graphql/schema.gql | Defines new vp_value query and its return types (VpValue and VpValueSpace) |
| src/graphql/operations/vpValue.ts | Implements the query resolver with address validation, SQL aggregation, and error handling |
| src/graphql/operations/index.ts | Registers the new vp_value operation in the GraphQL operations index |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
What's the purpose of the Seems a little ambiguous, since when a space has 100 votes, but only 1 with value, it will return 100 (so include votes with 0 value) But for a space with 100 votes without value, it will be skipped entirely It does not seem to represent the total number of votes of the user, nor the number of votes with value either |
| FROM votes v | ||
| WHERE v.voter = ? | ||
| GROUP BY v.space | ||
| HAVING vp_value > 0 |
There was a problem hiding this comment.
Without the votesCount, this could be refactored to use a simpler where, which will filtering out the no value votes before SUMing them
|
See #1037 |
Summary:
vp_valueto get the totalvp_valueof user, also breakdown per spaceHow to test:
yarn dev{ vp_value(voter: "0x5BFCB4BE4d7B43437d5A0c57E908c048a4418390") { user totalVpValue votesCount spaces { id totalVpValue votesCount } } }