Juniper: Derive "GraphQLObject" and "GraphQLInputObject"

Created on 25 Jun 2018  路  1Comment  路  Source: graphql-rust/juniper

Hi, I would like to be able to use some simple types as both input and object, such as:

#[derive(GraphQLObject, GraphQLInputObject)]
pub struct Coords {
    pub lat: f64,
    pub lng: f64,
}

But if I try so, I get:

error[E0119]: conflicting implementations of trait `juniper::GraphQLType` for type `Coords`:

59 | #[derive(Clone, Default, Debug, Serialize, Deserialize, GraphQLObject, GraphQLInputObject)]
   |                                                         ^^^^^^^^^^^^^  ------------------ first implementation here
   |                                                         |
   |                                                         conflicting implementation for `Location`

That makes sense because Juniper will try to make the schema type name match the struct name, but I would like to be able to do something like:

#[derive(GraphQLObject, GraphQLInputObject)]
#[graphql_input(name="CoordinateInput", description="An input for a position on the globe")]
#[graphql_object(name="Coordinate", description="A position on the globe")]
pub struct Coords {
    pub lat: f64,
    pub lng: f64,
}

Thoughts?

>All comments

That's not possible with the current trait system, since GraphQLType can only be implemented once.

Also, while sometimes annoying, I really value the strict separation between input and output types that GraphQL enforces and I think it leads to good separation in code also.

This was discussed in another issue too but I can't find it right now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spacemeowx2 picture spacemeowx2  路  5Comments

projektir picture projektir  路  4Comments

librelois picture librelois  路  3Comments

hrbigelow picture hrbigelow  路  5Comments

mihai-dinculescu picture mihai-dinculescu  路  3Comments