Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to infer GraphQL type from TypeScript reflection system

I'm trying to create an Alert class as follows:

@ObjectType()
export class Alert {
  @Field()
  status: 'error' | 'success' | 'warning' | 'info' | undefined

  @Field(() => [String])
  messages: string[];
}

However, it gives me the following error message:

Error: Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for 'status' of 'Alert' class.

like image 617
Ellie G Avatar asked Aug 22 '20 05:08

Ellie G


1 Answers

Create a type for 'error' | 'success' | 'warning' | 'info' | undefined and add it to the field definition as such: @Field(() => StatusType)

It's basically complaining that it can't infer the type of that field as it's not a primitive, whenever a field is an object or other user defined type you will need to provide type information like I've described

like image 96
Fiachna Carter Avatar answered Nov 13 '22 13:11

Fiachna Carter