-
Notifications
You must be signed in to change notification settings - Fork 318
Support ArgumentValue as payload attribute in GraphQlClient #1166
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
Comments
As explained in our reference documentation:
On the server side, Spring for GraphQL is handling the There are several options we can explore.
The third option doesn't seem straightforward at all, because it needs to involve several features and still requires developer interaction. First, we would need to contribute a new Jackson Module that teaches Jackson to serialize A complete example looks like this: class GraphQlJacksonModuleTests {
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new GraphQlJacksonModule());
@Test
void serializeArgumentValue() throws Exception {
Project project = new Project("spring-graphql", ArgumentValue.omitted());
objectMapper.writeValue(System.out, project);
project = new Project("spring-graphql", ArgumentValue.ofNullable(null));
objectMapper.writeValue(System.out, project);
project = new Project("spring-graphql", ArgumentValue.ofNullable("Spring for GraphQL"));
objectMapper.writeValue(System.out, project);
}
// Note, the JsonInclude annotation can be set on the "description" attribute directly
@JsonInclude(Include.NON_EMPTY)
record Project(String name, ArgumentValue<String> description) {
}
} This results in:
As a next step, we would need to figure out the following:
|
I've written a Jackson module that can be used to serialize/deserialize the ArgumentValue, which is based upon the implementation that exists for Optional. The branch for the changes is available here (commit), it has a dependency on the changes in this pull request. If that pull request can be merged, I can rebase and create a pull request for the jackson module. |
@JBodkin-Amphora Thanks a lot for this proposal. I have very similar changes already stashed, but yours include documentation and tests so we'll proceed with your changes. Before submitting the PR, here is some feedback that I would provide on the current changes:
Please proceed with the PR, with or without making additional changes regarding my feedback, I can take care of those if you don't have time right now. I'll close this issue as superseded once your PR is here. Thanks! |
I've made the changes as requested and raised a pull request. Please let me know if there is anything else |
Superseded by #1174. |
As seen in this StackOverflow question, developers are expecting to use
ArgumentValue<T>
as a way of expressing aT
value being present/absent/null
, not only in GraphQL controllers but also on the client side withGraphQlClient
andGraphQlTester
.Currently, if we try to use
ArgumentValue<T>
on the client side for an input type like this:This will result in Jackson serializing
ArgumentValue
itself with itsvalue
andommitted
properties.We should look into ways of supporting this use case.
The text was updated successfully, but these errors were encountered: