Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does GraphQL take Int as enum

I was trying to create an enum type with Int value in GraphQL schema but failed. I might miss something in the doc. Anyone has any idea about how to implement Int value in the enum type like below?

enum IntValue {
  1
  2
  3
}
like image 286
ZSFS Avatar asked Oct 17 '22 15:10

ZSFS


1 Answers

You could declare something like

enum IntValue { _1 _2 _3 }
enum IntName { ONE TWO THREE }

but in both cases those enumerated values would be different from the numbers 1, 2, 3.

You can't declare something that looks like an enum but contains actual numbers. In the specification, an EnumTypeDefinition contains a list of EnumValueDefinition, each of which contains a single EnumValue; each value is

Name but not true or false or null

and finally a Name must begin with an underscore or a ASCII letter.

like image 97
David Maze Avatar answered Nov 22 '22 07:11

David Maze