Skip to content

Commit 3472fe6

Browse files
authored
Fix attributes naming on fields and arguments for interfaces and unions (#806)
Additionally: - revive macros/tests/object - revive executor_tests/interfaces_unions
1 parent bcbf44e commit 3472fe6

File tree

21 files changed

+212
-343
lines changed

21 files changed

+212
-343
lines changed

docs/book/content/types/interfaces.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ use juniper::{graphql_interface, GraphQLObject};
167167
trait Character {
168168
fn id(&self) -> &str;
169169

170-
#[graphql_interface(ignore)] // or `#[graphql_interface(skip)]`, your choice
170+
#[graphql(ignore)] // or `#[graphql(skip)]`, your choice
171171
fn ignored(&self) -> u32 { 0 }
172172
}
173173

@@ -205,26 +205,26 @@ use juniper::graphql_interface;
205205
/// This doc is absent in GraphQL schema.
206206
trait Character {
207207
// Renames the field in GraphQL schema.
208-
#[graphql_interface(name = "myId")]
208+
#[graphql(name = "myId")]
209209
// Deprecates the field in GraphQL schema.
210210
// Usual Rust `#[deprecated]` attribute is supported too as field deprecation,
211211
// but `deprecated` attribute argument takes precedence over it, if specified.
212-
#[graphql_interface(deprecated = "Do not use it.")]
212+
#[graphql(deprecated = "Do not use it.")]
213213
// Describes the field in GraphQL schema.
214-
#[graphql_interface(description = "ID of my own character.")]
214+
#[graphql(description = "ID of my own character.")]
215215
// Usual Rust docs are supported too as field description,
216216
// but `description` attribute argument takes precedence over them, if specified.
217217
/// This description is absent in GraphQL schema.
218218
fn id(
219219
&self,
220220
// Renames the argument in GraphQL schema.
221-
#[graphql_interface(name = "myNum")]
221+
#[graphql(name = "myNum")]
222222
// Describes the argument in GraphQL schema.
223-
#[graphql_interface(description = "ID number of my own character.")]
223+
#[graphql(description = "ID number of my own character.")]
224224
// Specifies the default value for the argument.
225225
// The concrete value may be omitted, and the `Default::default` one
226226
// will be used in such case.
227-
#[graphql_interface(default = 5)]
227+
#[graphql(default = 5)]
228228
num: i32,
229229
) -> &str;
230230
}
@@ -254,7 +254,7 @@ trait Character { // while still can be specified via `Context =
254254
fn id(&self, context: &Database) -> Option<&str>;
255255

256256
// Otherwise, you may mark it explicitly as a context argument.
257-
fn name(&self, #[graphql_interface(context)] db: &Database) -> Option<&str>;
257+
fn name(&self, #[graphql(context)] db: &Database) -> Option<&str>;
258258
}
259259

260260
#[derive(GraphQLObject)]
@@ -307,7 +307,7 @@ trait Character<S: ScalarValue> {
307307
// Otherwise, you may mark it explicitly as an executor argument.
308308
async fn name<'b>(
309309
&'b self,
310-
#[graphql_interface(executor)] another: &Executor<'_, '_, (), S>,
310+
#[graphql(executor)] another: &Executor<'_, '_, (), S>,
311311
) -> &'b str
312312
where
313313
S: Send + Sync;
@@ -319,7 +319,7 @@ struct Human {
319319
id: String,
320320
name: String,
321321
}
322-
#[graphql_interface(Scalar = S)]
322+
#[graphql_interface(scalar = S)]
323323
impl<S: ScalarValue> Character<S> for Human {
324324
async fn id<'a>(&self, executor: &'a Executor<'_, '_, (), S>) -> &'a str
325325
where
@@ -356,12 +356,12 @@ struct Database {
356356
}
357357
impl juniper::Context for Database {}
358358

359-
#[graphql_interface(for = [Human, Droid], Context = Database)]
359+
#[graphql_interface(for = [Human, Droid], context = Database)]
360360
#[graphql_interface(on Droid = get_droid)] // enables downcasting `Droid` via `get_droid()` function
361361
trait Character {
362362
fn id(&self) -> &str;
363363

364-
#[graphql_interface(downcast)] // makes method a downcast to `Human`, not a field
364+
#[graphql(downcast)] // makes method a downcast to `Human`, not a field
365365
// NOTICE: The method signature may optionally contain `&Database` context argument.
366366
fn as_human(&self) -> Option<&Human> {
367367
None
@@ -419,7 +419,7 @@ By default, `#[graphql_interface]` macro generates code, which is generic over a
419419
use juniper::{graphql_interface, DefaultScalarValue, GraphQLObject};
420420

421421
#[graphql_interface(for = [Human, Droid])]
422-
#[graphql_interface(Scalar = DefaultScalarValue)] // removing this line will fail compilation
422+
#[graphql_interface(scalar = DefaultScalarValue)] // removing this line will fail compilation
423423
trait Character {
424424
fn id(&self) -> &str;
425425
}
@@ -430,7 +430,7 @@ struct Human {
430430
id: String,
431431
home_planet: String,
432432
}
433-
#[graphql_interface(Scalar = DefaultScalarValue)]
433+
#[graphql_interface(scalar = DefaultScalarValue)]
434434
impl Character for Human {
435435
fn id(&self) -> &str {
436436
&self.id
@@ -443,7 +443,7 @@ struct Droid {
443443
id: String,
444444
primary_function: String,
445445
}
446-
#[graphql_interface(Scalar = DefaultScalarValue)]
446+
#[graphql_interface(scalar = DefaultScalarValue)]
447447
impl Character for Droid {
448448
fn id(&self) -> &str {
449449
&self.id

docs/book/content/types/unions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ struct Database {
316316
}
317317
impl juniper::Context for Database {}
318318

319-
#[graphql_union(Context = Database)]
319+
#[graphql_union(context = Database)]
320320
trait Character {
321321
// NOTICE: The method signature may optionally contain `&Context`.
322322
fn as_human<'db>(&self, ctx: &'db Database) -> Option<&'db Human> { None }
@@ -363,7 +363,7 @@ struct Droid {
363363
trait Character {
364364
fn as_human(&self) -> Option<&Human> { None }
365365
fn as_droid(&self) -> Option<&Droid> { None }
366-
#[graphql_union(ignore)] // or `#[graphql_union(skip)]`, your choice
366+
#[graphql(ignore)] // or `#[graphql(skip)]`, your choice
367367
fn id(&self) -> &str;
368368
}
369369

@@ -410,13 +410,13 @@ struct Database {
410410
}
411411
impl juniper::Context for Database {}
412412

413-
#[graphql_union(Context = Database)]
413+
#[graphql_union(context = Database)]
414414
#[graphql_union(
415415
on Human = DynCharacter::get_human,
416416
on Droid = get_droid,
417417
)]
418418
trait Character {
419-
#[graphql_union(ignore)] // or `#[graphql_union(skip)]`, your choice
419+
#[graphql(ignore)] // or `#[graphql(skip)]`, your choice
420420
fn id(&self) -> &str;
421421
}
422422

integration_tests/codegen_fail/fail/interface/downcast_method_conflicts_with_external_downcast_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Character for ObjA {
2222
trait Character {
2323
fn id(&self, num: i32) -> &str;
2424

25-
#[graphql_interface(downcast)]
25+
#[graphql(downcast)]
2626
fn as_obja(&self) -> Option<&ObjA>;
2727
}
2828

integration_tests/codegen_fail/fail/interface/downcast_method_conflicts_with_external_downcast_fn.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error: GraphQL interface trait method `as_obja` conflicts with the external down
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: https://spec.graphql.org/June2018/#sec-Interfaces
8-
= note: use `#[graphql_interface(ignore)]` attribute argument to ignore this trait method for interface implementers downcasting
8+
= note: use `#[graphql(ignore)]` attribute argument to ignore this trait method for interface implementers downcasting
99

1010
error[E0412]: cannot find type `CharacterValue` in this scope
1111
--> $DIR/downcast_method_conflicts_with_external_downcast_fn.rs:4:18

integration_tests/codegen_fail/fail/interface/downcast_method_wrong_input_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait Character {
66
0
77
}
88

9-
#[graphql_interface(downcast)]
9+
#[graphql(downcast)]
1010
fn a(&self, ctx: &(), rand: u8) -> Option<&Human> {
1111
None
1212
}

integration_tests/codegen_fail/fail/interface/downcast_method_wrong_return_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait Character {
66
0
77
}
88

9-
#[graphql_interface(downcast)]
9+
#[graphql(downcast)]
1010
fn a(&self, ctx: &(), rand: u8) -> &Human {
1111
unimplemented!()
1212
}

integration_tests/codegen_fail/fail/interface/fields_duplicate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait Character {
1515
"funA"
1616
}
1717

18-
#[graphql_interface(name = "id")]
18+
#[graphql(name = "id")]
1919
fn id2(&self) -> &str {
2020
"funB"
2121
}

integration_tests/codegen_fail/fail/union/trait_method_conflicts_with_external_resolver_fn.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ error: GraphQL union trait method `a` conflicts with the external resolver funct
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: https://spec.graphql.org/June2018/#sec-Unions
8-
= note: use `#[graphql_union(ignore)]` attribute to ignore this trait method for union variants resolution
8+
= note: use `#[graphql(ignore)]` attribute to ignore this trait method for union variants resolution

integration_tests/codegen_fail/fail/union/trait_with_attr_on_method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use juniper::{graphql_union, GraphQLObject};
22

33
#[graphql_union]
44
trait Character {
5-
#[graphql_union(with = something)]
5+
#[graphql(with = something)]
66
fn a(&self) -> Option<&Human>;
77
}
88

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: GraphQL union cannot use #[graphql_union(with = ...)] attribute on a trait method
2-
--> $DIR/trait_with_attr_on_method.rs:5:21
1+
error: GraphQL union cannot use #[graphql(with = ...)] attribute on a trait method
2+
--> $DIR/trait_with_attr_on_method.rs:5:15
33
|
4-
5 | #[graphql_union(with = something)]
5-
| ^^^^
4+
5 | #[graphql(with = something)]
5+
| ^^^^
66
|
77
= note: https://spec.graphql.org/June2018/#sec-Unions
8-
= note: instead use #[graphql_union(ignore)] on the method with #[graphql_union(on ... = ...)] on the trait itself
8+
= note: instead use #[graphql(ignore)] on the method with #[graphql_union(on ... = ...)] on the trait itself

0 commit comments

Comments
 (0)