Tauri Plugin graphql

Crates.io Documentation MIT licensed

A plugin for Tauri that enables type-safe IPC through GraphQL.

Install

Rust

toml [dependencies] tauri-plugin-graphql = "0.1"

JavaScript

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] | urql adapter version

Usage

You need to register the plugin giving it a [juniper::RootNode] schema. This schema will be used to fulfill requests.

```rust use juniper::{graphqlobject, EmptySubscription, EmptyMutation, FieldResult, GraphQLObject, RootNode}; use tauriplugin_graphql::Context as GraphQLContext;

[derive(GraphQLObject, Debug, Clone)]

struct ListItem { id: i32, text: String }

impl ListItem { pub fn new(text: String) -> Self { Self { id: rand::random::(), text } } }

struct Query;

[graphql_object(context = GraphQLContext)]

impl Query { fn list() -> FieldResult> { let item = vec![ ListItem::new("foo".tostring()), ListItem::new("bar".tostring()) ];

    Ok(item)
}

}

// Consumers of this schema can only read data, so we must specifcy EmptyMutation and EmptySubscription type Schema = RootNode<'static, Query, EmptyMutation, EmptySubscription>;

fn main() { let schema = Schema::new( Query, EmptyMutation::::new(), EmptySubscription::::new(), );

tauri::Builder::default()
    .plugin(tauri_plugin_graphql::init(schema))
    .run(tauri::generate_context!())
    .expect("failed to run app");

} ```

Contributing

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

PRs are welcome!

License

MIT © Jonas Kruckenberg