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

Union type returns the results of all union type members #1391

Closed
shafreenAnfar opened this issue May 23, 2021 · 0 comments · Fixed by ballerina-platform/module-ballerina-graphql#249
Labels
module/graphql Issues related to Ballerina GraphQL module Team/PCM Protocol connector packages related issues Type/Bug

Comments

@shafreenAnfar
Copy link
Contributor

Query,

{
  search(status:OPEN) {
    ... on Trail {
      name
      trees
    }
  }
}

The result,

Here the third result should not be there. Because it is part of Lifts. Hence, trees end up being null.

{
  "data": {
    "search": [
      {
        "name": "Blue Bird",
        "trees": false
      },
      {
        "name": "Blackhawk",
        "trees": false
      },
      {
        "name": "Astra Express",
        "trees": null
      }
    ]
  }
}

Implementation,

resource function get search (ds:Status status) returns SearchResult[] {
        ds:TrailRecord[] trails = from var trail in ds:trailTable where trail.status == status select trail;
        SearchResult[] searchResults = trails.map(function (ds:TrailRecord trail) returns Trail => new Trail(trail));

        ds:LiftRecord[] lifts = from var lift in ds:liftTable where lift.status == status select lift;
        lifts.forEach(function (ds:LiftRecord lift) returns () => searchResults.push(new Lift(lift)));

        return searchResults;
    }
@shafreenAnfar shafreenAnfar added Priority/Blocker Type/Bug module/graphql Issues related to Ballerina GraphQL module Team/PCM Protocol connector packages related issues labels May 23, 2021
@shafreenAnfar shafreenAnfar changed the title Union type returns the results of all union type Union type returns the results of all union type members May 23, 2021
@ThisaruGuruge ThisaruGuruge added this to the Swan Lake Beta1 milestone May 25, 2021
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 Team/PCM Protocol connector packages related issues Type/Bug
Projects
None yet
2 participants