Giveth/DeVouch-BE

[needs project info] Sort unified list by count of vouches from all tracked attestor groups

Closed this issue · 7 comments

We will need to be able to sort the response given by the list of all projects should be the total count of vouches made by all tracked attester groups in ascending/descending order.

If a filter is applied to look for only certain attester groups this should be reflected as well.

If a filter is applied to look for only projects from a certain platform this should be reflected.

For example

Project A

vouches received

  • Attester group a - 10
  • attester goup b - 5
  • attester group c - 7
  • total vouches = 22

Project B

vouches received

  • Attester group a - 15
  • attester goup b - 10
  • attester group c - 15
  • total vouches = 40

Project C

vouches received

  • Attester group a - 7
  • attester goup b - 5
  • attester group c - 3
  • total vouches = 15

So the order of responses should be given in descending order as projects B, A, C

Alternatively, the user will be able to sort by ASCENDING order - so we should be able to handle this as well.

AC

  • can sort all projects in response by highest count of vouches from all tracked attester groups
  • can sort all projects in response by lowest count of vouches from all tracked attester groups
  • sorting can also handle when filtered by specific attester organization
  • sorting can handle filter by specific source platform

response also contains information about each project listed:

  • project title
  • count of vouches from each tracked attester groups
  • count of flags from each tracked attester groups
  • project short description
  • banner image
  • slug/link to project page
  • source platform
  • if a given address has attested for this project before

It's possible with

{
  projects(where: {
    
  }, orderBy: totalVouches_DESC) {
    id
    totalVouches
    totalFlags
    totalAttests
  }
}

Response

{
  "data": {
    "projects": [
      {
        "id": "giveth-2880",
        "totalVouches": 3,
        "totalFlags": 0,
        "totalAttests": 3
      },
      {
        "id": "giveth-123",
        "totalVouches": 1,
        "totalFlags": 2,
        "totalAttests": 3
      },
      {
        "id": "giveth-2881",
        "totalVouches": 1,
        "totalFlags": 0,
        "totalAttests": 1
      }
    ]
  }
}

@divine-comedian I assume you don't mean sorting based on total vouches received by limited organizations. For instance if

I don't think you finished your thought there @aminlatifi

We'll need the project data as well in this response to call this user story done.

The use case in question is

  • user HAS NOT filtered by any specific attester organization
  • sorts list of responses by highest vouch count

but there is a possible scenario where:

  • user filters by specific attesterorganization
  • sorts filtered list by highest vouch count on a given project
  • could also filter by specific source platform

@divine-comedian You are right 😄

Please try this one. It shows the flexibility and power of queries

{
  projects(where: {source_eq: "giveth"}, orderBy: totalVouches_DESC) {
    id
    source
    title
    description
    totalVouches
    totalFlags
    totalAttests
    all_organistaions_attestations: attestedOrganisations {
      organisation {
        name
      }
      count
      vouch
    }
    givth_organisation_attestations: attestedOrganisations(where: {organisation: {id_eq: "0xf63f2a7159ee674aa6fce42196a8bb0605eafcf20c19e91a7eafba8d39fa0404"}}) {
      organisation {
        name
      }
      count
      vouch
    }
    attestor_826976d7c600d45fb8287ca1d7c76fc8eb732030_attests: attests (where: {
      attestorOrganisation: {
        attestor: {
          id_eq: "0x826976d7c600d45fb8287ca1d7c76fc8eb732030"
        }
      }
    }) {
      vouch
      attestTimestamp
      revoked
      attestorOrganisation {
        attestor {
          id
        }
      }
    }
  }
}

Response:

{
  "data": {
    "projects": [
      {
        "id": "giveth-2880",
        "source": "giveth",
        "title": null,
        "description": null,
        "totalVouches": 3,
        "totalFlags": 1,
        "totalAttests": 4,
        "all_organistaions_attestations": [
          {
            "organisation": {
              "name": "Giveth Verification Team"
            },
            "count": 1,
            "vouch": false
          },
          {
            "organisation": {
              "name": "Giveth Verification Team"
            },
            "count": 1,
            "vouch": true
          },
          {
            "organisation": {
              "name": "Trace"
            },
            "count": 2,
            "vouch": true
          }
        ],
        "givth_organisation_attestations": [
          {
            "organisation": {
              "name": "Giveth Verification Team"
            },
            "count": 1,
            "vouch": false
          },
          {
            "organisation": {
              "name": "Giveth Verification Team"
            },
            "count": 1,
            "vouch": true
          }
        ],
        "attestor_826976d7c600d45fb8287ca1d7c76fc8eb732030_attests": [
          {
            "vouch": true,
            "attestTimestamp": "2024-05-09T17:36:36.000000Z",
            "revoked": false,
            "attestorOrganisation": {
              "attestor": {
                "id": "0x826976d7c600d45fb8287ca1d7c76fc8eb732030"
              }
            }
          },
          {
            "vouch": true,
            "attestTimestamp": "2024-05-10T12:24:36.000000Z",
            "revoked": false,
            "attestorOrganisation": {
              "attestor": {
                "id": "0x826976d7c600d45fb8287ca1d7c76fc8eb732030"
              }
            }
          }
        ]
      },
      {
        "id": "giveth-123",
        "source": "giveth",
        "title": null,
        "description": null,
        "totalVouches": 1,
        "totalFlags": 2,
        "totalAttests": 3,
        "all_organistaions_attestations": [
          {
            "organisation": {
              "name": "Trace"
            },
            "count": 2,
            "vouch": false
          },
          {
            "organisation": {
              "name": "Trace"
            },
            "count": 1,
            "vouch": true
          }
        ],
        "givth_organisation_attestations": [],
        "attestor_826976d7c600d45fb8287ca1d7c76fc8eb732030_attests": []
      },
      {
        "id": "giveth-2881",
        "source": "giveth",
        "title": null,
        "description": null,
        "totalVouches": 1,
        "totalFlags": 0,
        "totalAttests": 1,
        "all_organistaions_attestations": [
          {
            "organisation": {
              "name": "Trace"
            },
            "count": 1,
            "vouch": true
          }
        ],
        "givth_organisation_attestations": [],
        "attestor_826976d7c600d45fb8287ca1d7c76fc8eb732030_attests": [
          {
            "vouch": true,
            "attestTimestamp": "2024-05-12T16:26:36.000000Z",
            "revoked": false,
            "attestorOrganisation": {
              "attestor": {
                "id": "0x826976d7c600d45fb8287ca1d7c76fc8eb732030"
              }
            }
          }
        ]
      }
    ]
  }
}

Moved it to QA, @maryjaf if you have any question in producing the queries please reach out to me.

@aminlatifi

This looks good for the primary use case with no filters

I had some trouble in applying the filters to this response, namely for projects that have received attestations ONLY from a certain attester organizations. Do you know how to format such a query?

@aminlatifi

This looks good for the primary use case with no filters

I had some trouble in applying the filters to this response, namely for projects that have received attestations ONLY from a certain attester organizations. Do you know how to format such a query?

query {
  projects (where:{
    attests_some:{}
    attests_every:{
      attestorOrganisation: {
        organisation: {
          name_eq: "Trace"
        }
      }
    }
  }) {
    id
    title
    attests {
      vouch
      revoked
      attestorOrganisation {
        attestor {
          id
        }
        organisation {
          name
        }
      }
    }
  }
}

Response

{
  "data": {
    "projects": [
      {
        "id": "giveth-123",
        "title": null,
        "attests": [
          {
            "vouch": true,
            "revoked": false,
            "attestorOrganisation": {
              "attestor": {
                "id": "0xf23ea0b5f14afcbe532a1df273f7b233ebe41c78"
              },
              "organisation": {
                "name": "Trace"
              }
            }
          },
          {
            "vouch": false,
            "revoked": false,
            "attestorOrganisation": {
              "attestor": {
                "id": "0x76192dedff8bd9c5da45c578f8ffec325c1405f3"
              },
              "organisation": {
                "name": "Trace"
              }
            }
          },
          {
            "vouch": false,
            "revoked": false,
            "attestorOrganisation": {
              "attestor": {
                "id": "0x180242ff18cf7d0c6aca16a169cfaf12975c72b5"
              },
              "organisation": {
                "name": "Trace"
              }
            }
          }
        ]
      }
    ]
  }
}