英文:
how to query enum data type with grpahql
问题
我如何从GraphQL查询枚举。我正在使用Nest.js和GraphQL,并且出现错误:"message": "Enum "TraitReportType" cannot represent value: "EMBEDDED"。",
我尝试使用type: EMBEDDED,但不起作用。还尝试使用try {},但在子选择中也不起作用。
这是我的类型:@Expose()
@IsDefined()
@IsEnum(TraitReportType)
@ApiProperty({ enum: TraitReportType })
@Field(() => TraitReportType, { nullable: false })
type: TraitReportType;
进一步的TraitReportType:import { registerEnumType } from '@nestjs/graphql';
export enum TraitReportType {
LAYOUT = 'layout',
EMBEDDED = 'embedded',
}
registerEnumType(TraitReportType, {
name: 'TraitReportType',
description: 'Trait Report Type枚举类型',
});
我如何查询:
query EntityReportsQuery($id: ID!) {
entity(id: $id) {
id
secondaryId
reports {
key
name
description
icon {
type
component
name
size
source
}
type
layout
url
}
}
}
我从数据库查询的数据是:
{
"key": "A",
"url": "https://search.mevris.app/s/app-dashboards/app/dashboards#/view/204e17a0-a6df-11ed-ac80-b52d3b051a25?embed=true&_g=(filters:!(('$state':(store:globalState),meta:(alias:!n,disabled:!f,key:entityId.keyword,negate:!f,params:(query:%2203258d26-3914-4a19-b919-f8e88f3a68dd%22),type:phrase),query:(match_phrase:(entityId:%22${id}%22)))),refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&show-time-filter=true&hide-filter-bar=true",
"icon": {
"name": "current-ac",
"size": 2.7,
"type": "type icon",
"component": "component"
},
"name": "Current",
"type": "EMBEDDED",
"description": "Sum of Current"
}
我尝试使用type: EMBEDDED,但不起作用。
<details>
<summary>英文:</summary>
how can i query enum from graphql . i am using nest.js with graphql
and error : "message": "Enum \"TraitReportType\" cannot represent value: \"EMBEDDED\"",
i try with type:EMBEEDED but did not works . also try with try {} also did not work with sub selection .
here is my type : @Expose()
@IsDefined()
@IsEnum(TraitReportType)
@ApiProperty({ enum: TraitReportType })
@Field(() => TraitReportType, { nullable: false })
type: TraitReportType;
further TraitReportType : import { registerEnumType } from '@nestjs/graphql';
export enum TraitReportType {
LAYOUT = 'layout',
EMBEDDED = 'embedded',
}
registerEnumType(TraitReportType, {
name: 'TraitReportType',
description: 'Trait Report Type enum types',
});
how i query : query EntityReportsQuery($id: ID!) {
entity(id: $id) {
id
secondaryId
reports {
key
name
description
icon {
type
component
name
size
source
}
type
layout
url
}
}
} and data which i query from db is : {
"key": "A",
"url": "https://search.mevris.app/s/app-dashboards/app/dashboards#/view/204e17a0-a6df-11ed-ac80-b52d3b051a25?embed=true&_g=(filters:!(('$state':(store:globalState),meta:(alias:!n,disabled:!f,key:entityId.keyword,negate:!f,params:(query:%2203258d26-3914-4a19-b919-f8e88f3a68dd%22),type:phrase),query:(match_phrase:(entityId:%22${id}%22)))),refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&show-time-filter=true&hide-filter-bar=true",
"icon": {
"name": "current-ac",
"size": 2.7,
"type": "type icon",
"component": "component"
},
"name": "Current",
"type": "EMBEDDED",
"description": "Sum of Current"
}
`
i try with type:EMBEEDED but did not works .
</details>
# 答案1
**得分**: 0
{
"key": "A",
"url": "https://search.mevris.app/s/app-dashboards/app/dashboards#/view/204e17a0-a6df-11ed-ac80-b52d3b051a25?embed=true&_g=(filters:!((%24state:(store:globalState),meta:(alias:!n,disabled:!f,key:entityId.keyword,negate:!f,params:(query:%2203258d26-3914-4a19-b919-f8e88f3a68dd%22),type:phrase),query:(match_phrase:(entityId:%22${id}%22)))),refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&show-time-filter=true&hide-filter-bar=true",
"icon": {
"name": "current-ac",
"size": 2.7,
"type": "type icon",
"component": "component"
},
"name": "Current",
"type": "embedded",
"description": "Sum of Current"
} i just replace in db "type": "EMBEDDED", with "type": "embedded" then it works
<details>
<summary>英文:</summary>
{
"key": "A",
"url": "https://search.mevris.app/s/app-dashboards/app/dashboards#/view/204e17a0-a6df-11ed-ac80-b52d3b051a25?embed=true&_g=(filters:!(('$state':(store:globalState),meta:(alias:!n,disabled:!f,key:entityId.keyword,negate:!f,params:(query:%2203258d26-3914-4a19-b919-f8e88f3a68dd%22),type:phrase),query:(match_phrase:(entityId:%22${id}%22)))),refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&show-time-filter=true&hide-filter-bar=true",
"icon": {
"name": "current-ac",
"size": 2.7,
"type": "type icon",
"component": "component"
},
"name": "Current",
"type": "EMBEDDED",
"description": "Sum of Current"
} i just replace in db "type": "EMBEDDED", with "type": "embedded" then it works
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论