Crates.io | tauri-plugin-graphql |
lib.rs | tauri-plugin-graphql |
version | 2.1.0 |
source | src |
created_at | 2022-03-30 19:24:49.393982 |
updated_at | 2023-01-10 12:56:25.356273 |
description | A plugin for Tauri that enables type-safe IPC through GraphQL. |
homepage | |
repository | https://github.com/JonasKruckenberg/tauri-plugin-graphql |
max_upload_size | |
id | 559369 |
size | 202,151 |
A plugin for Tauri that enables type-safe IPC through GraphQL.
[dependencies]
tauri-plugin-graphql = "2.0.0"
The only client-side adapter currently is tauri-plugin-graphql-urql
, a custom exchange for urql
.
If you need adapters for other GraphQL clients, open a PR!
Package | Version (click for changelogs) |
---|---|
tauri-plugin-graphql-urql |
You need to register the plugin giving it a async_graphql::Schema
. This schema will be used to fulfill requests.
use async_graphql::{Schema, Object, EmptySubscription, EmptyMutation, Result as GraphQLResult, SimpleObject};
#[derive(SimpleObject, Debug, Clone)]
struct ListItem {
id: i32,
text: String
}
impl ListItem {
pub fn new(text: String) -> Self {
Self {
id: rand::random::<i32>(),
text
}
}
}
struct Query;
#[Object]
impl Query {
async fn list(&self) -> GraphQLResult<Vec<ListItem>> {
let item = vec![
ListItem::new("foo".to_string()),
ListItem::new("bar".to_string())
];
Ok(item)
}
}
fn main() {
let schema = Schema::new(
Query,
EmptyMutation,
EmptySubscription,
);
tauri::Builder::default()
.plugin(tauri_plugin_graphql::init(schema))
.run(tauri::generate_context!())
.expect("failed to run app");
}
If you want to help out, there are a few areas that need improvement:
PRs are welcome!