Loopback-next: Unable to use GraphQL-to-OpenAPI wrappers

Created on 28 May 2020  路  8Comments  路  Source: strongloop/loopback-next

Steps to reproduce

lb4 project_name
lb4 model (create any)
lb4 repository
lb4 controller

npm i --save openapi-to-graphql-cli
npx openapi-to-graphql --port=3001 http://localhost:3000/openapi.json

Current Behavior


npx openapi-to-graphql --port=3001 http://localhost:3000/openapi.json
OpenAPI-to-GraphQL creation event error: Cannot use 'in' operator to search for '#' in undefined
(node:25724) UnhandledPromiseRejectionWarning: AssertionError: Identical path templates detected
....
....
(node:25724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


Expected Behavior

GraphQL accessible at: http://localhost:3001/graphql

Link to reproduction sandbox


lb4 project_name
lb4 model (create any)
lb4 repository 
lb4 controller

npm i --save openapi-to-graphql-cli
npx openapi-to-graphql --port=3001 http://localhost:3000/openapi.json

OR

openapi-to-graphql --port=3001 http://localhost:3000/openapi.json

Why doesnt start the graphql server once u make a model, repo and a controller.?

Even the to do example that u have https://github.com/strongloop/loopback-next/tree/master/examples/todo does not work and throw the same error

Solution

npm install --save oasgraph
sudo npm i -g oasgraph-cli
oasgraph --port=3001 http://localhost:3000/openapi.json

still doesnt work as expected :(

Apparently the new naming doesnt work properly

Got the following warnings from your TODO example

{
  "warnings": [
    {
      "type": "MissingResponseSchema",
      "message": "Operation 'PUT /todos/{id}' has no (valid) response schema.You can create placeholder schemas using the fillEmptyResponses option.",
      "mitigation": "Ignore operation"
    },
    {
      "type": "MissingResponseSchema",
      "message": "Operation 'PATCH /todos/{id}' has no (valid) response schema.You can create placeholder schemas using the fillEmptyResponses option.",
      "mitigation": "Ignore operation"
    },
    {
      "type": "MissingResponseSchema",
      "message": "Operation 'DELETE /todos/{id}' has no (valid) response schema.You can create placeholder schemas using the fillEmptyResponses option.",
      "mitigation": "Ignore operation"
    },
    {
      "type": "InvalidSchemaType",
      "message": "Request / response schema has no (valid) type: {}",
      "mitigation": "Fall back to type 'GraphQL String'"
    },
    {
      "type": "InvalidSchemaType",
      "message": "Request / response schema has no (valid) type: {}",
      "mitigation": "Fall back to type 'GraphQL String'"
    }
  ],
  "numOps": 6,
  "numOpsQuery": 2,
  "numOpsMutation": 4,
  "numQueriesCreated": 2,
  "numMutationsCreated": 1
}

Further debbuging pointed me to @get deccorator

(node:31186) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:31186) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It doesnt like controller with get for ID

  @get('/draft_speakers/{id}', {
    responses: {
      '200': {
        description: 'DraftSpeakers model instance',
        content: {
          'application/json': {
            schema: getModelSchemaRef(DraftSpeakers, { includeRelations: true }),
          },
        },
      },
    },
  })
  async findById(
    @param.path.string('uuid') uuid: string,
    @param.filter(DraftSpeakers, { exclude: 'where' }) filter?: FilterExcludingWhere<DraftSpeakers>
  ): Promise<DraftSpeakers> {
    return this.draftSpeakersRepository.findById(uuid, filter);

Yea thats basically as far as i could get, very unfortunate that its not working properly. But it has to be somesort of overlap with some routes and it doesnt like it.
Its either

(node:32440) UnhandledPromiseRejectionWarning: AssertionError: path parameters must appear in the path

OR

(node:32493) UnhandledPromiseRejectionWarning: AssertionError: Identical path templates detected

Another recommendation would be to have better logs, because the output is not helpful at all, u cant pin point to the source of the problem, its node_modules stuff.

edited: P.S the error of the title of this thread(Cannot use 'in' operator to search for '#' in undefined) can be fixed by installing oasgraph

OpenAPI bug

All 8 comments

@Alan-Cha, could you please take a look as well? Thanks.

@GitMastStas Sorry for the long delay. Unfortunately, I've needed to prioritize other work so I haven't had a chance to take a look at this. I should be able to address this problem beginning of next week. Sadly, it is the best that I can do for now.

thanks anyway, look forward to your evaluation of this problem :)

Any news on this front?

@GitMastStas Actually, I just created a new release v2.1.1 which should resolve this issue! Can you try and let me know if it works for you?

@GitMastStas In your sample code, the variable in your endpoint url path is not the same as the one in the method parameter. {id} and 'uuid'. Could that be the issue?

@get('/draft_speakers/{id}', {
    responses: {
      '200': {
        description: 'DraftSpeakers model instance',
        content: {
          'application/json': {
            schema: getModelSchemaRef(DraftSpeakers, { includeRelations: true }),
          },
        },
      },
    },
  })
  async findById(
    @param.path.string('uuid') uuid: string,
    @param.filter(DraftSpeakers, { exclude: 'where' }) filter?: FilterExcludingWhere<DraftSpeakers>
  ): Promise<DraftSpeakers> {
    return this.draftSpeakersRepository.findById(uuid, filter);

Closing due to inactivity. Feel free to comment if the problem persists.

FYI - for issues related to openapi-to-graphql, please open an issue over https://github.com/ibm/openapi-to-graphql. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rexliu0715 picture rexliu0715  路  3Comments

teambitcodeGIT picture teambitcodeGIT  路  3Comments

mightytyphoon picture mightytyphoon  路  3Comments

kesavkolla picture kesavkolla  路  3Comments

mhdawson picture mhdawson  路  3Comments