Grafbase Gateway SDK for Extensions
This crate provides building blocks for creating Grafbase Gateway extensions.
Usage
Extensions are still under development. Expect issues if you try them out before we complete development.
Initialize a new project with the Grafbase CLI:
This creates a new project with the necessary files and dependencies to get you started. Edit the src/lib.rs file to add your extension logic. The Grafbase Gateway initializes the struct TestProject once during the initial extension call. The Grafbase Gateway keeps extensions in a connection pool and reuses the struct for multiple requests. Because an extension is single-threaded, we keep multiple instances in the gateway memory to handle multiple requests concurrently.
The initialization gets a list of schema directives containing the schema directives from the federated schema, defined in the schema file. Often you need configuration to initialize the extension, which the schema directive provides.
The ResolverExtension derive macro generates the necessary code to initialize the extension, and guides you to implement two traits: [Extension] and [Resolver]. The Extension trait initializes the extension, and the Resolver trait implements the extension logic to resolve a field:
Building
You can build your extension with the Grafbase CLI. For this to work, you must have a working rustup installation:
This compiles your extension and creates two files:
build/
├── manifest.json
└── test_project.wasm
Checking
The Grafbase CLI provides a way to test your extension's implementation:
This builds the extension and initializes it from the Grafbase Gateway.
Publishing
To publish the extension to the Grafbase extensions repository, use the Grafbase CLI: