Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic schema #88

Closed
sunli829 opened this issue Nov 1, 2022 · 8 comments · Fixed by #114
Closed

Dynamic schema #88

sunli829 opened this issue Nov 1, 2022 · 8 comments · Fixed by #114

Comments

@sunli829
Copy link

sunli829 commented Nov 1, 2022

Async-graphql will support fully dynamic schema, a preview will be released this week, it will be great to use in combination with seaography.

  let myobj = Object::new("MyObj")
            .field(Field::new("a", TypeRef::INT, Value::from(123)))
            .field(Field::new("b", TypeRef::STRING, Value::from("abc")));

        let query = Object::new("Query")
            .field(Field::new("value", TypeRef::INT, Value::from(100)))
            .field(Field::new(
                "valueObj",
                TypeRef::new("MyObj"),
                ResolverFn::new(|_| async { Ok(FieldValue::NULL) }),
            ));
        let schema = Schema::build("Query", None)
            .register(query)
            .register(myobj)
            .finish()
            .unwrap();

        assert_eq!(
            schema
                .execute("{ value valueObj { a b } }")
                .await
                .into_result()
                .unwrap()
                .data,
            value!({
                "value": 100,
                "valueObj": {
                    "a": 123,
                    "b": "abc",
                }
            })
        );
@karatakis
Copy link
Collaborator

@sunli829 thanks for the heads up. This will make things wayyyy easier. I can convert the database schema to graphql on startup 🤩. No need to compile on changes.

@billy1624
Copy link
Member

Hey @sunli829, Is there a full demo on the dynamic schema v.s. static schema? I just saw the code snippet on the README.md but not a complete Rust example. Thanks!!

@billy1624
Copy link
Member

Thanks for the great work!! @sunli829

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 15, 2022

Thank you @sunli829

@karatakis
Copy link
Collaborator

Thanks @sunli829 👏

@karatakis
Copy link
Collaborator

@sunli829 you can see it in action in #114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants