question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing simple request serialization

See original GitHub issue

Hello,

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:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
kobylynskyicommented, May 26, 2020

Agreed. Then let it be:


    /**
     * @deprecated Not intended for use and will be removed in the next version.
     * Please use one of: {@link #toHttpJsonBody} or {@link #toQueryString}
     */
    @Override
    @Deprecated
    public String toString() {
        return toHttpJsonBody();
    }

    /**
     * TODO: PROPER JAVADOC
     */
    public String toHttpJsonBody() {
        return GraphQLRequestSerializer.toHttpJsonBody(this);
    }

    /**
     * TODO: PROPER JAVADOC
     */
    public String toQueryString() {
        return GraphQLRequestSerializer.toQueryString(this);
    }
1reaction
lmartellottocommented, May 27, 2020

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ProtoBuf serialization missing data even for simple entities
Firstly, your serialize / deserialize methods are both broken; you are over-reporting the result ( GetBuffer() , without Length ), and you ...
Read more >
Problem to deserialize object with jackson #1865 - GitHub
Hi guys, I have two applications, one read and another write on redis: My entity @Data @JsonTypeInfo(use = JsonTypeInfo.
Read more >
Serialization guidelines | Microsoft Learn
This document provides guidelines to consider when designing an API to be serialized and a summary of the different serialization ...
Read more >
Understanding TypeScript object serialization - LogRocket Blog
Learn about object serialization in TypeScript, the way systems communicate seamlessly, and the issues with serialization in TypeScript.
Read more >
Strange error with JSON serialize/deserialize
I'm seeing some weird behavior while trying to deserialize json containing some Accounts with child objects. Example code:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found