The contract comes first.
You write the schema.
Rust gets the shape.
Define your GraphQL API in SDL.
Cargo generates the contracts.
You bring the implementation.
◇ schema.graphqlGraphQL SDLInitial schematype Query {
hello(name: String!): String!
}
Add a fieldtype Query {
hello(name: String!): String!
version: String!
}
{ }The source of truth.
Your API starts here.
→
Existing implementationpub struct Query;
impl<C: Sync> crate::generated::resolvers::QueryResolver<C> for Query {
async fn hello(
&self,
_context: &C,
args: crate::generated::types::Query::hello::Args,
) -> Result<String, necrassrs::ResolverError> {
Ok(format!("Hello, {}", args.name))
}
}
After cargo build: a new stub, existing body preservedpub struct Query;
impl<C: Sync> crate::generated::resolvers::QueryResolver<C> for Query {
async fn hello(
&self,
_context: &C,
args: crate::generated::types::Query::hello::Args,
) -> Result<String, necrassrs::ResolverError> {
Ok(format!("Hello, {}", args.name))
}
async fn version(
&self,
_context: &C,
_args: crate::generated::types::Query::version::Args,
) -> Result<String, necrassrs::ResolverError> {
unimplemented!()
}
}
$ cargo buildSDL → Rust contracts + resolver scaffolding↵
Keep scrolling to evolve your schema.