nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

field (union/intersection/ambiguous type was used) #2066

Closed RobinYang11 closed 2 years ago

RobinYang11 commented 2 years ago

Is there an existing issue for this?

Current behavior

F:\workdir\graphql_cad_service\node_modules\reflect-metadata\Reflect.js:553 var decorated = decorator(target, propertyKey, descriptor); ^ Error: Cannot determine a type for the "Material.materialSecondType" field (union/intersection/ambiguous type was used). Make sure your property is decorated with a "@Prop({ type: TYPE_HERE })" decorator. at F:\workdir\graphql_cad_service\node_modules\@nestjs\mongoose\dist\decorators\prop.decorator.js:22:23 at DecorateProperty (F:\workdir\graphql_cad_service\node_modules\reflect-metadata\Reflect.js:553:33) at Object.decorate (F:\workdir\graphql_cad_service\node_modules\reflect-metadata\Reflect.js:123:24) at __decorate (F:\workdir\graphql_cad_service\dist\components\material\entities\material.schema.js:4:92) at Object. (F:\workdir\graphql_cad_service\src\components\material\entities\material.schema.ts:29:2) at Module._compile (internal/modules/cjs/loader.js:1068:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10) at Module.load (internal/modules/cjs/loader.js:933:32) at Function.Module._load (internal/modules/cjs/loader.js:774:14) at Module.require (internal/modules/cjs/loader.js:957:19)

Minimum reproduction code

none

Steps to reproduce

No response

Expected behavior

// sechma @Prop() @Field(() => MaterialTopType, { description: "材料分类(二级)", nullable: true }) materialTopType: MaterialTopType;

// error F:\workdir\graphql_cad_service\node_modules\reflect-metadata\Reflect.js:553 var decorated = decorator(target, propertyKey, descriptor); ^ Error: Cannot determine a type for the "Material.materialSecondType" field (union/intersection/ambiguous type was used). Make sure your property is decorated with a "@Prop({ type: TYPE_HERE })" decorator. at F:\workdir\graphql_cad_service\node_modules\@nestjs\mongoose\dist\decorators\prop.decorator.js:22:23 at DecorateProperty (F:\workdir\graphql_cad_service\node_modules\reflect-metadata\Reflect.js:553:33) at Object.decorate (F:\workdir\graphql_cad_service\node_modules\reflect-metadata\Reflect.js:123:24) at __decorate (F:\workdir\graphql_cad_service\dist\components\material\entities\material.schema.js:4:92) at Object. (F:\workdir\graphql_cad_service\src\components\material\entities\material.schema.ts:29:2) at Module._compile (internal/modules/cjs/loader.js:1068:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10) at Module.load (internal/modules/cjs/loader.js:933:32) at Function.Module._load (internal/modules/cjs/loader.js:774:14) at Module.require (internal/modules/cjs/loader.js:957:19)

Package version

8.1.3

Graphql version

"@nestjs/common": "^8.0.0", "@nestjs/config": "^1.1.5", "@nestjs/core": "^8.0.0", "@nestjs/graphql": "^9.1.2", "@nestjs/jwt": "^8.0.0", "@nestjs/mongoose": "^9.0.2", "@nestjs/platform-express": "^8.0.0", "@nestjs/typeorm": "^8.0.2", "@types/cache-manager": "^3.4.2", "@types/redis": "^4.0.11", "apollo-server-express": "^3.5.0",

NestJS version

^8.0.0

Node.js version

14.17.0

In which operating systems have you tested?

Other

import { MaterialSecondType } from './../../material_second_type/entities/material_second_type.schema'; import { Field, ObjectType } from "@nestjs/graphql"; import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; import { FillPattern } from 'src/components/fill_pattern/entities/fill_pattern.schema'; import { MaterialTopType } from 'src/components/material_top_type/entities/material_top_type.schema'; import { Document } from 'mongoose';

@ObjectType() @Schema() export class Material extends Document {

@Field({ description: "" })
id: string;

@Prop()
@Field({ description: "产品图url" })
productFigureUrl: string;

@Prop()
@Field({ description: "品牌" })
brand: string;

@Prop()
@Field({ description: "材料名称" })
name: string;

@Prop()
@Field(() => MaterialSecondType, { description: "材料分类(二级)", nullable: true })
materialSecondType: MaterialSecondType;

@Prop()
@Field({ description: "材料分类(二级)ID" })
materialSecondTypeId: string;

@Prop()
@Field(() => MaterialTopType, { description: "材料分类(二级)", nullable: true })
materialTopType: MaterialTopType;

@Prop()
@Field({ description: "材料分类(二级)ID", nullable: true })
materialTopTypeId: string;

@Prop()
@Field({ description: "使用场景url" })
usageScenariosUrl: string;

@Prop()
@Field({ description: "经验" })
context: string;

@Prop()
@Field({ description: "表面填充样式" })
surfaceFillPattern: FillPattern;

@Prop()
@Field({ description: "截面填充样式" })
crossSectionFillPattern: FillPattern;

@Prop()
@Field({ description: "表面填充样式ID" })
surfaceFillPatternId: string;

@Prop()
@Field({ description: "截面填充样式ID" })
crossSectionFillPatternId: string;

@Prop()
@Field({ description: "是否删除" })
isDel: boolean;

@Prop()
@Field({ description: "防火等级Id" })
fireRating: string;

@Prop()
@Field({ description: "环保等级Id" })
environmentalProtectionLevel: string;

@Prop()
@Field({ description: "耐磨等级Id" })
wearResistingLevel: string;

@Prop()
@Field({ description: "防水等级Id" })
waterproofLevel: string;

@Prop()
@Field({ description: "防滑等级Id" })
preventSlipperyLevel: string;

@Prop()
@Field({ description: "材料流水号" })
materialNumber: number;

@Prop()
@Field({ description: "私有的材料编号(以供在本库进行编号的模糊查询)" })
privateMaterialNumber: string;

@Prop()
@Field({ description: "创建时间" })
tmCreate: number;

@Prop()
@Field({ description: "修改时间" })
tmModify: number;

@Prop()
@Field({ description: "详细名首字母大写组合,用于排序" })
sortedCode: string;

@Prop()
@Field({ description: "0-无需导入   1-付费可导入  2-基本可导入" })
statusCode: number;

@Prop()
@Field({ description: "'OFFICIAL'为官方  其他为客户" })
clientId: string;

}

export const MaterialSchema = SchemaFactory.createForClass(Material);

jmcdo29 commented 2 years ago

Please use our Discord channel (Support). We are using GitHub to track Bug Reports, Feature Requests, and Regressions.