-
Notifications
You must be signed in to change notification settings - Fork 429
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
graphql_interface and graphql_object does not mix well #814
Comments
Also, #[graphql_object(
impl = NamespaceValue,
)]
impl User {
pub fn username() -> String {
panic!("not implemented"); // TODO
}
}
#[graphql_interface]
impl Namespace for User {
fn id(&self) -> Option<uuid::Uuid> {
Some(self.id)
}
fn created_at(&self) -> chrono::DateTime<chrono::Utc> {
self.created_at
}
fn name(&self) -> String {
self.name.clone()
}
} it generates the following code: type User implements Namespace {
username: String!
} while it should have generated: type User implements Namespace {
id: Uuid!
createdAt: DateTimeUtc!
name: String!
username: String!
} |
Thanks for the high-quality report! This does indeed look like a bug. I might be able to look at it over the weekend, but feel free to take a crack at it...the schema generation code is pretty straightforward and contained. |
After exploring the tests (https://github.com/graphql-rust/juniper/blob/a4871887bb6b30029bd4671af716c0649a0cc60c/juniper/src/tests/fixtures/starwars/schema.rs / https://github.com/graphql-rust/juniper/blob/a4871887bb6b30029bd4671af716c0649a0cc60c/juniper/src/tests/fixtures/starwars/starwars.graphql) I also noticed that the interface methods are duplicated in both in the For example, this code: #[derive(Debug, Clone)]
pub struct User {
id: uuid::Uuid,
created_at: chrono::DateTime<chrono::Utc>,
name: String,
}
#[graphql_object(
impl = NamespaceInterface,
)]
impl User {
pub fn id(&self) -> Option<ID> {
Some(self.id.into())
}
pub fn created_at(&self) -> Time {
self.created_at.into()
}
pub fn name(&self) -> String {
self.name.clone()
}
pub fn username() -> String {
panic!("not implemented"); // TODO
}
}
#[graphql_interface]
impl Namespace for User {
fn id(&self) -> Option<ID> {
User::id(self)
}
fn created_at(&self) -> Time {
User::created_at(self)
}
fn name(&self) -> String {
User::name(&self)
}
} generates the good output, but is 'weird' |
Not being intuitive is a bug :-) |
The problem is that #[graphql_object]
#[graphql(impl = NamespaceValue)]
impl User { is invalid definition at the moment, where Even if #[graphql_object]
#[graphql_object(impl = NamespaceValue)]
impl User { like the This is for the reasons explained here. But I think that point needs re-checking. Also, need to think about some compile-time check to prevent the situation described above, so it would be complain about |
- remove support for `#[graphql_interface(dyn)]` - describe all interface trait methods with type's fields or impl block instead of `#[graphql_interface]` attribute on `impl Trait` - forbid default impls on non-skipped trait methods - support additional nullable arguments on implementer - support returning sub-type on implementer
With #1009 being merged we have compile-time checks for that, even with a human-readable error message. |
Describe the bug
A
struct
using#[graphql_object]
(for complexe fields resolvers) and#[graphql_interface]
does not generate a valid schema (as_schema_language
)To Reproduce
generates
Expected behavior
The expected generated schema is as follow
Additional context
branch:
master
rev: 4ffd276
The text was updated successfully, but these errors were encountered: