-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure Specification(June 2018) Compliance (#631)
* Implemented most test cases from the specification * Unified error handling for all generators - Removed proc-macro-error -> not required -> use syn::Error - Everything below lib.rs uses proc_macro2::TokenStream instead of proc_macro::TokenStream - Replaced error handling in attribute parsers * WIP better error messages for *all* macros * Refactored GraphQLInputObject and minor tweaks - removed support for Scalar within a string ("DefaultScalarValue") - removed unraw function and replaced it with the built-in one - added error messages and return types for all functions within utils - added more constraints to fulfill the GraphQL spec * Fixed test-cases which are not compliant with the specification * Removed unused function * Added constrains, updated error messages, added marker * Added argument rename within impl_graphql and fixed `__` tests * Formatted and cleanup * Added GraphQLTypeAsync for input object * Moved codegen tests to separate module Nightly and stable produce different outputs, thus only test nightly. * Added IsInputType/IsOutputType traits for type checking Co-authored-by: Christian Legnitto <[email protected]>
- Loading branch information
Showing
77 changed files
with
2,589 additions
and
1,023 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "juniper_codegen_tests" | ||
version = "0.1.0" | ||
publish = false | ||
edition = "2018" | ||
|
||
[dependencies] | ||
juniper = { path = "../../juniper" } | ||
futures = "0.3.1" | ||
|
||
[dev-dependencies] | ||
serde_json = { version = "1" } | ||
tokio = { version = "0.2", features = ["rt-core", "time", "macros"] } | ||
trybuild = "1.0.25" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[tasks.release] | ||
disabled = true | ||
[tasks.release-some] | ||
disabled = true | ||
[tasks.release-local-test] | ||
disabled = true | ||
[tasks.release-some-local-test] | ||
disabled = true | ||
[tasks.release-dry-run] | ||
disabled = true | ||
[tasks.release-some-dry-run] | ||
disabled = true | ||
|
||
[tasks.test] | ||
condition = { channels = ["nightly"] } | ||
[tasks.test-custom] | ||
condition = { channels = ["nightly"] } | ||
[tasks.test-flow] | ||
condition = { channels = ["nightly"] } | ||
[tasks.test-multi-flow-phase] | ||
condition = { channels = ["nightly"] } | ||
[tasks.test-thread-safe] | ||
condition = { channels = ["nightly"] } | ||
[tasks.test-verbose] | ||
condition = { channels = ["nightly"] } | ||
[tasks.test-with-args] | ||
condition = { channels = ["nightly"] } | ||
[tasks.ci-coverage-flow] | ||
condition = { channels = ["nightly"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[derive(juniper::GraphQLEnum)] | ||
pub enum Test {} | ||
|
||
fn main() { } |
7 changes: 7 additions & 0 deletions
7
integration_tests/codegen_fail/fail/enum/derive_no_fields.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: GraphQL enum expects at least one field | ||
--> $DIR/derive_no_fields.rs:2:1 | ||
| | ||
2 | pub enum Test {} | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: https://spec.graphql.org/June2018/#sec-Enums |
11 changes: 11 additions & 0 deletions
11
integration_tests/codegen_fail/fail/input-object/derive_incompatible_object.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#[derive(juniper::GraphQLObject)] | ||
struct ObjectA { | ||
test: String, | ||
} | ||
|
||
#[derive(juniper::GraphQLInputObject)] | ||
struct Object { | ||
field: ObjectA, | ||
} | ||
|
||
fn main() {} |
30 changes: 30 additions & 0 deletions
30
integration_tests/codegen_fail/fail/input-object/derive_incompatible_object.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error[E0277]: the trait bound `ObjectA: juniper::ast::FromInputValue<__S>` is not satisfied | ||
--> $DIR/derive_incompatible_object.rs:6:10 | ||
| | ||
6 | #[derive(juniper::GraphQLInputObject)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `juniper::ast::FromInputValue<__S>` is not implemented for `ObjectA` | ||
| | ||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `ObjectA: juniper::ast::FromInputValue<__S>` is not satisfied | ||
--> $DIR/derive_incompatible_object.rs:6:10 | ||
| | ||
6 | #[derive(juniper::GraphQLInputObject)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `juniper::ast::FromInputValue<__S>` is not implemented for `ObjectA` | ||
| | ||
= note: required by `juniper::ast::FromInputValue::from_input_value` | ||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0599]: no method named `to_input_value` found for struct `ObjectA` in the current scope | ||
--> $DIR/derive_incompatible_object.rs:6:10 | ||
| | ||
2 | struct ObjectA { | ||
| -------------- method `to_input_value` not found for this | ||
... | ||
6 | #[derive(juniper::GraphQLInputObject)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `ObjectA` | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
= note: the following trait defines an item `to_input_value`, perhaps you need to implement it: | ||
candidate #1: `juniper::ast::ToInputValue` | ||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) |
4 changes: 4 additions & 0 deletions
4
integration_tests/codegen_fail/fail/input-object/derive_no_fields.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[derive(juniper::GraphQLInputObject)] | ||
struct Object {} | ||
|
||
fn main() {} |
7 changes: 7 additions & 0 deletions
7
integration_tests/codegen_fail/fail/input-object/derive_no_fields.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: GraphQL input object expects at least one field | ||
--> $DIR/derive_no_fields.rs:2:1 | ||
| | ||
2 | struct Object {} | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: https://spec.graphql.org/June2018/#sec-Input-Objects |
7 changes: 7 additions & 0 deletions
7
integration_tests/codegen_fail/fail/input-object/derive_no_underscore.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#[derive(juniper::GraphQLInputObject)] | ||
struct Object { | ||
#[graphql(name = "__test")] | ||
test: String, | ||
} | ||
|
||
fn main() {} |
7 changes: 7 additions & 0 deletions
7
integration_tests/codegen_fail/fail/input-object/derive_no_underscore.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: All types and directives defined within a schema must not have a name which begins with `__` (two underscores), as this is used exclusively by GraphQL’s introspection system. | ||
--> $DIR/derive_no_underscore.rs:3:15 | ||
| | ||
3 | #[graphql(name = "__test")] | ||
| ^^^^ | ||
| | ||
= note: https://spec.graphql.org/June2018/#sec-Schema |
8 changes: 8 additions & 0 deletions
8
integration_tests/codegen_fail/fail/input-object/derive_unique_name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[derive(juniper::GraphQLInputObject)] | ||
struct Object { | ||
test: String, | ||
#[graphql(name = "test")] | ||
test2: String, | ||
} | ||
|
||
fn main() {} |
9 changes: 9 additions & 0 deletions
9
integration_tests/codegen_fail/fail/input-object/derive_unique_name.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error: GraphQL input object does not allow fields with the same name | ||
--> $DIR/derive_unique_name.rs:4:5 | ||
| | ||
4 | / #[graphql(name = "test")] | ||
5 | | test2: String, | ||
| |_________________^ | ||
| | ||
= help: There is at least one other field with the same name `test`, possibly renamed via the #[graphql] attribute | ||
= note: https://spec.graphql.org/June2018/#sec-Input-Objects |
23 changes: 23 additions & 0 deletions
23
integration_tests/codegen_fail/fail/interface/impl_argument_no_object.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[derive(juniper::GraphQLObject)] | ||
#[graphql(scalar = juniper::DefaultScalarValue)] | ||
pub struct ObjA { | ||
test: String, | ||
} | ||
|
||
enum Character { | ||
A(ObjA), | ||
} | ||
|
||
juniper::graphql_interface!(Character: () where Scalar = juniper::DefaultScalarValue |&self| { | ||
field id(__test: ObjA) -> &str { | ||
match *self { | ||
Character::A(_) => "funA", | ||
} | ||
} | ||
|
||
instance_resolvers: |_| { | ||
&ObjA => match *self { Character::A(ref h) => Some(h) }, | ||
} | ||
}); | ||
|
||
fn main() {} |
27 changes: 27 additions & 0 deletions
27
integration_tests/codegen_fail/fail/interface/impl_argument_no_object.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0277]: the trait bound `ObjA: juniper::ast::FromInputValue` is not satisfied | ||
--> $DIR/impl_argument_no_object.rs:11:1 | ||
| | ||
11 | / juniper::graphql_interface!(Character: () where Scalar = juniper::DefaultScalarValue |&self| { | ||
12 | | field id(__test: ObjA) -> &str { | ||
13 | | match *self { | ||
14 | | Character::A(_) => "funA", | ||
... | | ||
20 | | } | ||
21 | | }); | ||
| |___^ the trait `juniper::ast::FromInputValue` is not implemented for `ObjA` | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `ObjA: juniper::ast::FromInputValue` is not satisfied | ||
--> $DIR/impl_argument_no_object.rs:11:1 | ||
| | ||
11 | / juniper::graphql_interface!(Character: () where Scalar = juniper::DefaultScalarValue |&self| { | ||
12 | | field id(__test: ObjA) -> &str { | ||
13 | | match *self { | ||
14 | | Character::A(_) => "funA", | ||
... | | ||
20 | | } | ||
21 | | }); | ||
| |___^ the trait `juniper::ast::FromInputValue` is not implemented for `ObjA` | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) |
23 changes: 23 additions & 0 deletions
23
integration_tests/codegen_fail/fail/interface/impl_argument_no_underscore.rs.disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[derive(juniper::GraphQLObject)] | ||
#[graphql(scalar = juniper::DefaultScalarValue)] | ||
pub struct ObjA { | ||
test: String, | ||
} | ||
|
||
enum Character { | ||
A(ObjA), | ||
} | ||
|
||
juniper::graphql_interface!(Character: () where Scalar = juniper::DefaultScalarValue |&self| { | ||
field id(__test: String) -> &str { | ||
match *self { | ||
Character::A(_) => "funA", | ||
} | ||
} | ||
|
||
instance_resolvers: |_| { | ||
&ObjA => match *self { Character::A(ref h) => Some(h) }, | ||
} | ||
}); | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
integration_tests/codegen_fail/fail/interface/impl_no_fields.rs.disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
enum Character {} | ||
|
||
juniper::graphql_interface!(Character: () where Scalar = <S> |&self| { | ||
field id() -> &str { | ||
match *self { | ||
} | ||
} | ||
|
||
instance_resolvers: |_| {} | ||
}); | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
integration_tests/codegen_fail/fail/interface/impl_no_input_object.rs.disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[derive(juniper::GraphQLInputObject)] | ||
#[graphql(scalar = juniper::DefaultScalarValue)] | ||
pub struct ObjA { | ||
test: String, | ||
} | ||
|
||
enum Character { | ||
A(ObjA), | ||
} | ||
|
||
juniper::graphql_interface!(Character: () where Scalar = juniper::DefaultScalarValue |&self| { | ||
field id() -> &str { | ||
match *self { | ||
Character::A(_) => "funA", | ||
} | ||
} | ||
|
||
instance_resolvers: |_| { | ||
&ObjA => match *self { Character::A(ref h) => Some(h) }, | ||
} | ||
}); | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
integration_tests/codegen_fail/fail/interface/impl_no_underscore.rs.disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[derive(juniper::GraphQLObject)] | ||
#[graphql(scalar = juniper::DefaultScalarValue)] | ||
pub struct ObjA { | ||
test: String, | ||
} | ||
|
||
enum Character { | ||
A(ObjA), | ||
} | ||
|
||
juniper::graphql_interface!(Character: () where Scalar = juniper::DefaultScalarValue |&self| { | ||
field __id() -> &str { | ||
match *self { | ||
Character::A(_) => "funA", | ||
} | ||
} | ||
|
||
instance_resolvers: |_| { | ||
&ObjA => match *self { Character::A(ref h) => Some(h) }, | ||
} | ||
}); | ||
|
||
fn main() {} |
Oops, something went wrong.