Skip to content

GraphQLInput Generics #1127

Answered by tyranron
bnhardy asked this question in Q&A
Nov 21, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

@bnhardy yup, at the moment GraphQLInputObject macro cannot work with generics. Unfortunately, even when it will be able to, it won't allow your use case anyway.

What you're trying to reach here is a bit fundamentally incorrect, because GraphQL types system has no notion of generics at all. Try to express the same thing using SDL (GraphQL schema definition language), and you won't be able to.

So... what happens, actually?

When you write:

#[derive(GraphQLInputObject, Serialize, Debug)]
pub struct ConnectionParams<T> {
    pub after: Option<String>,
    pub first: Option<i32>,
    pub params: Option<T>,
}

You define in GraphQL schema a ConnectionParams input object like this:

input Connecti…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@twiclo
Comment options

Answer selected by bnhardy
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants