Missing simple request serialization
See original GitHub issueHello,
Is your feature request related to a problem? Please describe. We use this project to test our GraphQL API with RestAssured. Our API exposes two endpoints: GET and POST, as mentionned here: https://graphql.org/learn/serving-over-http/.
We generate requests as follow:
ItemByIdQueryRequest query = new ItemByIdQueryRequest.Builder()
.setId(1)
.build();
ItemResponseProjection fields = new ItemResponseProjection()
.name()
.tags();
GraphQLRequest request = new GraphQLRequest(query, fields);
… which generates GraphQL following JSON query thanks to request.toString():
{"query":"query { itemById(id: 1){ name tags } }"}
This JSON can be sent to the POST endpoint, it works fine. But not for the GET endpoint! Because the GET endpoint is waiting for “query” parameter where the value is not a JSON query, but the GraphQL query itself. So, we need to have only:
query { itemById(id: 1){ name tags } }
Describe the solution you’d like
Maybe just a new getter in the GraphQLRequest
class, which returns the GraphQL query without JSON encapsulation.
What about a toString()
method overload, like:
@Override
public String toString() {
return toString(true);
}
public String toString(final boolean jsonEncapsulation) {
// TODO
}
All the serialization work is already done in the GraphQLRequestSerializer.serialize()
; it just needs to not call the last method buildJsonQuery()
when we don’t need JSON encapsulation.
If you are ok with that, I can submit a PR 😃
Thanks for your time, Laura
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
Agreed. Then let it be:
@kobylynskyi yes, I almost done. Just some questioning about JSON encoding… I will submit the PR tonight if it’s ok for you. But of course, you can release version 1.8.0 before if you want 😃