Skip to content

Commit f176aec

Browse files
astubenbordAnton Stubenbord
andauthored
fix: Escape enum literals starting with underscore (heftapp#329)
Co-authored-by: Anton Stubenbord <anton2@heat-mvmnt.de>
1 parent ff4c70c commit f176aec

3 files changed

Lines changed: 202 additions & 1 deletion

File tree

packages/graphql_codegen/lib/src/printer/utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ class NamePrinter {
182182
String printKeywordSafe(String name) =>
183183
_keywords.contains(name) ? "\$${name}" : name;
184184

185-
String printEnumValueName(NameNode name) => printKeywordSafe(name.value);
185+
String printEnumValueName(NameNode name) =>
186+
_printPropertyNameString(name.value);
186187

187188
String printPropertyName(NameNode name) =>
188189
_printPropertyNameString(name.value);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
enum CustomEnum {
2+
nonPrivateLiteral
3+
_privateLiteral
4+
}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
enum Enum$CustomEnum { nonPrivateLiteral, $_privateLiteral, $unknown }
2+
3+
String toJson$Enum$CustomEnum(Enum$CustomEnum e) {
4+
switch (e) {
5+
case Enum$CustomEnum.nonPrivateLiteral:
6+
return r'nonPrivateLiteral';
7+
case Enum$CustomEnum.$_privateLiteral:
8+
return r'_privateLiteral';
9+
case Enum$CustomEnum.$unknown:
10+
return r'$unknown';
11+
}
12+
}
13+
14+
Enum$CustomEnum fromJson$Enum$CustomEnum(String value) {
15+
switch (value) {
16+
case r'nonPrivateLiteral':
17+
return Enum$CustomEnum.nonPrivateLiteral;
18+
case r'_privateLiteral':
19+
return Enum$CustomEnum.$_privateLiteral;
20+
default:
21+
return Enum$CustomEnum.$unknown;
22+
}
23+
}
24+
25+
enum Enum$__TypeKind {
26+
SCALAR,
27+
OBJECT,
28+
INTERFACE,
29+
UNION,
30+
ENUM,
31+
INPUT_OBJECT,
32+
LIST,
33+
NON_NULL,
34+
$unknown
35+
}
36+
37+
String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
38+
switch (e) {
39+
case Enum$__TypeKind.SCALAR:
40+
return r'SCALAR';
41+
case Enum$__TypeKind.OBJECT:
42+
return r'OBJECT';
43+
case Enum$__TypeKind.INTERFACE:
44+
return r'INTERFACE';
45+
case Enum$__TypeKind.UNION:
46+
return r'UNION';
47+
case Enum$__TypeKind.ENUM:
48+
return r'ENUM';
49+
case Enum$__TypeKind.INPUT_OBJECT:
50+
return r'INPUT_OBJECT';
51+
case Enum$__TypeKind.LIST:
52+
return r'LIST';
53+
case Enum$__TypeKind.NON_NULL:
54+
return r'NON_NULL';
55+
case Enum$__TypeKind.$unknown:
56+
return r'$unknown';
57+
}
58+
}
59+
60+
Enum$__TypeKind fromJson$Enum$__TypeKind(String value) {
61+
switch (value) {
62+
case r'SCALAR':
63+
return Enum$__TypeKind.SCALAR;
64+
case r'OBJECT':
65+
return Enum$__TypeKind.OBJECT;
66+
case r'INTERFACE':
67+
return Enum$__TypeKind.INTERFACE;
68+
case r'UNION':
69+
return Enum$__TypeKind.UNION;
70+
case r'ENUM':
71+
return Enum$__TypeKind.ENUM;
72+
case r'INPUT_OBJECT':
73+
return Enum$__TypeKind.INPUT_OBJECT;
74+
case r'LIST':
75+
return Enum$__TypeKind.LIST;
76+
case r'NON_NULL':
77+
return Enum$__TypeKind.NON_NULL;
78+
default:
79+
return Enum$__TypeKind.$unknown;
80+
}
81+
}
82+
83+
enum Enum$__DirectiveLocation {
84+
QUERY,
85+
MUTATION,
86+
SUBSCRIPTION,
87+
FIELD,
88+
FRAGMENT_DEFINITION,
89+
FRAGMENT_SPREAD,
90+
INLINE_FRAGMENT,
91+
VARIABLE_DEFINITION,
92+
SCHEMA,
93+
SCALAR,
94+
OBJECT,
95+
FIELD_DEFINITION,
96+
ARGUMENT_DEFINITION,
97+
INTERFACE,
98+
UNION,
99+
ENUM,
100+
ENUM_VALUE,
101+
INPUT_OBJECT,
102+
INPUT_FIELD_DEFINITION,
103+
$unknown
104+
}
105+
106+
String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
107+
switch (e) {
108+
case Enum$__DirectiveLocation.QUERY:
109+
return r'QUERY';
110+
case Enum$__DirectiveLocation.MUTATION:
111+
return r'MUTATION';
112+
case Enum$__DirectiveLocation.SUBSCRIPTION:
113+
return r'SUBSCRIPTION';
114+
case Enum$__DirectiveLocation.FIELD:
115+
return r'FIELD';
116+
case Enum$__DirectiveLocation.FRAGMENT_DEFINITION:
117+
return r'FRAGMENT_DEFINITION';
118+
case Enum$__DirectiveLocation.FRAGMENT_SPREAD:
119+
return r'FRAGMENT_SPREAD';
120+
case Enum$__DirectiveLocation.INLINE_FRAGMENT:
121+
return r'INLINE_FRAGMENT';
122+
case Enum$__DirectiveLocation.VARIABLE_DEFINITION:
123+
return r'VARIABLE_DEFINITION';
124+
case Enum$__DirectiveLocation.SCHEMA:
125+
return r'SCHEMA';
126+
case Enum$__DirectiveLocation.SCALAR:
127+
return r'SCALAR';
128+
case Enum$__DirectiveLocation.OBJECT:
129+
return r'OBJECT';
130+
case Enum$__DirectiveLocation.FIELD_DEFINITION:
131+
return r'FIELD_DEFINITION';
132+
case Enum$__DirectiveLocation.ARGUMENT_DEFINITION:
133+
return r'ARGUMENT_DEFINITION';
134+
case Enum$__DirectiveLocation.INTERFACE:
135+
return r'INTERFACE';
136+
case Enum$__DirectiveLocation.UNION:
137+
return r'UNION';
138+
case Enum$__DirectiveLocation.ENUM:
139+
return r'ENUM';
140+
case Enum$__DirectiveLocation.ENUM_VALUE:
141+
return r'ENUM_VALUE';
142+
case Enum$__DirectiveLocation.INPUT_OBJECT:
143+
return r'INPUT_OBJECT';
144+
case Enum$__DirectiveLocation.INPUT_FIELD_DEFINITION:
145+
return r'INPUT_FIELD_DEFINITION';
146+
case Enum$__DirectiveLocation.$unknown:
147+
return r'$unknown';
148+
}
149+
}
150+
151+
Enum$__DirectiveLocation fromJson$Enum$__DirectiveLocation(String value) {
152+
switch (value) {
153+
case r'QUERY':
154+
return Enum$__DirectiveLocation.QUERY;
155+
case r'MUTATION':
156+
return Enum$__DirectiveLocation.MUTATION;
157+
case r'SUBSCRIPTION':
158+
return Enum$__DirectiveLocation.SUBSCRIPTION;
159+
case r'FIELD':
160+
return Enum$__DirectiveLocation.FIELD;
161+
case r'FRAGMENT_DEFINITION':
162+
return Enum$__DirectiveLocation.FRAGMENT_DEFINITION;
163+
case r'FRAGMENT_SPREAD':
164+
return Enum$__DirectiveLocation.FRAGMENT_SPREAD;
165+
case r'INLINE_FRAGMENT':
166+
return Enum$__DirectiveLocation.INLINE_FRAGMENT;
167+
case r'VARIABLE_DEFINITION':
168+
return Enum$__DirectiveLocation.VARIABLE_DEFINITION;
169+
case r'SCHEMA':
170+
return Enum$__DirectiveLocation.SCHEMA;
171+
case r'SCALAR':
172+
return Enum$__DirectiveLocation.SCALAR;
173+
case r'OBJECT':
174+
return Enum$__DirectiveLocation.OBJECT;
175+
case r'FIELD_DEFINITION':
176+
return Enum$__DirectiveLocation.FIELD_DEFINITION;
177+
case r'ARGUMENT_DEFINITION':
178+
return Enum$__DirectiveLocation.ARGUMENT_DEFINITION;
179+
case r'INTERFACE':
180+
return Enum$__DirectiveLocation.INTERFACE;
181+
case r'UNION':
182+
return Enum$__DirectiveLocation.UNION;
183+
case r'ENUM':
184+
return Enum$__DirectiveLocation.ENUM;
185+
case r'ENUM_VALUE':
186+
return Enum$__DirectiveLocation.ENUM_VALUE;
187+
case r'INPUT_OBJECT':
188+
return Enum$__DirectiveLocation.INPUT_OBJECT;
189+
case r'INPUT_FIELD_DEFINITION':
190+
return Enum$__DirectiveLocation.INPUT_FIELD_DEFINITION;
191+
default:
192+
return Enum$__DirectiveLocation.$unknown;
193+
}
194+
}
195+
196+
const possibleTypesMap = <String, Set<String>>{};

0 commit comments

Comments
 (0)