Skip to content

Support custom serialization of parameters in GraphQLOperationRequest #472

Closed
@kobylynskyi

Description

@kobylynskyi
Owner

Schema:

scalar LocalDate
schema {
    query: Query
}
type Query {
    birthdaysScalar(dateOfBirth: LocalDate!): [Person]!
    birthdaysType(dateOfBirth: DateOfBirth!): [Person]!
}
input DateOfBirth {
    date: LocalDate!
}
type Person {
    name: String!
    dateOfBirth: LocalDate!
}

Code for the request:

GraphQLRequestSerializer.OBJECT_MAPPER
        .registerModule(new JavaTimeModule())
        .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

PersonResponseProjection projection = new PersonResponseProjection().name();

BirthdaysScalarQueryRequest birthdaysScalarQueryRequest = BirthdaysScalarQueryRequest.builder()
        .setDateOfBirth(LocalDate.now())
        .build();
BirthdaysTypeQueryRequest birthdaysTypeQueryRequest = BirthdaysTypeQueryRequest.builder()
        .setDateOfBirth(DateOfBirth.builder().setDate(LocalDate.now()).build())
        .build();

GraphQLRequest requestScalar = new GraphQLRequest(birthdaysScalarQueryRequest, projection);
GraphQLRequest requestType = new GraphQLRequest(birthdaysTypeQueryRequest, projection);

System.out.println("Using Scalar: " + requestScalar.toHttpJsonBody());
System.out.println("Using Type: " + requestType.toHttpJsonBody());

Output:

Using Scalar: {"query":"query { birthdaysScalar: birthdaysScalar(dateOfBirth: 2020-12-29){ name } }"}
Using Type: {"query":"query { birthdaysType: birthdaysType(dateOfBirth: { date: \"2020-12-29\" }){ name } }"}

Originally posted by @idegroot in #464 (reply in thread)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

    Participants

    @kobylynskyi

    Issue actions

      Support custom serialization of parameters in GraphQLOperationRequest · Issue #472 · kobylynskyi/graphql-java-codegen