Skip to content

Automatically implement interface fields on implementor graphql objects? #113

Closed
@jacobh

Description

@jacobh

Ideally I'd like to be able to do

pub trait Node {
    fn id(&self) -> &Uuid;
}

pub struct Queue {
    pub id: Uuid,
    pub name: String,
    ...
}
impl Node for Queue {
    fn id(&self) -> &Uuid {
        &self.id
    }
}

graphql_interface!(<'a> &'a Node: Context as "Node" |&self| {
    field id() -> &Uuid {
        self.id()
    }

    instance_resolvers: |&context| { ... }
});

graphql_object!(Queue: Context |&self| {
    interfaces: [&Node]
    field name() -> &str {
        &self.name
    }
});

And get

scalar Uuid

interface Node {
  id: Uuid
}

type Queue implements Node {
  id: Uuid
  name: String
}

Currently you can get an invalid schema if you forget to implement the id field on the Queue object.

Python's Graphene works in this way http://docs.graphene-python.org/en/latest/types/interfaces/

I realise this wouldn't be a very backwards-compatible change

Thoughts?

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions