graphql-java-codegen icon indicating copy to clipboard operation
graphql-java-codegen copied to clipboard

Problem with ArgumentValue serialization by GraphQLRequest (GraphQLRequest#toHttpJsonBody)

Open mka92 opened this issue 1 year ago • 1 comments

used configuration

<resolverArgumentAnnotations>org.springframework.graphql.data.method.annotation.Argument</resolverArgumentAnnotations>
<useWrapperForNullableInputTypes>true</useWrapperForNullableInputTypes>

and I've go an error in test like below: Invalid syntax with ANTLR error 'token recognition error at: '.s'' at line 1 column 70

I think the problem is that argument value is not serialized properly to the request body.

{"query":"query testTest { testTest: testTest(testInput: { testInput: org.springframework.graphql.data.ArgumentValue@6b0b9cb6 }){ result } }"}

Schema

type Query {
    testTest(
        testInput: TestInput!
    ): TestResult

input TestInput {
    testInput: String
}

type TestResult {
    result: String
}
}

Example test code:

        TestInputGQL testInputGQL = TestInputGQL.builder()
                .setTestInput(ArgumentValue.ofNullable("testValue"))
                .build();

        TestResultResponseProjection testResultResponseProjection = new TestResultResponseProjection().result();

        GraphQLRequest graphQLRequest = new GraphQLRequest(
                TestTestQueryRequest.builder().setTestInput(testInputGQL).build(),
                testResultResponseProjection
        );

        TestTestQueryResponse graphqlResponse = sendGraphQLQuery(
                graphQLRequest
        )
                .then()
                .statusCode(200)
                .extract()
                .body()
                .as(TestTestQueryResponse.class);

expected

{"query":"query testTest { testTest: testTest(testInput: { testInput: "testValue" }){ result } }"}

or skipped value when is ommited

Environment and Setup

  • graphql-java-codegen version: 5.10.0
  • Build tool: Maven

mka92 avatar Mar 07 '24 07:03 mka92

Had a look. As indicated and suspected: ArgumentValue is not serializable, which seems to be the root cause. I'm unsure how to fix this, as ArgumentValue is purposefully not part of the dependencies, so it doesn't seem possible to add a custom serializer. Any suggestions would be appreciated. The only idea I can come up with, is contrubuting to spring-graphql, making it serializable.

rwo-trackunit avatar Apr 02 '24 05:04 rwo-trackunit