Skip to content

Commit ba7839f

Browse files
committed
Use object shorthand in tests and documentation
1 parent 2b1c9cf commit ba7839f

File tree

12 files changed

+47
-47
lines changed

12 files changed

+47
-47
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ graphql_enum!(Episode {
7272
Episode::Jedi => "JEDI",
7373
});
7474

75-
graphql_object!(Human: () as "Human" |&self| {
75+
graphql_object!(Human: () |&self| {
7676
description: "A humanoid creature in the Star Wars universe"
7777

7878
// Field resolver methods look almost like ordinary methods. The macro picks

src/executor_tests/introspection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| {
4141
}
4242
});
4343

44-
graphql_object!(Root: () as "Root" |&self| {
44+
graphql_object!(Root: () |&self| {
4545
description: "The root query object in the schema"
4646

4747
interfaces: [Interface]

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct Database { users: HashMap<String, User> }
4343
// object to provide e.g. database access to the field accessors.
4444
//
4545
// In this example, we use the Database struct as our context.
46-
graphql_object!(User: Database as "User" |&self| {
46+
graphql_object!(User: Database |&self| {
4747
4848
// Expose a simple field as a GraphQL string.
4949
field id() -> &String {
@@ -76,7 +76,7 @@ graphql_object!(User: Database as "User" |&self| {
7676
7777
// The context object is passed down to all referenced types - all your exposed
7878
// types need to have the same context type.
79-
graphql_object!(QueryRoot: Database as "Query" |&self| {
79+
graphql_object!(QueryRoot: Database |&self| {
8080
8181
// Arguments work just like they do on functions.
8282
field user(&mut executor, id: String) -> Option<&User> {
@@ -112,7 +112,7 @@ use juniper::iron_handlers::GraphQLHandler;
112112
# struct QueryRoot;
113113
# struct Database { users: HashMap<String, User> }
114114
#
115-
# graphql_object!(User: Database as "User" |&self| {
115+
# graphql_object!(User: Database |&self| {
116116
# field id() -> FieldResult<&String> {
117117
# Ok(&self.id)
118118
# }
@@ -128,7 +128,7 @@ use juniper::iron_handlers::GraphQLHandler;
128128
# }
129129
# });
130130
#
131-
# graphql_object!(QueryRoot: Database as "Query" |&self| {
131+
# graphql_object!(QueryRoot: Database |&self| {
132132
# field user(&mut executor, id: String) -> FieldResult<Option<&User>> {
133133
# Ok(executor.context().users.get(&id))
134134
# }

src/macros/object.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The simplest case exposes fields on a struct:
1313
# #[macro_use] extern crate juniper;
1414
struct User { id: String, name: String, group_ids: Vec<String> }
1515
16-
graphql_object!(User: () as "User" |&self| {
16+
graphql_object!(User: () |&self| {
1717
field id() -> &String {
1818
&self.id
1919
}
@@ -42,7 +42,7 @@ arguments:
4242
# #[macro_use] extern crate juniper;
4343
struct User { id: String, name: String, group_ids: Vec<String> }
4444
45-
graphql_object!(User: () as "User" |&self| {
45+
graphql_object!(User: () |&self| {
4646
description: "A user in the database"
4747
4848
field id() -> &String as "The user's unique identifier" {
@@ -105,7 +105,7 @@ graphql_interface!(<'a> &'a Interface: () as "Interface" |&self| {
105105
}
106106
});
107107
108-
graphql_object!(Implementor: () as "Implementor" |&self| {
108+
graphql_object!(Implementor: () |&self| {
109109
field id() -> &str { &self.id }
110110
111111
interfaces: [&Interface]
@@ -130,7 +130,7 @@ continue executing despite some fields failing.
130130
# use juniper::FieldResult;
131131
struct User { id: String }
132132
133-
graphql_object!(User: () as "User" |&self| {
133+
graphql_object!(User: () |&self| {
134134
field id() -> FieldResult<&String> {
135135
Ok(&self.id)
136136
}

src/macros/tests/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Syntax to validate:
1818
1919
*/
2020

21-
graphql_object!(Root: () as "Root" |&self| {
21+
graphql_object!(Root: () |&self| {
2222
field simple() -> i64 { 0 }
2323
field exec_arg(&mut executor) -> i64 { 0 }
2424
field exec_arg_and_more(&mut executor, arg: i64) -> i64 { 0 }

src/macros/tests/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ graphql_enum!(EnumDeprecation {
5757
EnumDeprecation::Bar => "BAR" as "The BAR value" deprecated "Please don't use BAR any more",
5858
});
5959

60-
graphql_object!(Root: () as "Root" |&self| {
60+
graphql_object!(Root: () |&self| {
6161
field default_name() -> DefaultName { DefaultName::Foo }
6262
field named() -> Named { Named::Foo }
6363
field no_trailing_comma() -> NoTrailingComma { NoTrailingComma::Foo }

src/macros/tests/field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Syntax to validate:
1717
1818
*/
1919

20-
graphql_object!(Root: () as "Root" |&self| {
20+
graphql_object!(Root: () |&self| {
2121
field simple() -> i64 { 0 }
2222

2323
field description() -> i64 as "Field description" { 0 }
@@ -31,7 +31,7 @@ graphql_object!(Root: () as "Root" |&self| {
3131
interfaces: [Interface]
3232
});
3333

34-
graphql_interface!(Interface: () as "Interface" |&self| {
34+
graphql_interface!(Interface: () |&self| {
3535
field simple() -> i64 { 0 }
3636

3737
field description() -> i64 as "Field description" { 0 }

src/macros/tests/input_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ graphql_input_object!(
4848
}
4949
);
5050

51-
graphql_object!(Root: () as "Root" |&self| {
51+
graphql_object!(Root: () |&self| {
5252
field test_field(
5353
a1: DefaultName,
5454
a2: NoTrailingComma,

src/macros/tests/interface.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Syntax to validate:
1919

2020
struct Concrete;
2121

22-
struct DefaultName;
22+
struct CustomName;
2323

2424
#[allow(dead_code)]
2525
struct WithLifetime<'a> { data: PhantomData<&'a i64> }
@@ -42,7 +42,7 @@ graphql_object!(Concrete: () |&self| {
4242
field simple() -> i64 { 0 }
4343
});
4444

45-
graphql_interface!(DefaultName: () |&self| {
45+
graphql_interface!(CustomName: () as "ACustomNamedInterface" |&self| {
4646
field simple() -> i64 { 0 }
4747

4848
instance_resolvers: |_| { Concrete => Some(Concrete) }
@@ -60,31 +60,31 @@ graphql_interface!(<T> WithGenerics<T>: () as "WithGenerics" |&self| {
6060
});
6161

6262

63-
graphql_interface!(DescriptionFirst: () as "DescriptionFirst" |&self| {
63+
graphql_interface!(DescriptionFirst: () |&self| {
6464
description: "A description"
6565

6666
field simple() -> i64 { 0 }
6767

6868
instance_resolvers: |_| { Concrete => Some(Concrete) }
6969
});
7070

71-
graphql_interface!(FieldsFirst: () as "FieldsFirst" |&self| {
71+
graphql_interface!(FieldsFirst: () |&self| {
7272
field simple() -> i64 { 0 }
7373

7474
description: "A description"
7575

7676
instance_resolvers: |_| { Concrete => Some(Concrete) }
7777
});
7878

79-
graphql_interface!(InterfacesFirst: () as "InterfacesFirst" |&self| {
79+
graphql_interface!(InterfacesFirst: () |&self| {
8080
instance_resolvers: |_| { Concrete => Some(Concrete) }
8181

8282
field simple() -> i64 { 0 }
8383

8484
description: "A description"
8585
});
8686

87-
graphql_interface!(CommasWithTrailing: () as "CommasWithTrailing" |&self| {
87+
graphql_interface!(CommasWithTrailing: () |&self| {
8888
instance_resolvers: |_| { Concrete => Some(Concrete) },
8989

9090
field simple() -> i64 { 0 },
@@ -93,23 +93,23 @@ graphql_interface!(CommasWithTrailing: () as "CommasWithTrailing" |&self| {
9393
});
9494

9595

96-
graphql_interface!(CommasOnMeta: () as "CommasOnMeta" |&self| {
96+
graphql_interface!(CommasOnMeta: () |&self| {
9797
instance_resolvers: |_| { Concrete => Some(Concrete) }
9898
description: "A description",
9999

100100
field simple() -> i64 { 0 }
101101
});
102102

103103

104-
graphql_interface!(ResolversWithTrailingComma: () as "ResolversWithTrailingComma" |&self| {
104+
graphql_interface!(ResolversWithTrailingComma: () |&self| {
105105
instance_resolvers: |_| { Concrete => Some(Concrete), }
106106
description: "A description",
107107

108108
field simple() -> i64 { 0 }
109109
});
110110

111111
graphql_object!(<'a> Root: () as "Root" |&self| {
112-
field default_name() -> DefaultName { DefaultName {} }
112+
field custom_name() -> CustomName { CustomName {} }
113113

114114
field with_lifetime() -> WithLifetime<'a> { WithLifetime { data: PhantomData } }
115115
field with_generics() -> WithGenerics<i64> { WithGenerics { data: 123 } }
@@ -167,9 +167,9 @@ fn run_type_info_query<F>(type_name: &str, f: F)
167167
}
168168

169169
#[test]
170-
fn introspect_default_name() {
171-
run_type_info_query("DefaultName", |object, fields| {
172-
assert_eq!(object.get("name"), Some(&Value::string("DefaultName")));
170+
fn introspect_custom_name() {
171+
run_type_info_query("ACustomNamedInterface", |object, fields| {
172+
assert_eq!(object.get("name"), Some(&Value::string("ACustomNamedInterface")));
173173
assert_eq!(object.get("description"), Some(&Value::null()));
174174

175175
assert!(fields.contains(&Value::object(vec![

src/macros/tests/object.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Syntax to validate:
1818

1919
struct Interface;
2020

21-
struct DefaultName;
21+
struct CustomName;
2222

2323
#[allow(dead_code)]
2424
struct WithLifetime<'a> { data: PhantomData<&'a i64> }
@@ -35,7 +35,7 @@ struct CommasOnMeta;
3535

3636
struct Root;
3737

38-
graphql_object!(DefaultName: () |&self| {
38+
graphql_object!(CustomName: () as "ACustomNamedType" |&self| {
3939
field simple() -> i64 { 0 }
4040
});
4141

@@ -49,39 +49,39 @@ graphql_object!(<T> WithGenerics<T>: () as "WithGenerics" |&self| {
4949
});
5050

5151

52-
graphql_interface!(Interface: () as "Interface" |&self| {
52+
graphql_interface!(Interface: () |&self| {
5353
field simple() -> i64 { 0 }
5454

5555
instance_resolvers: |_| {
5656
DescriptionFirst => Some(DescriptionFirst {}),
5757
}
5858
});
5959

60-
graphql_object!(DescriptionFirst: () as "DescriptionFirst" |&self| {
60+
graphql_object!(DescriptionFirst: () |&self| {
6161
description: "A description"
6262

6363
field simple() -> i64 { 0 }
6464

6565
interfaces: [Interface]
6666
});
6767

68-
graphql_object!(FieldsFirst: () as "FieldsFirst" |&self| {
68+
graphql_object!(FieldsFirst: () |&self| {
6969
field simple() -> i64 { 0 }
7070

7171
description: "A description"
7272

7373
interfaces: [Interface]
7474
});
7575

76-
graphql_object!(InterfacesFirst: () as "InterfacesFirst" |&self| {
76+
graphql_object!(InterfacesFirst: ()|&self| {
7777
interfaces: [Interface]
7878

7979
field simple() -> i64 { 0 }
8080

8181
description: "A description"
8282
});
8383

84-
graphql_object!(CommasWithTrailing: () as "CommasWithTrailing" |&self| {
84+
graphql_object!(CommasWithTrailing: () |&self| {
8585
interfaces: [Interface],
8686

8787
field simple() -> i64 { 0 },
@@ -90,15 +90,15 @@ graphql_object!(CommasWithTrailing: () as "CommasWithTrailing" |&self| {
9090
});
9191

9292

93-
graphql_object!(CommasOnMeta: () as "CommasOnMeta" |&self| {
93+
graphql_object!(CommasOnMeta: () |&self| {
9494
interfaces: [Interface],
9595
description: "A description",
9696

9797
field simple() -> i64 { 0 }
9898
});
9999

100100
graphql_object!(<'a> Root: () as "Root" |&self| {
101-
field default_name() -> DefaultName { DefaultName {} }
101+
field custom_name() -> CustomName { CustomName {} }
102102

103103
field with_lifetime() -> WithLifetime<'a> { WithLifetime { data: PhantomData } }
104104
field with_generics() -> WithGenerics<i64> { WithGenerics { data: 123 } }
@@ -155,9 +155,9 @@ fn run_type_info_query<F>(type_name: &str, f: F)
155155
}
156156

157157
#[test]
158-
fn introspect_default_name() {
159-
run_type_info_query("DefaultName", |object, fields| {
160-
assert_eq!(object.get("name"), Some(&Value::string("DefaultName")));
158+
fn introspect_custom_name() {
159+
run_type_info_query("ACustomNamedType", |object, fields| {
160+
assert_eq!(object.get("name"), Some(&Value::string("ACustomNamedType")));
161161
assert_eq!(object.get("description"), Some(&Value::null()));
162162
assert_eq!(object.get("interfaces"), Some(&Value::list(vec![])));
163163

0 commit comments

Comments
 (0)