Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Class Properties Not Reflected in GraphQL Schema When Using SWC Builder #14351

Open
3 of 15 tasks
maronnjapan opened this issue Dec 24, 2024 · 0 comments
Open
3 of 15 tasks
Labels
needs triage This issue has not been looked into

Comments

@maronnjapan
Copy link

maronnjapan commented Dec 24, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When generating a schema from a model using @ObjectType, if swc is specified as the builder in nestjs-cli.json, the id property does not become nullable in the schema.

import { Field, ObjectType } from "@nestjs/graphql";

@ObjectType()
export class Hoge {
    @Field(() => String)
    id?: string;
}
# generated schema
type Hoge {
  id: String!
}

However, with no builder specified, the id property becomes nullable with the above definition.

Minimum reproduction code

https://github.com/maronnjapan/test-nestjs-graphql-in-swc

Steps to reproduce

  1. pnpm i
  2. pnpm start:dev

Expected behavior

When switching to the swc builder, we expect the generated schema to remain the same as the default one.
Even if it changes, we would like to understand why the behavior differs when switching to the swc builder.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

@nestjs/graphql

NestJS version

10.4.15

Packages versions

{
"scripts": {
"build": "nest build",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/graphql": "^12.2.2",
"@nestjs/mercurius": "^12.2.2",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.4.15",
"graphql": "^16.10.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@swc/cli": "^0.5.2",
"@swc/core": "^1.10.1",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
}

Node.js version

20.11.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

The nest-cli.json in the sample project is as follows:

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "deleteOutDir": true,
    "builder":"swc",
    "plugins": [
      {"name": "@nestjs/graphql","options":{
        "controllerKeyOfComment": "true"
      }},
      "@nestjs/graphql/plugin"
    ]
  }
}
@maronnjapan maronnjapan added the needs triage This issue has not been looked into label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

1 participant