nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.02k stars 7.56k forks source link

nest@10 graphl introspectComments generate gql fail #11911

Closed LastKing closed 1 year ago

LastKing commented 1 year ago

Is there an existing issue for this?

Current behavior

  1. start
  2. check schema.gql
  3. AuthorModel.id field don't generate in shema.gql
type Author {
  firstName: String
  lastName: String
  posts: [Post!]!
}

Minimum reproduction code

https://github.com/toonew-issue/nestjs-swc-graphql-comments

Steps to reproduce

  1. webstorm debug run npm run start:debug
  2. See schema.gql

Expected behavior

expect generate

type Author {
  firstName: String
  lastName: String
  posts: [Post!]!

  """Test"""
  id: Float!
}

Package

Other package

No response

NestJS version

10.0.5

Packages versions

{
  "name": "nestjs-study",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@apollo/server": "^4.7.5",
    "@nestjs/apollo": "^12.0.4",
    "@nestjs/common": "^10.0.3",
    "@nestjs/core": "^10.0.3",
    "@nestjs/graphql": "^12.0.4",
    "@nestjs/platform-express": "^10.0.3",
    "graphql": "^16.7.1",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.5",
    "@nestjs/schematics": "^10.0.1",
    "@nestjs/testing": "^10.0.3",
    "@swc/cli": "^0.1.62",
    "@swc/core": "^1.3.66",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.2",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^5.60.1",
    "@typescript-eslint/parser": "^5.60.1",
    "eslint": "^8.43.0",
    "eslint-config-prettier": "^8.8.0",
    "eslint-plugin-prettier": "^4.2.1",
    "jest": "^29.5.0",
    "prettier": "^2.8.8",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

Node.js version

18.16.0

In which operating systems have you tested?

Other

No response

LastKing commented 1 year ago

remove nestjs-cli.json file compilerOptions.builder:"swc" ,genereateschema.gql return to normal

kamilmysliwiec commented 1 year ago

Did you follow this guide https://docs.nestjs.com/graphql/cli-plugin#swc-builder?

LastKing commented 1 year ago

Sorry, I didn't notice this guide section before.

I flow this guide,change my mini projejct,add "compilerOptions.typeCheck:true" in nest-cli.json.

A new problem arises。

metadata.ts as follows

/* eslint-disable */
export default async () => {
  const t = {};
  return {
    '@nestjs/graphql': {
      models: [
        [
          import('../D:/code/node-tx/nestjs-study/src/author/model/post.model'),   //  1
          { Post: {} },
        ],
        [
          import(
            '../D:/code/node-tx/nestjs-study/src/author/model/author.model'  // 2
          ),
          { Author: { id: { type: () => Number, description: 'Test' } } },
        ],
      ],
    },
  };
};

above code 1 2 ,the path wrong.

It doesn't look like an absolute path, nor does it look like a relative path.

LastKing commented 1 year ago

normalizeImportPath

the method receive value: pathToSource: D:\\code\\node-tx\\nestjs-study\\src path: D:/code/node-tx/nestjs-study/src/author/model/author.model.ts result: ../D:/code/node-tx/nestjs-study/src/author/model/author.model.ts

kamilmysliwiec commented 1 year ago

This should be fixed in @nestjs/graphql@12.0.5