Skip to content

Commit 1295e42

Browse files
committed
Add field deprecation support and tests
1 parent 6cc124d commit 1295e42

File tree

5 files changed

+327
-8
lines changed

5 files changed

+327
-8
lines changed

src/macros/field.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
#[doc(hidden)]
22
#[macro_export]
33
macro_rules! __graphql__build_field_matches {
4+
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
5+
(
6+
$resolveargs:tt,
7+
( $( $acc:tt )* ),
8+
field deprecated $_reason:tt $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
9+
) => {
10+
__graphql__build_field_matches!(
11+
$resolveargs,
12+
(($name; $args; $t; $body) $( $acc )*),
13+
$( $rest )*);
14+
};
15+
16+
// field deprecated <reason> <name>(...) -> <type> { ... }
17+
(
18+
$resolveargs:tt,
19+
( $( $acc:tt )* ),
20+
field deprecated $_reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
21+
) => {
22+
__graphql__build_field_matches!(
23+
$resolveargs,
24+
(($name; $args; $t; $body) $( $acc )*),
25+
$( $rest )*);
26+
};
27+
28+
// field <name>(...) -> <type> as <description> { ... }
429
(
530
$resolveargs:tt,
631
( $( $acc:tt )* ), field $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
@@ -11,6 +36,7 @@ macro_rules! __graphql__build_field_matches {
1136
$( $rest )*);
1237
};
1338

39+
// field <name>(...) -> <type> { ... }
1440
(
1541
$resolveargs:tt,
1642
( $( $acc:tt )* ), field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*

src/macros/interface.rs

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,44 @@ macro_rules! graphql_interface {
8888
( @as_item, $i:item) => { $i };
8989
( @as_expr, $e:expr) => { $e };
9090

91+
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
92+
(
93+
@gather_meta,
94+
$reg:expr, $acc:expr, $descr:expr,
95+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
96+
) => {
97+
$acc.push(__graphql__args!(
98+
@apply_args,
99+
$reg,
100+
$reg.field_inside_result(
101+
&$crate::to_snake_case(stringify!($name)),
102+
Err("dummy".to_owned()) as $t)
103+
.description($desc)
104+
.deprecated($reason),
105+
$args));
106+
107+
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
108+
};
109+
110+
// field deprecated <reason> <name>(...) -> <type> { ... }
111+
(
112+
@gather_meta,
113+
$reg:expr, $acc:expr, $descr:expr,
114+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
115+
) => {
116+
$acc.push(__graphql__args!(
117+
@apply_args,
118+
$reg,
119+
$reg.field_inside_result(
120+
&$crate::to_snake_case(stringify!($name)),
121+
Err("dummy".to_owned()) as $t)
122+
.deprecated($reason),
123+
$args));
124+
125+
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
126+
};
127+
128+
// field <name>(...) -> <type> as <description> { ... }
91129
(
92130
@gather_meta,
93131
$reg:expr, $acc:expr, $descr:expr,
@@ -105,6 +143,7 @@ macro_rules! graphql_interface {
105143
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
106144
};
107145

146+
// field <name>(...) -> <type> { ... }
108147
(
109148
@gather_meta,
110149
$reg:expr, $acc:expr, $descr:expr,
@@ -121,6 +160,7 @@ macro_rules! graphql_interface {
121160
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*);
122161
};
123162

163+
// description: <description>
124164
(
125165
@gather_meta,
126166
$reg:expr, $acc:expr, $descr:expr,
@@ -131,16 +171,36 @@ macro_rules! graphql_interface {
131171
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*)
132172
};
133173

174+
// instance_resolvers: | <ctxtvar> | [...]
134175
(
135176
@gather_meta,
136177
$reg:expr, $acc:expr, $descr:expr,
137-
instance_resolvers: | $execvar:pat | $resolvers:tt $( $rest:tt )*
178+
instance_resolvers: | $ctxtvar:pat | $resolvers:tt $( $rest:tt )*
138179
) => {
139180
graphql_interface!(@gather_meta, $reg, $acc, $descr, $( $rest )*)
140181
};
141182

142183
( @gather_meta, $reg:expr, $acc:expr, $descr:expr, $(,)* ) => {};
143184

185+
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
186+
(
187+
@resolve_into_type,
188+
$buildargs:tt,
189+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
190+
) => {
191+
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
192+
};
193+
194+
// field deprecated <reason> <name>(...) -> <type> { ... }
195+
(
196+
@resolve_into_type,
197+
$buildargs:tt,
198+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
199+
) => {
200+
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
201+
};
202+
203+
// field <name>(...) -> <type> as <description> { ... }
144204
(
145205
@resolve_into_type,
146206
$buildargs:tt,
@@ -149,6 +209,7 @@ macro_rules! graphql_interface {
149209
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
150210
};
151211

212+
// field <name>(...) -> <type> { ... }
152213
(
153214
@resolve_into_type,
154215
$buildargs:tt,
@@ -157,50 +218,59 @@ macro_rules! graphql_interface {
157218
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
158219
};
159220

221+
// description: <description>
160222
(
161223
@resolve_into_type,
162224
$buildargs:tt, description : $value:tt $( $rest:tt )*
163225
) => {
164226
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
165227
};
166228

229+
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
167230
(
168-
@resolve_into_type,
169-
$buildargs:tt, interfaces : $value:tt $( $rest:tt )*
231+
@concrete_type_name,
232+
$buildargs:tt,
233+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
170234
) => {
171-
graphql_interface!(@resolve_into_type, $buildargs, $( $rest )*)
235+
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
172236
};
173237

238+
// field deprecated <reason> <name>(...) -> <type> { ... }
174239
(
175240
@concrete_type_name,
176241
$buildargs:tt,
177-
field $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
242+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
178243
) => {
179244
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
180245
};
181246

247+
// field <name>(...) -> <type> as <description> { ... }
182248
(
183249
@concrete_type_name,
184250
$buildargs:tt,
185-
field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
251+
field $name:ident $args:tt -> $t:ty as $descr:tt $body:block $( $rest:tt )*
186252
) => {
187253
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
188254
};
189255

256+
// field <name>(...) -> <type> { ... }
190257
(
191258
@concrete_type_name,
192-
$buildargs:tt, description : $value:tt $( $rest:tt )*
259+
$buildargs:tt,
260+
field $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
193261
) => {
194262
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
195263
};
196264

265+
// description: <description>
197266
(
198267
@concrete_type_name,
199-
$buildargs:tt, interfaces : $value:tt $( $rest:tt )*
268+
$buildargs:tt, description : $value:tt $( $rest:tt )*
200269
) => {
201270
graphql_interface!(@concrete_type_name, $buildargs, $( $rest )*)
202271
};
203272

273+
// instance_resolvers: | <ctxtvar> | [...]
204274
(
205275
@concrete_type_name,
206276
($outname:tt, $ctxtarg:ident, $ctxttype:ty),
@@ -225,6 +295,7 @@ macro_rules! graphql_interface {
225295
()
226296
};
227297

298+
// instance_resolvers: | <ctxtvar> |
228299
(
229300
@resolve_into_type,
230301
($outname:tt, $typenamearg:ident, $execarg:ident, $ctxttype:ty),

src/macros/object.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,44 @@ macro_rules! graphql_object {
239239
( @as_item, $i:item) => { $i };
240240
( @as_expr, $e:expr) => { $e };
241241

242+
// field deprecated <reason> <name>(...) -> <type> as <description> { ... }
243+
(
244+
@gather_object_meta,
245+
$reg:expr, $acc:expr, $descr:expr, $ifaces:expr,
246+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty as $desc:tt $body:block $( $rest:tt )*
247+
) => {
248+
$acc.push(__graphql__args!(
249+
@apply_args,
250+
$reg,
251+
$reg.field_inside_result(
252+
&$crate::to_snake_case(stringify!($name)),
253+
Err("dummy".to_owned()) as $t)
254+
.description($desc)
255+
.deprecated($reason),
256+
$args));
257+
258+
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*);
259+
};
260+
261+
// field deprecated <reason> <name>(...) -> <type> { ... }
262+
(
263+
@gather_object_meta,
264+
$reg:expr, $acc:expr, $descr:expr, $ifaces:expr,
265+
field deprecated $reason:tt $name:ident $args:tt -> $t:ty $body:block $( $rest:tt )*
266+
) => {
267+
$acc.push(__graphql__args!(
268+
@apply_args,
269+
$reg,
270+
$reg.field_inside_result(
271+
&$crate::to_snake_case(stringify!($name)),
272+
Err("dummy".to_owned()) as $t)
273+
.deprecated($reason),
274+
$args));
275+
276+
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*);
277+
};
278+
279+
// field <name>(...) -> <type> as <description> { ... }
242280
(
243281
@gather_object_meta,
244282
$reg:expr, $acc:expr, $descr:expr, $ifaces:expr,
@@ -256,6 +294,7 @@ macro_rules! graphql_object {
256294
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*);
257295
};
258296

297+
// field <name>(...) -> <type> { ... }
259298
(
260299
@gather_object_meta,
261300
$reg:expr, $acc:expr, $descr:expr, $ifaces:expr,
@@ -272,6 +311,7 @@ macro_rules! graphql_object {
272311
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*);
273312
};
274313

314+
// description: <description>
275315
(
276316
@gather_object_meta,
277317
$reg:expr, $acc:expr, $descr:expr, $ifaces:expr,
@@ -282,6 +322,7 @@ macro_rules! graphql_object {
282322
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*)
283323
};
284324

325+
// interfaces: [...]
285326
(
286327
@gather_object_meta,
287328
$reg:expr, $acc:expr, $descr:expr, $ifaces:expr,
@@ -292,6 +333,7 @@ macro_rules! graphql_object {
292333
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*)
293334
};
294335

336+
// base case
295337
(
296338
@gather_object_meta,
297339
$reg:expr, $acc:expr, $descr:expr, $ifaces:expr, $(,)*

0 commit comments

Comments
 (0)