IBM / openapi-to-graphql

Translate APIs described by OpenAPI Specifications (OAS) into GraphQL
https://developer.ibm.com/open/projects/openapi-to-graphql/
MIT License
1.6k stars 206 forks source link

Aliased queries return null #419

Open bigman73 opened 2 years ago

bigman73 commented 2 years ago

Describe the bug When executing a query without an alias, to a given web api, there is a valid result. However, once the query is aliased then the result shows null, even though the underlying HTTP request is valid and the service is returning results.

Hypothesis: There seems to be a issue on the final output results mapping phase. Perhaps the library doesn't know how to handle aliases?

To Reproduce Given a functional query and service, for example: Service: https://www.boredapi.com/documentation#endpoints-random A sample query: http://www.boredapi.com/api/activity?type=recreational

OpenAPI specification: https://api.swaggerhub.com/apis/bigman73/bored-api-activity/0.2#/default/get_api_activity

  1. Run the query in regular form, without an alias:

    {
    boredapi {
    getRecommendedActivity(participants: 2) {
      activity
      key
      participants
      price
      type
    }
    }
    }
  2. Result is valid: For example:

    {
    "data": {
    "boredapi": {
      "getRecommendedActivity": {
        "activity": "Compliment someone",
        "key": "9149470",
        "participants": 2,
        "price": 0,
        "type": "social"
      }
    }
    }
    }
  3. Run the query but this time with an alias (e.g., a):

    {
    boredapi {
    a: getRecommendedActivity(participants: 2) {
      activity
      key
      participants
      price
      type
    }
    }
    }
  4. Result is null

    {
    "data": {
    "boredapi": {
      "a": null
    }
    }
    }

Expected behavior The output should be valid, not null

Screenshots image

Alan-Cha commented 2 years ago

This is very strange to me. Aliases should be outside our scope. It should be handled by the GraphQL engine. I don't see how it should be related to the schema and the resolvers that OtG generates.

Unfortunately, it will be quite some time before I come around to this. To be honest, I haven't had any time to work on this library at all even though I would like to. I definitely plan on working on OtG the first opportunity I have but for now, I do not know when I can look at this. Thank you very much for reporting the issue however!