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

Improve the Return Type Validation in GraphQL Interceptors #4255

Closed
DimuthuMadushan opened this issue Mar 23, 2023 · 0 comments · Fixed by ballerina-platform/module-ballerina-graphql#1440
Assignees
Labels
module/graphql Issues related to Ballerina GraphQL module Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/PCM Protocol connector packages related issues Type/Bug

Comments

@DimuthuMadushan
Copy link

DimuthuMadushan commented Mar 23, 2023

Description:
When returning a value that includes a map from a GraphQL interceptor, It's not validated correctly.
Consider the following GraphQL service:

import ballerina/graphql;

public type Languages record {|
    map<string> name;
|};

readonly service class InterceptMap {
    *graphql:Interceptor;

    isolated remote function execute(graphql:Context context, graphql:Field 'field) returns anydata|error {
        Languages ls = {
            name: {
                backend: "PHP",
                frontend: "Flutter",
                data: "Ballerina",
                native: "java"
            }
        };
        var result = context.resolve('field);
        if 'field.getName() == "languages"{
            return ls;
        }
        return result;
    }
}

@graphql:ServiceConfig {
    interceptors: [new InterceptMap()]
}
service /gql_map on new graphql:Listener(9000) {
    private final Languages languages;

    function init() {
        self.languages = {
            name: {
                backend: "Ballerina",
                frontend: "JavaScript",
                data: "Python",
                native: "C++"
            }
        };
    }

    isolated resource function get languages() returns Languages {
        return self.languages;
    }
}

If we query the service as follows:

query {
  languages {
    name(key:"backend")
  }
}

It returns the following response.

{
  "data": {
    "languages": {
      "name": {}
    }
  }
}

But the actual response should be as follows:

{
  "data": {
    "languages": {
      "name": "PHP"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/graphql Issues related to Ballerina GraphQL module Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/PCM Protocol connector packages related issues Type/Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants