Skip to content

Creating a generic GraphQL structure #1051

Closed
@ClementNerma

Description

@ClementNerma

Hi there!

I'm currently writing a Paginated<T> type for paginated responses, where T is a value that can be handled by GraphQL.

I struggle at writing this structure, here is what I have currently:

struct Paginated<T> {
  items: Vec<T>
}

#[graphql_object]
impl<T> Paginated<T> {
  pub fn items(&self) -> &[T] {
    self.items.as_slice()
  }
}

This fails because T is not a GraphQLValue. Seems logical, so I added a where T: GraphQLValue<DefaultScalarValue> constraint to my impl. But now it asks me to also implement IsOutputType, GraphQLType, GraphQLValueAsync, ensure that <T as GraphQLValue>::Context: juniper::Context, and so on.

This is a lot of constraints (especially the GraphQLValueAsync part) so is there a simpler way to constraint T?

Thanks in advance for your help!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions