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 208 forks source link

Cannot create property '_openAPIToGraphQL' on number #380

Open angrocode opened 3 years ago

angrocode commented 3 years ago
openapi-to-graphql/lib/resolver_builder.js:505
                                                element[exports.OPENAPI_TO_GRAPHQL] = {
                                                                                    ^

TypeError: Cannot create property '_openAPIToGraphQL' on number '99000006'
    at /opt/nodejs/gate_rest_graph/node_modules/openapi-to-graphql/lib/resolver_builder.js:505:85
    at Array.forEach (<anonymous>)
    at Request._callback (/opt/nodejs/gate_rest_graph/node_modules/openapi-to-graphql/lib/resolver_builder.js:503:50)
    at Request.self.callback (/opt/nodejs/gate_rest_graph/node_modules/request/request.js:185:22)
    at Request.emit (node:events:369:20)
    at Request.<anonymous> (/opt/nodejs/gate_rest_graph/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:369:20)
    at IncomingMessage.<anonymous> (/opt/nodejs/gate_rest_graph/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:475:28)
    at IncomingMessage.emit (node:events:381:22)

Library version 2.3.0

Alan-Cha commented 3 years ago

@angrocode This is a very interesting error. _openAPIToGraphQL is a field that is added to API call responses to pass request/response information to other resolvers down the chain (for example in nested fields from link objects).

Can you provide a sample OAS so it is easier to debug this error?

angrocode commented 3 years ago

https://esi.evetech.net/latest/swagger.json It doesn't accept the whole thing because of the size You can save universe Answer in numbers /universe/systems/ /universe/regions/ ....

KolbySisk commented 3 years ago

Hi, I'm running into this same problem. I have an endpoint that returns an array of ints.

Here is the response from the swagger doc

"responses": {
      "200": {
          "description": "OK",
          "schema": {
              "type": "array",
              "items": {
                  "type": "integer",
                  "format": "int32"
              }
          }
      }
  }
KolbySisk commented 3 years ago

@Alan-Cha Any thoughts on the cause of this?

It seems to happen anytime I have an endpoint that returns an array of primitives.

Kichrum commented 3 years ago

The same error with an array of primitives (in my case - string) also in @graphql-mesh/openapi

So both libs support only objects in response?

Alan-Cha commented 3 years ago

@KolbySisk Sorry for the delay. I would like to take a look at this issue today. I'll let you know if I discover anything.

@Kichrum No, this library should be able to support anything in the response, primitive, objects, arrays of primitives, arrays of objects, even more complex cases like objects using oneOf (which should generate a union type).

daniloalexandre commented 3 years ago

Hi, Everyone, Have you advanced with this issue? I'm facing the same problem with string arrays.

OAS:

responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
                  example: Cielo

Exception:


ERROR: uncaughtException: Cannot create property '_openAPIToGraphQL' on string 'Cielo'
TypeError: Cannot create property '_openAPIToGraphQL' on string 'Cielo'```
ReginaldoSantos commented 3 years ago

+1

Hi @Alan-Cha, any news on that?

It looks very similar to #412 and I'm also stucked on it!

yondh commented 1 year ago

@Alan-Cha Any new regarding this issue?