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

Support custom serialization of parameters in GraphQLOperationRequest #472

Closed
kobylynskyi opened this issue Dec 30, 2020 · 0 comments · Fixed by #473
Closed

Support custom serialization of parameters in GraphQLOperationRequest #472

kobylynskyi opened this issue Dec 30, 2020 · 0 comments · Fixed by #473
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@kobylynskyi
Copy link
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)

@kobylynskyi kobylynskyi self-assigned this Dec 30, 2020
@kobylynskyi kobylynskyi added the enhancement New feature or request label Dec 30, 2020
@kobylynskyi kobylynskyi added this to the 4.1.0 milestone Dec 30, 2020
kobylynskyi added a commit that referenced this issue Dec 31, 2020
…perationRequest #472

* Support custom serialization of parameters in GraphQLOperationRequest #472

* #473

* #473

Co-authored-by: Bogdan Kobylynskyi <92bogdan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant