refactor(experimental): graphql: enable schema extending #2613
+209
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Many projects who wish to use the RPC-GraphQL resolver library may wish to
extend the default schema, which is designed around the
Solana JSON-RPC API. Currently, the library does
not allow for such customization.
There's currently no way for developers to add additional queries, types, and
resolvers to the GraphQL client, making extending this powerful library very
difficult.
Summary of Changes
Introduce three optional configurations for
createRpcGraphQL
.queryResolvers
: Custom root query resolvers.typeResolvers
: Custom type definition resolvers.typeDefs
: Custom GraphQL schema type definitions.I've also made the default type resolvers, which drive the batch loader,
availably publicly to downstream users (
resolveAccount
,resolveBlock
,resolveTransaction
).Lastly, I've added a test demonstrating how one might define custom types,
resolvers, and a custom query and provide those to the GraphQL RPC client.
Note: This should be the first in a series of changes to allow schema
extension. While the change proposed herein enables a wide range of possible
extended functionality, there are a few limitations. One such limitation is the
lack of ability to provide custom codec-based resolvers to convert
base58
orbase64
encoded accounts/instructions to custom decoded types.Ref: #2614