ourzora / zdk

MIT License
107 stars 42 forks source link

Complex filtering logic in tokens() query? #70

Open rodrigoescandon opened 2 years ago

rodrigoescandon commented 2 years ago

If I run the following query, I get all tokens with that match the attribute filter {traitType: "Eyes", value: "classic"} or {traitType: "Hat", value: "strawberry hat"}. Is there a way to filter using complicated logic? For example, a way to get tokens that match both attributes (intersection of sets rather than union)? I tried using the standard and, or, and not operators from GraphQL but couldn't figure out how to pass them to the tokens query.

  query Query {
    tokens(
      filter: {attributeFilters: [
        {traitType: "Eyes", value: "classic"},
        {traitType: "Hat", value: "strawberry hat"}
      ]},
      where: {collectionAddresses: "0x5af0d9827e0c53e4799bb226655a1de152a425a5"},
      pagination: {limit: 12},
      sort: {sortKey: MINTED, sortDirection: ASC}
    ) {
      nodes {
        token {
          tokenId
          attributes {
            traitType
            value
          }
        }
      }
    }
  }
iainnash commented 2 years ago

@rodrigoescandon I believe we can add this but it'll require some custom query logic on our end. I believe one issue with more complex nested logic is the query load could get quite high without collection filter (say all tokens owned by someone that owns 11k tokens with a nested and or and not filter etc). Can see how this will be useful and will bring it up to the team.

@sjiang2019