16 releases (6 breaking)

0.7.3 Mar 28, 2023
0.7.0 Feb 21, 2023

#1888 in Network programming

Download history 73/week @ 2023-02-03 33/week @ 2023-02-10 44/week @ 2023-02-17 4/week @ 2023-02-24 19/week @ 2023-03-03 58/week @ 2023-03-10 123/week @ 2023-03-17 86/week @ 2023-03-24 19/week @ 2023-03-31 120/week @ 2023-04-07 122/week @ 2023-04-14 76/week @ 2023-04-21 8/week @ 2023-04-28 111/week @ 2023-05-05 107/week @ 2023-05-12 435/week @ 2023-05-19

661 downloads per month
Used in raphtory-graphql

MIT license

66KB
2K SLoC

Dynamic graphql

Build Status Latest Version Rust Documentation GitHub license

extendable and dynamic graphql schema definition for async-graphql

Usage

use dynamic_graphql::App;

mod foo {
    use dynamic_graphql::{App, ExpandObject, ExpandObjectFields, SimpleObject};

    use super::root::Query;

    #[derive(SimpleObject)]
    pub struct Foo {
        id: String,
        name: String,
    }

    #[derive(ExpandObject)]
    pub struct FooQuery<'a>(&'a Query);

    #[ExpandObjectFields]
    impl FooQuery<'_> {
        async fn foo(id: String) -> Foo {
            Foo {
                id,
                name: "test".to_string(),
            }
        }
    }

    #[derive(App)]
    pub struct FooApp(FooQuery<'static>);
}

mod root {
    use dynamic_graphql::SimpleObject;

    #[derive(SimpleObject)]
    #[graphql(root)]
    pub struct Query;
}

#[derive(App)]
struct App(root::Query, foo::FooApp);

#[tokio::test]
async fn test() {
    let schema = App::create_schema().finish().unwrap();

    let sdl = schema.sdl();

    assert_eq!(
        &sdl,
        r#"

type Foo {
	id: String!
	name: String!
}



type Query {
	foo(id: String!): Foo!
}


schema {
	query: Query
}
"#
    );

    let query = r#"
        query {
            foo(id: "1") {
                id
                name
            }
        }
    "#;

    let res = schema.execute(query).await;
    let data = res.data.into_json().unwrap();

    assert_eq!(
        data,
        serde_json::json!({ "foo": { "id": "1", "name": "test" } })
    );
}

Dependencies

~11–18MB
~418K SLoC