Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using generics with both SimpleObject and InputObject as field in output type fails #1498

Open
kilork opened this issue Mar 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kilork
Copy link

kilork commented Mar 19, 2024

Hi, I encountered a weird issue I want to overcome somehow. Actually, I would be happy with w/a, because as alternative I have to generate quite massive structure with a lot of fields and I do not want to do this.

Expected Behavior

This code should work normally.

    #[tokio::test]
    pub async fn test_both_input_output_result_generic() {
        #[derive(SimpleObject, InputObject)]
        #[graphql(concrete(name = "MyObjectU32", params(u32)))]
        #[graphql(concrete(name = "MyObjectString", params(String)))]
        struct MyObject<T: InputType + OutputType> {
            a: T,
        }

        #[derive(SimpleObject)]
        struct MyObjectResult {
            fields: MyObject<u32>,
        }

        struct Query;

        #[Object]
        impl Query {
            async fn my_object_result(&self, fields: MyObject<u32>) -> MyObjectResult {
                MyObjectResult { fields }
            }
        }

        let _ = Schema::new(Query, EmptyMutation, EmptySubscription);
    }

Actual Behavior

It fails with the message:

Register `MyObjectU32` as `Object`, but it is already registered as `InputObject`

Steps to Reproduce the Problem

  1. Have two structures, one generic with both SimpleObject and InputObject and second using first one, but only with SimpleObject annotation.
  2. Use first structure as input parameter and second - as output in method declaration for some query.
  3. Try to build a scheme with this query.

Specifications

  • Version: 7.0.3
  • Platform: n/a
  • Subsystem: derive macros
@kilork kilork added the bug Something isn't working label Mar 19, 2024
@carlocorradini
Copy link

Any update?
I think the best solution is to allow
input_name in concrete:

 #[graphql(concrete(..., input_name="..."))]

This allows us to have both generic SimpleObject and InputObject with custom names avoiding conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants