labscommunity / arweavekit

https://docs.arweavekit.com
MIT License
10 stars 7 forks source link

feat: Add GraphQL support #64

Closed kranthicodes closed 1 year ago

kranthicodes commented 1 year ago

Summary

This PR adds support to query GraphQL endpoint of selected gateway and query Transactions data via GraphQL endpoint with the help of newly introduced methods queryGQL, queryTransactionsGQL, queryAllTransactionsGQL.

These methods pre-validates user's supplied query by parsing it into AST and further using validate method from graphql package. With this validation, we can make sure to catch silly mistakes or invalid query that is not as per schema.

Tests

Added unit tests for both of the methods covering common scenarios

Further notes

kranthicodes commented 1 year ago

So @kranthicodes @t8 I tested these functions locally and they work as expected!

I have a few suggestions though:

  • The functions take in query and optional filters as inputs.

    • The query needs to be defined on the users end, but giving them the option to select from preexisting query structures would lower the barrier to using the GQL features.
    • On the other hand, if we keep only user defined queries as the default, then the users might not end up using the filters at all (I am however, a supporter of the filters)
    • Going a step further, I feel we should predefine some optional filters like txnID, tags, etc. for the commonly searched option along with some predefined query structures to make querying easy.
  • Alternatively, we can consider drawing inspiration from ArDB and completely take away the need for users to write any GQL.

    • Here is their pkg: https://www.npmjs.com/package/ardb.

    • The GQL syntax could be handled entirely on the backend.

    • This could also be something that we could add analogous to the functions Sai has created so that newbies have this option but veterans can use the custom options.

    • This would make sure that new users can quickly get started with querying on Arweave (like the primary goal of arweavekit)

    • While also leaving way for expert users who like to have their options.

We agreed to implement further abstraction down the line.