FuelLabs / fuels-ts

Fuel Network Typescript SDK
https://docs.fuel.network/docs/fuels-ts/
Apache License 2.0
44.25k stars 1.34k forks source link

Submit custom GraphQL queries from `Provider` #3095

Open danielbate opened 1 week ago

danielbate commented 1 week ago

Currently we interact with GraphQL endpoints supplied by the node via wrapped operations provided by graphql-codegen, these are then exposed to SDK consumers via wrapped provider functions (Provider.getVersion(), Provider.getBlockNumber() etc). This potentially restricts the information we are providing to consumers or means they have to go around the SDK to query the node. We should provide a way for consumers to submit their own custom queries.

Potential implmentation in Provider

/**
 * Passes a custom document and variables via the provider
 */
async customQuery(query: DocumentNode, variables: Record<string, unknown>): Promise<unknown> {
  return this.operations.query(query, variables);
}
danielbate commented 1 week ago

In #3047 I reused a lot of what we already have in the SDK to create a custom query, we could do something similar but more flexibly. Have a public function on the provider that takes a document and variables and passes the whole thing to requester, similarly to how we already build our operations.