question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use 'in' operator to search for '#' in undefined

See original GitHub issue

Describe the bug After creating a new project with the loopback 4 cli, I try to create a graphql schema from the Openapi json file. However, it fails with following error:

openapi-to-graphql http://localhost:3000/openapi.json
OpenAPI-to-GraphQL creation event error: Cannot use 'in' operator to search for '#' in undefined

To Reproduce Steps to reproduce the behavior:

  1. Create new project with tslint (lb4 app)
  2. Create new model with id, name, image, subphase (lb4 controller)
  3. Create new in-memory datasource (lb4 datasource)
  4. Create new repository with DefaultCrudRepository (lb4 repository)
  5. Create new controller (lb4 controller)
  6. Start the project (npm start)
  7. Use openapi-to-graphql to get new schema (openapi-to-graphql http://localhost:3000/openapi.json)
  8. See above error

Expected behavior Expect a Graphql schema of this because I did not change any code of the model, repository or controller. It should at least work with a generated project to start developing.

Code

export class PartnerController {
  constructor(
    @repository(PartnerRepository)
    public partnerRepository : PartnerRepository,
  ) {}

  @post('/partners', {
    responses: {
      '200': {
        description: 'Partner model instance',
        content: {'application/json': {schema: getModelSchemaRef(Partner)}},
      },
    },
  })
  async create(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Partner, {
            title: 'NewPartner',
            
          }),
        },
      },
    })
    partner: Partner,
  ): Promise<Partner> {
    return this.partnerRepository.create(partner);
  }

  @get('/partners/count', {
    responses: {
      '200': {
        description: 'Partner model count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  async count(
    @param.where(Partner) where?: Where<Partner>,
  ): Promise<Count> {
    return this.partnerRepository.count(where);
  }

  @get('/partners', {
    responses: {
      '200': {
        description: 'Array of Partner model instances',
        content: {
          'application/json': {
            schema: {
              type: 'array',
              items: getModelSchemaRef(Partner, {includeRelations: true}),
            },
          },
        },
      },
    },
  })
  async find(
    @param.filter(Partner) filter?: Filter<Partner>,
  ): Promise<Partner[]> {
    return this.partnerRepository.find(filter);
  }

  @patch('/partners', {
    responses: {
      '200': {
        description: 'Partner PATCH success count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  async updateAll(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Partner, {partial: true}),
        },
      },
    })
    partner: Partner,
    @param.where(Partner) where?: Where<Partner>,
  ): Promise<Count> {
    return this.partnerRepository.updateAll(partner, where);
  }

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

  @patch('/partners/{id}', {
    responses: {
      '204': {
        description: 'Partner PATCH success',
      },
    },
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Partner, {partial: true}),
        },
      },
    })
    partner: Partner,
  ): Promise<void> {
    await this.partnerRepository.updateById(id, partner);
  }

  @put('/partners/{id}', {
    responses: {
      '204': {
        description: 'Partner PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() partner: Partner,
  ): Promise<void> {
    await this.partnerRepository.replaceById(id, partner);
  }

  @del('/partners/{id}', {
    responses: {
      '204': {
        description: 'Partner DELETE success',
      },
    },
  })
  async deleteById(@param.path.number('id') id: number): Promise<void> {
    await this.partnerRepository.deleteById(id);
  }
}

If this issue is missing some information, please let me know!

Thanks, Maikel

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Alan-Chacommented, Jun 15, 2020

@mcoenen1994 @yassinebenameur @Geril Sorry for the long wait. I couldn’t find any time at all to work on OtG in the last for weeks. I believe I have finally resolved this issue however. Please update to v2.1.1 and let me know if this problem still persists.

@mcoenen1994 Your repo was instrumental to debugging this problem. Thank you very much for creating it!

0reactions
Gerilcommented, Jun 15, 2020

Works for me as well! Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: cannot use 'in' operator to search for 'x' in 'y'
The JavaScript exception "right-hand side of 'in' should be an object" occurs when the in operator was used to search in strings, ...
Read more >
Cannot use 'in' operator to search for 'sth' in undefined
Problem was simply checking if object has xhr element. By default it does not exist so it's undefined , and you were asking...
Read more >
JavaScript TypeError - Cannot use 'in' operator to search for 'X ...
Cause of the Error: The in operator can be used only for to check if a property is in an object. This can...
Read more >
Error: Cannot use 'in' operator to search for 'undefined' in ...
I added all the variables myself in the Javascript. However, the problem now is TypeError: Cannot use 'in' operator to search for 'undefined' ......
Read more >
Uncaught TypeError Cannot use in operator to search for 324
I'm trying to send a Get request by ajax and output json data that is returned by server in html. But, I got...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found