Open smmoosavi opened 1 year ago
@xoac
dynamic graphql is not designed to work with the default async-graphql schema. only async-graphql::dynamic
is supported. #[derive(Debug, async_graphql::SimpleObject, dynamic_graphql::SimpleObject)]
may be not works.
federation attributes (shareable, tag, ...) are not supported yet in dynamic-graphql
dynamic-graphql::SimpleObject
and async-graphql::SimpleObject
are similar and defined graphql types based on structs.
ResolveObject
and ResolvedObjectFields
together are similar to #[Object]
and allow users to define type based on the impl
block
ExpandObject
and ExpandObjectFields
allow users to add fields to an existing object. If you want to access self
in ExpandObjectFields
, it should be defined like this:
use ExampleQuery<'a>(&'a Query)
not ExampleQuery(Query)
#[derive(SimpleObject)]
#[graphql(root)]
struct Query {
foo: String,
#[graphql(skip)]
example: Option<Example>,
}
#[derive(SimpleObject)]
struct Example {
field: String,
}
#[derive(ExpandObject)]
struct ExampleQuery<'a>(&'a Query); // expand Query object type
#[ExpandObjectFields]
impl<'a> ExampleQuery<'a> {
fn example(&self) -> Option<&'a Example> { // define field example for query
self.0.example.as_ref()
}
}
Another piece of advice: make your graphql layer as thin as possible and move business logic, authorization, etc to the business logic layer, and graphql only call the business logic layer without conditions and logics
see more in here: https://github.com/graphql-python/graphene-django/issues/79#issuecomment-600866987
@smmoosavi Thanks. I have checked first scenario but I wasn't able to fit it into my case. The main problem is that I have part of GQL application that is defined as in above example with
MyObj
(notMySimpleObj
). Could you provide example scenario for that?As far as I understand I need to rewrite all Object defined with
async_graphql
to be defined withdynamic_graphql
? Then it's hard to go from one library to second and still keep compatible. For example below will not compile:Also in my scenario I don't know how to use states correctly with
dynamic-graphql
crateExtendedObject
don't accept self as parameter.Below I share code that compile but panic at runtime with
I would be glad if you could help me understand how can I fix it.
Originally posted by @xoac in https://github.com/async-graphql/async-graphql/issues/1248#issuecomment-1468903035