ballerina-platform / ballerina-central

Ballerina Central Website
Apache License 2.0
104 stars 1 forks source link

The GraphQL API returns a string instead of a JSON #214

Open anupama-pathirage opened 1 month ago

anupama-pathirage commented 1 month ago

@nipunayf cloned issue wso2-enterprise/ballerina-registry#2828 on 2024-10-01:

Description

In this case, we need to explicitly pass logic to the JSON parser to convert the "clients" string into a JSON map. Ideally, the API should return the result as a JSON map rather than a string.

Request and Response

Input:


query ApiDocs {

    apiDocs(

        inputFilter: {

            moduleInfo: {

                orgName: "ballerina"

                moduleName: "http"

                version: "2.12.0"

            }

            clientFilter: { name: "Client" }

        }

    ) {

        docsData {

            modules {

                clients

            }

        }

    }

}

Output:


{

    "data": {

        "apiDocs": {

            "docsData": {

                "modules": [

                    {

                        "clients": "{\"remoteMethods\":[{\"accessor\":\"\", \"resourcePath\":\"\", \"isIsolated\":true, \"isRemote\":true, \"isResource\":false, \"isExtern\":true, \"parameters\":[{\"defaultValue\":\"\", \"type\":{\"name\":\"string\", \"category\":\"builtin\", \"isAnonymousUnionType\":false, \"isInclusion\":....PI it\\nprovides includes the functions for the standard HTTP methods forwarding a received request and sending requests\\nusing custom HTTP verbs.\\n\", \"descriptionSections\":[], \"isDeprecated\":false, \"isReadOnly\":false}"

                    }

                ]

            }

        }

    }

}
anupama-pathirage commented 1 month ago

@tharindu-nw commented on 2024-10-01:

Ballerina graphql services do not allow user defined return types to have json fields, i.e. we cannot have something like:


public type ModuleResponse record {

  string id;

  string summary;

  json clients;

  json functions;

}

as the return type. In that case we need to define records for clients and functions types as well. This is not feasible as the semantic details change with language versions and changes to the Docs API.