You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement GraphQL custom scalars for Efficient Data Type Conversion.
We need to make use of GraphQL custom scalars to automatically handle simple data parsing.
For instance, consider the parsing from a String to BN.
Currently, all BN data retrieved via GraphQL is in string format, always requiring a manual conversion to BN.
Implementing custom scalars will eliminate the need for these repetitive manual conversions. Below is an illustrative example:
Warning
This code is provided as an example and should not be considered the final solution.
// Implementation of the BigNumber scalarconstbigNumberScalar=newGraphQLScalarType({name: 'BN',description: 'A custom scalar type for BN',serialize(value){// Converts BN to a string for the responsereturnvalue.toString();},parseValue(value){// Transforms an incoming string into BNreturnbn(value);},parseLiteral(ast){if(ast.kind==='StringValue'){returnbn(ast.value);}returnnull;}});// Definition of resolversconstresolvers={BN: bigNumberScalar,// Additional resolvers can be defined here};
1 - I will close and create another issue in favor of this one today. I've misinterpreted how the problem presented by the FE feedback could be solved on our side. It seems that implementing a custom scalar can only be done on the server side. I will write the specs for the new issue later today.
2 - #1570 is not related to this one. However, It needs some investigation to validate if graphQL resolvers can be used on a node client-side application.
Implement GraphQL custom scalars for Efficient Data Type Conversion.
We need to make use of GraphQL custom scalars to automatically handle simple data parsing.
For instance, consider the parsing from a
String
toBN
.Currently, all
BN
data retrieved via GraphQL is in string format, always requiring a manual conversion toBN
.Implementing custom scalars will eliminate the need for these repetitive manual conversions. Below is an illustrative example:
Warning
This code is provided as an example and should not be considered the final solution.
Note
The text was updated successfully, but these errors were encountered: