#tauri #tauri-plugin #graphql

mizuki

A toolkit for building Tauri Plugins that enables type-safe IPC through GraphQL

5 releases

0.2.0 Mar 6, 2024
0.2.0-alpha.3 Feb 4, 2024
0.2.0-alpha.2 Dec 16, 2023
0.2.0-alpha.1 Dec 13, 2023
0.1.0 Dec 4, 2023

#1135 in GUI

Download history 525/week @ 2024-06-27 80/week @ 2024-07-04 218/week @ 2024-07-11 91/week @ 2024-07-18 208/week @ 2024-07-25 212/week @ 2024-08-01 124/week @ 2024-08-08 106/week @ 2024-08-15 54/week @ 2024-08-22 2/week @ 2024-08-29 7/week @ 2024-09-05 50/week @ 2024-09-12 59/week @ 2024-09-19 20/week @ 2024-09-26 22/week @ 2024-10-03 5/week @ 2024-10-10

115 downloads per month

MIT license

110KB
417 lines

Mizuki

Crates.io Documentation MIT licensed

A toolkit for building Tauri plugins that enables type-safe IPC through GraphQL.

Notice

This project is a fork from JonasKruckenberg/tauri-plugin-graphql.

But I thought that it would be a great a idea to push the plugin futher and create a toolkit for building GraphQL Tauri Plugins.

Install

Rust

[dependencies]
mizuki = "0.2.0"

JavaScript

The only client-side adapter currently is @mizuki/urql, a custom exchange for urql. If you need adapters for other GraphQL clients, open a PR!

Package Version (click for changelogs)
mizuki-urql-adapter urql adapter version

Usage

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 init_plugin<R: tauri::Runtime>() -> mizuki::MizukiPlugin<R, Query, EmptyMutation, EmptySubscription> {
    mizuki::Builder::new("todo-plugin", Schema::new(
        Query,
        EmptyMutation,
        EmptySubscription,
    )).build()
}

fn main() {
    tauri::Builder::default()
        // The plugin name is required
        .plugin(init_plugin())
        .run(tauri::generate_context!())
        .expect("failed to run app");
}

Contributing

If you want to help out, there are a few areas that need improvement:

  • Client Adapters - Currently, only a urql adapter exists; having adapters for more client libraries would be very nice.

PRs are welcome!

License

MIT © Tony Mushah

Dependencies

~25–67MB
~1M SLoC