pub fn init<R, Query, Mutation, Subscription>(
schema: Schema<Query, Mutation, Subscription>,
) -> TauriPlugin<R>where
R: Runtime,
Query: ObjectType + 'static,
Mutation: ObjectType + 'static,
Subscription: SubscriptionType + 'static,
Expand description
Initializes the GraphQL plugin.
This plugin exposes a async-graphql endpoint via Tauri’s IPC system, allowing the frontend to invoke backend functionality through GraphQL. This does not open a web server.
The schema
argument must be a valid async_graphql::Schema
.
§Example
use async_graphql::{Schema, Object, EmptyMutation, EmptySubscription, SimpleObject, Result as GraphQLResult};
#[derive(SimpleObject)]
struct User {
id: i32,
name: String
}
struct Query;
// Implement resolvers for all possible queries.
#[Object]
impl Query {
async fn me(&self) -> GraphQLResult<User> {
Ok(User {
id: 1,
name: "Luke Skywalker".to_string(),
})
}
}
let schema = Schema::new(
Query,
EmptyMutation,
EmptySubscription,
);
tauri::Builder::default()
.plugin(tauri_plugin_graphql::init(schema));