Skip to content
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

refactor(experimental): graphql: enable schema extending #2613

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

buffalojoec
Copy link
Collaborator

@buffalojoec buffalojoec commented May 4, 2024

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 or
base64 encoded accounts/instructions to custom decoded types.

Ref: #2614

Copy link

changeset-bot bot commented May 4, 2024

⚠️ No Changeset found

Latest commit: 1f83c37

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @buffalojoec and the rest of your teammates on Graphite Graphite

@buffalojoec buffalojoec force-pushed the 05-04-refactor_experimental_graphql_enable_schema_extending branch 2 times, most recently from 7e67c8d to b9bdb88 Compare May 4, 2024 15:51
@buffalojoec buffalojoec force-pushed the 05-04-refactor_experimental_graphql_enable_schema_extending branch from b9bdb88 to 1f83c37 Compare May 4, 2024 16:03
@buffalojoec buffalojoec marked this pull request as ready for review May 4, 2024 16:03
Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added via Giphy

So, here's what I think is much more likely to happen.

  1. Export the schema from @solana/rpc-graphql
  2. Export the context creator, createSolanaGraphQLContext()
  3. Let people stitch the schemas together themselves

See a tutorial on this and a running example.

Here's why:

  1. People's extensions might collide with our types. @graphql-tools/stitch lets you supply functions that decide how to resolve conflicts.
  2. People's extensions might simply aim to add a field to an existing type (eg. imagine adding nfts to Account or whatever). Take a look at this example with two different schemas being merged into one User type.
  3. People's schema executors might be remote, and not at all written in JavaScript. The present PR doesn't offer a solution for delegating the whole entire subquery to (for instance) some URL. @graphql-tools/stitch does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants