Skip to content

graphql_interface and graphql_object does not mix well #814

Closed
@sylvain101010

Description

@sylvain101010

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

use juniper::{graphql_interface, graphql_object, graphql_interface};

#[graphql_interface(for = User)]
pub trait Namespace {
    fn id(&self) -> Option<uuid::Uuid>;
    fn created_at(&self) -> chrono::DateTime<chrono::Utc>;
    fn name(&self) -> String;
}


#[derive(Debug, Clone)]
pub struct User {
    id: uuid::Uuid,
    created_at: chrono::DateTime<chrono::Utc>,
    name: String,
    other: String,
}

#[graphql_object]
#[graphql(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()
    }
}

generates

interface Namespace {
  id: Uuid
  createdAt: DateTimeUtc!
  name: String!
}


type User {
  username: String!
}

"DateTime"
scalar DateTimeUtc
"Uuid"
scalar Uuid

Expected behavior
The expected generated schema is as follow

type User implements Namespace {
  id: Uuid!
  createdAt: DateTimeUtc!
  name: String!
  username: String!
}

Additional context
branch: master
rev: 4ffd276

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingk::apiRelated to API (application interface)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions