https://github.com/Tak-Iwamoto/rusty-gql/pull/18/files
Improve Code Generate
- support incremental file update
We can generate Rust files incrementally.
Initial
schema.graphql
type Todo {
title: String!
content: String
done: Boolean!
}
src/graphql/resolver/todo.rs
pub struct Todo {
pub title: String,
pub content: Option<String>,
pub done: bool,
}
#[GqlType]
impl Todo {
pub async fn title(&self, ctx: &Context<'_>) -> String {
self.title.clone()
}
pub async fn content(&self, ctx: &Context<'_>) -> Option<String> {
self.content.clone()
}
pub async fn done(&self, ctx: &Context<'_>) -> bool {
self.done
}
}
Update GraphQL schemas and Run rusty-gql g
schema.graphql
type Todo {
title: String!
content: String
done: Boolean!
user: User!
}
type User {
name: String!
}
src/graphql/resolver/todo.rs
pub struct Todo {
pub title: String,
pub content: Option<String>,
pub done: bool,
}
#[GqlType]
impl Todo {
pub async fn title(&self, ctx: &Context<'_>) -> String {
self.title.clone()
}
pub async fn content(&self, ctx: &Context<'_>) -> Option<String> {
self.content.clone()
}
pub async fn done(&self, ctx: &Context<'_>) -> bool {
self.done
}
// We can add incrementally
pub async fn user(&self, ctx: &Context<'_>) -> User {
todo!()
}
}