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.

GraphQL: @ApiProperty(required=false) does not work

See original GitHub issue

In my Entity, I have a property:

/**
 * @var int The account balance
 *
 * @ORM\Column(type="integer")
 * @ApiProperty(required=false)
 * @Assert\Type(type="integer")
 */
private $balance = 0;

I want this property to be optional in my GraphQL query, but not in database.

So I added the required=false attributes, but it doesn’t work.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jensstaldercommented, Feb 7, 2022

So this is still an issue? Is there at least a workaround? For example I am trying to add a property to an entity that does not need to persist to the db at all. But it’s still a required field for graphql. At least when creating. when updating this does not seam to be a problem (since the values already exist and just get rehydrated into the entity already).

2reactions
brettinscommented, Apr 29, 2021

I am using a boolean with a default, which also should be a case where the GraphQL input is not required.

    /**
     * @ORM\Column(type="boolean",  options={"default": false})
     */
Read more comments on GitHub >

github_iconTop Results From Across the Web

Types and Parameters - OpenAPI - Documentation | NestJS
Hint Instead of explicitly typing the @ApiProperty({ required: false }) you can use the @ApiPropertyOptional() short-hand decorator.
Read more >
Parameter(required = false) not working in swagger open api v3
my problem is with annotation @Parameter that belongs to io.swagger.v3.oas.annotations.Parameter. by default should be required = false, but as ...
Read more >
CLI Plugin - OpenAPI - A progressive Node.js framework
The Swagger plugin will automatically: annotate all DTO properties with @ApiProperty unless @ApiHideProperty is used; set the required property depending on ...
Read more >
Setting up a Hybrid REST & GraphQL API with NestJS and ...
Both of them offer fantastic typing for querying and inserting/updating data, but TypeORM has accumulated some issues over the years and was ...
Read more >
OpenAPI for your REST APIs in NestJS - notiz.dev
The setup is complete, start your Nest application npm run start:dev and visit ... @ApiProperty({ required: false, nullable: true }) name?
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