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

GraphQL Service Crashes when Input Object Type Variable Value Includes an Additional Field #7317

Assignees
Labels
module/graphql Issues related to Ballerina GraphQL module Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Type/Bug

Comments

@DimuthuMadushan
Copy link

Description

GraphQL service crashes when the input object type variable value includes an additional field.

Steps to Reproduce

Consider the below service:

import ballerina/graphql;

type NewProfile record {|
    string name;
    int age;
|};

type Profile readonly & record {|
    *NewProfile;
    int id;
|};

table<Profile> key(id) profiles = table [];

service /graphql on new graphql:Listener(9090) {
    remote function addProfile(NewProfile newProfile) returns Profile {
        Profile profile = {id: profiles.nextKey(), ...newProfile};
        profiles.add(profile);
        return profile;
    }

    resource function get profiles() returns table<Profile> {
        return profiles;
    }
}

Service is crashing for the following GraphQL query.

mutation($profile: NewProfile!){
  addProfile(newProfile:$profile) {
    id
    name
    age
  }
}

variable:

{
  "profile": {
    "name": "gql",
    "age": 4,
    "address": {}
  }
}

output:

error: {ballerina/lang.map}KeyNotFound {"message":"invalid field access: field 'address' not found in record type 'input_obj:NewProfile'"}
        at ballerina.graphql.1.Engine:executeMutationMethod(engine.bal:484)
           ballerina.graphql.1.Engine:resolveRemoteMethod(engine.bal:383)
           ballerina.graphql.1.Engine:getFieldValue(engine.bal:434)
           ballerina.graphql.1.Engine:resolve(engine.bal:343)
           ballerina.graphql.1.ExecutorVisitor:execute(executor_visitor.bal:116)
           ballerina.graphql.1:$anon$method$delegate$ExecutorVisitor.execute$0(executor_visitor.bal:78)
           ballerina.graphql.1.ExecutorVisitor:visitField(executor_visitor.bal:81)
           ballerina.graphql.parser.1.FieldNode:accept(field_node.bal:38)
           ballerina.graphql.1.ExecutorVisitor:visitOperation(executor_visitor.bal:50)
           ballerina.graphql.parser.1.OperationNode:accept(operation_node.bal:41)
           ballerina.graphql.1.Engine:getResult(engine.bal:133)
           ballerina.graphql.1:getResponseFromExecution(listener_utils.bal:101)
           ballerina.graphql.1:getResponseFromQuery(listener_utils.bal:89)
           ballerina.graphql.1:getResponseFromJsonPayload(listener_utils.bal:66)
           ballerina.graphql.1:handlePostRequests(listener_utils.bal:43)
           ballerina.graphql.1.$anonType$_15:$post$.(listener_utils.bal:348)

Version

2201.9.x

Environment Details (with versions)

No response

@ThisaruGuruge
Copy link
Member

Reopening the issue since this is not fixed on 2201.10.x and the master.

The changes cannot be ported currently due to the following bug:

ballerina-platform/ballerina-lang#43675

@ThisaruGuruge
Copy link
Member

Reopenning since this is not yet ported to 2201.10.x

@ThisaruGuruge ThisaruGuruge reopened this Dec 4, 2024
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. Type/Bug
Projects
Archived in project
2 participants