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

Create object type if there are links #443

Open Alan-Cha opened 2 years ago

Alan-Cha commented 2 years ago

Currently, the response body schema has a higher priority than if there are link objects.

For example, if the response schema is:

"content": {
    "text/plain": {
      "schema": {
        "type": "string"
        }
      }
    }
  }

or

"content": {
    "application/json": {
      "schema": {
        "type": "string"
        }
      }
    }
  }

... OtG will create a field with a string return type, which means we cannot add fields created from link objects.

Only when OtG is already going to create a field with an object return type can a link field be added.

"content": {
    "application/json": {
      "schema": {
        "type": "string",
        "properties": {
          "hello": {
            "type": "string"
          }
        }
      }
    }
  }

I think that if there is a link object, we should consider defaulting to an object type so that we can add the link field. I think it will be a bit more complicated than that because we will need to map the response object appropriately but that is the gist.