Skip to content

Commit 8dd2eaf

Browse files
theduketheduke
authored andcommitted
Add *Internal custom derive variants for juniper crate
Currently, custom derives inside the main juniper crate are supported by an ugly hack using the __juniper_use_everything macro. This commit adds new custom derive variants that are for main juniper crate internal use only (GraphQL{Enum,InputObject}Internal. All custom derives inside the juniper crate are refactored to use the new '*Internal' derives. This allows us to * remove the use_everything macro, * simplify the generated code for custom derives * support the Rust 2018 edition
1 parent 3f1ae66 commit 8dd2eaf

File tree

18 files changed

+129
-166
lines changed

18 files changed

+129
-166
lines changed

juniper/src/executor_tests/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use validation::RuleError;
77
use value::{DefaultScalarValue, Object, Value};
88
use GraphQLError::ValidationError;
99

10-
#[derive(GraphQLEnum, Debug)]
10+
#[derive(GraphQLEnumInternal, Debug)]
1111
enum Color {
1212
Red,
1313
Green,

juniper/src/executor_tests/introspection/enums.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,41 @@ Syntax to validate:
1515
1616
*/
1717

18-
#[derive(GraphQLEnum)]
18+
#[derive(GraphQLEnumInternal)]
1919
enum DefaultName {
2020
Foo,
2121
Bar,
2222
}
2323

24-
#[derive(GraphQLEnum)]
24+
#[derive(GraphQLEnumInternal)]
2525
#[graphql(name = "ANamedEnum")]
2626
enum Named {
2727
Foo,
2828
Bar,
2929
}
3030

31-
#[derive(GraphQLEnum)]
31+
#[derive(GraphQLEnumInternal)]
3232
enum NoTrailingComma {
3333
Foo,
3434
Bar,
3535
}
3636

37-
#[derive(GraphQLEnum)]
37+
#[derive(GraphQLEnumInternal)]
3838
#[graphql(description = "A description of the enum itself")]
3939
enum EnumDescription {
4040
Foo,
4141
Bar,
4242
}
4343

44-
#[derive(GraphQLEnum)]
44+
#[derive(GraphQLEnumInternal)]
4545
enum EnumValueDescription {
4646
#[graphql(description = "The FOO value")]
4747
Foo,
4848
#[graphql(description = "The BAR value")]
4949
Bar,
5050
}
5151

52-
#[derive(GraphQLEnum)]
52+
#[derive(GraphQLEnumInternal)]
5353
enum EnumDeprecation {
5454
#[graphql(deprecated = "Please don't use FOO any more")]
5555
Foo,

juniper/src/executor_tests/introspection/input_object.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,47 @@ use value::{DefaultScalarValue, Object, Value};
66

77
struct Root;
88

9-
#[derive(GraphQLInputObject)]
9+
#[derive(GraphQLInputObjectInternal)]
1010
struct DefaultName {
1111
field_one: String,
1212
field_two: String,
1313
}
1414

15-
#[derive(GraphQLInputObject)]
15+
#[derive(GraphQLInputObjectInternal)]
1616
struct NoTrailingComma {
1717
field_one: String,
1818
field_two: String,
1919
}
2020

21-
#[derive(GraphQLInputObject, Debug)]
21+
#[derive(GraphQLInputObjectInternal, Debug)]
2222
struct Derive {
2323
field_one: String,
2424
}
2525

26-
#[derive(GraphQLInputObject, Debug)]
26+
#[derive(GraphQLInputObjectInternal, Debug)]
2727
#[graphql(name = "ANamedInputObject")]
2828
struct Named {
2929
field_one: String,
3030
}
3131

32-
#[derive(GraphQLInputObject, Debug)]
32+
#[derive(GraphQLInputObjectInternal, Debug)]
3333
#[graphql(description = "Description for the input object")]
3434
struct Description {
3535
field_one: String,
3636
}
3737

38-
#[derive(GraphQLInputObject, Debug)]
38+
#[derive(GraphQLInputObjectInternal, Debug)]
3939
pub struct Public {
4040
field_one: String,
4141
}
4242

43-
#[derive(GraphQLInputObject, Debug)]
43+
#[derive(GraphQLInputObjectInternal, Debug)]
4444
#[graphql(description = "Description for the input object")]
4545
pub struct PublicWithDescription {
4646
field_one: String,
4747
}
4848

49-
#[derive(GraphQLInputObject, Debug)]
49+
#[derive(GraphQLInputObjectInternal, Debug)]
5050
#[graphql(
5151
name = "APublicNamedInputObjectWithDescription",
5252
description = "Description for the input object",
@@ -55,21 +55,21 @@ pub struct NamedPublicWithDescription {
5555
field_one: String,
5656
}
5757

58-
#[derive(GraphQLInputObject, Debug)]
58+
#[derive(GraphQLInputObjectInternal, Debug)]
5959
#[graphql(name = "APublicNamedInputObject")]
6060
pub struct NamedPublic {
6161
field_one: String,
6262
}
6363

64-
#[derive(GraphQLInputObject, Debug)]
64+
#[derive(GraphQLInputObjectInternal, Debug)]
6565
struct FieldDescription {
6666
#[graphql(description = "The first field")]
6767
field_one: String,
6868
#[graphql(description = "The second field")]
6969
field_two: String,
7070
}
7171

72-
#[derive(GraphQLInputObject, Debug)]
72+
#[derive(GraphQLInputObjectInternal, Debug)]
7373
struct FieldWithDefaults {
7474
#[graphql(default = "123")]
7575
field_one: i32,

juniper/src/executor_tests/introspection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use schema::model::RootNode;
1010
use types::scalars::EmptyMutation;
1111
use value::{ParseScalarResult, ParseScalarValue, Value};
1212

13-
#[derive(GraphQLEnum)]
13+
#[derive(GraphQLEnumInternal)]
1414
#[graphql(name = "SampleEnum")]
1515
enum Sample {
1616
One,

juniper/src/executor_tests/variables.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ graphql_scalar!(TestComplexScalar {
3232
}
3333
});
3434

35-
#[derive(GraphQLInputObject, Debug)]
35+
#[derive(GraphQLInputObjectInternal, Debug)]
3636
#[graphql(scalar = "DefaultScalarValue")]
3737
struct TestInputObject {
3838
a: Option<String>,
@@ -41,20 +41,20 @@ struct TestInputObject {
4141
d: Option<TestComplexScalar>,
4242
}
4343

44-
#[derive(GraphQLInputObject, Debug)]
44+
#[derive(GraphQLInputObjectInternal, Debug)]
4545
#[graphql(scalar = "DefaultScalarValue")]
4646
struct TestNestedInputObject {
4747
na: TestInputObject,
4848
nb: String,
4949
}
5050

51-
#[derive(GraphQLInputObject, Debug)]
51+
#[derive(GraphQLInputObjectInternal, Debug)]
5252
struct ExampleInputObject {
5353
a: Option<String>,
5454
b: i32,
5555
}
5656

57-
#[derive(GraphQLInputObject, Debug)]
57+
#[derive(GraphQLInputObjectInternal, Debug)]
5858
struct InputWithDefaults {
5959
#[graphql(default = "123")]
6060
a: i32,

juniper/src/lib.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,6 @@ extern crate juniper_codegen;
121121
#[doc(hidden)]
122122
pub use juniper_codegen::*;
123123

124-
// This macro is used as abstraction to make custom derives work
125-
// in juniper itself and outside of juniper
126-
// This macro needs to be here because it is used a derive in value::scalar
127-
// The tests in macros are using a macro from the value module, and because
128-
// rust macros needs to be defined before they are used it would cause problems
129-
// to move this macro somewhere else.
130-
#[macro_export]
131-
#[doc(hidden)]
132-
macro_rules! __juniper_use_everything {
133-
() => {
134-
pub use $crate::*;
135-
};
136-
}
137-
138124
#[macro_use]
139125
mod value;
140126
#[macro_use]

juniper/src/macros/tests/args.rs

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

22-
#[derive(GraphQLInputObject)]
22+
#[derive(GraphQLInputObjectInternal)]
2323
struct Point {
2424
x: i32,
2525
}

juniper/src/parser/tests/value.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use schema::meta::{MetaType, ScalarMeta, EnumMeta, EnumValue, InputObjectMeta, A
99
use schema::model::SchemaType;
1010
use types::scalars::EmptyMutation;
1111

12-
#[derive(GraphQLEnum)]
12+
#[derive(GraphQLEnumInternal)]
1313
enum Enum {
1414
EnumValue
1515
}
1616

17-
#[derive(GraphQLInputObject)]
17+
#[derive(GraphQLInputObjectInternal)]
1818
struct Bar {
1919
foo: String,
2020
}
2121

22-
#[derive(GraphQLInputObject)]
22+
#[derive(GraphQLInputObjectInternal)]
2323
struct Foo {
2424
key: i32,
2525
other: Bar,

juniper/src/schema/model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct DirectiveType<'a, S> {
5757
pub arguments: Vec<Argument<'a, S>>,
5858
}
5959

60-
#[derive(Clone, PartialEq, Eq, Debug, GraphQLEnum)]
60+
#[derive(Clone, PartialEq, Eq, Debug, GraphQLEnumInternal)]
6161
#[graphql(name = "__DirectiveLocation")]
6262
pub enum DirectiveLocation {
6363
Query,

juniper/src/tests/model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::collections::HashMap;
44

5-
#[derive(GraphQLEnum, Copy, Clone, Eq, PartialEq, Debug)]
5+
#[derive(GraphQLEnumInternal, Copy, Clone, Eq, PartialEq, Debug)]
66
pub enum Episode {
77
#[graphql(name = "NEW_HOPE")]
88
NewHope,

0 commit comments

Comments
 (0)