-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve GraphQL utilities #1570
Comments
Do you mean that we write resolvers such that e.g. a call to |
@nedsalk Not exactly. These resolvers should take care only of the data manipulation that happens before returning the data. For this specific case I believe would be this part fuels-ts/packages/providers/src/provider.ts Lines 898 to 927 in 53dafb1
In this specific case, it could be a little different, I did not go deep into it. |
The only way to go forward with this is to have an adapter between what is returned from the node and what is given to the users. We can take the Tai64Timestamp scalar as an example. We infer it as a string and thus have to manually convert it to the Problems with current toolsFurther continuing with the {
// ...
"config": {
"scalars": {
//...
"Tai64Timestamp": "DateTime"
},
} However, this would only enforce the compile-time type, whereas the runtime type would still remain a Besides these type problems, there is no "catch all" way of defining the adapter and we'd have to manually create adapters for each operation of interest. Solution
The adapter function could look something like this: type SdkOperations = Omit<Operations, "tai64Example"> & {
tai64Example: Omit<Pick<Operations, "tai64Example">, "time"> & {time: DateTime}
}
function adapter(operations: Operations): SdkOperations {
return {
...operations,
tai64Example: {
...operations.tai64Example,
time: tai64Adapter(operations.tai64Example.time)
}
}
} The |
We need to enhance our GraphQL API by implementing custom resolvers that manipulate the data returned from the queries to match the specific data types and structures required by the SDK and its consumers.
A prime example is the GraphQL type for UTXOs:
InputCoin
which needs to be manipulated to the corresponding SDK type:Resource
.We need to make this change to improve things not only for the internal use of the SDK but also for the SDK consumers.
Having said that, a deep analysis should be made not only in the SDK but also on the block explorer to identify all possible resolvers that can be created to reduce the data manipulation after queries, as the block explorer executes a lot of GraphQL queries.
Note
The text was updated successfully, but these errors were encountered: