Search code examples
typescriptgraphqlnestjs

how to query enum data type with grpahql


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 .


Solution

  • {
      "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