Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Specification(June 2018) Compliance #631

Merged
merged 14 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"juniper",
"integration_tests/juniper_tests",
"integration_tests/async_await",
"integration_tests/codegen_fail",
"juniper_hyper",
"juniper_iron",
"juniper_rocket",
Expand Down
61 changes: 26 additions & 35 deletions integration_tests/async_await/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
use juniper::{graphql_value, GraphQLError, RootNode, Value};
use juniper::{graphql_value, EmptyMutation, EmptySubscription, GraphQLError, RootNode, Value};

#[derive(juniper::GraphQLEnum)]
enum UserKind {
Expand Down Expand Up @@ -71,24 +71,14 @@ impl Query {
}
}

struct Mutation;

#[juniper::graphql_object]
impl Mutation {}

struct Subscription;

#[juniper::graphql_subscription]
impl Subscription {}

#[tokio::test]
async fn async_simple() {
let schema = RootNode::new(Query, Mutation, Subscription);
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
let doc = r#"
query {
query {
fieldSync
fieldAsyncPlain
delayed
fieldAsyncPlain
delayed
user(id: "user1") {
kind
name
Expand Down Expand Up @@ -125,7 +115,7 @@ async fn async_simple() {

#[tokio::test]
async fn async_field_validation_error() {
let schema = RootNode::new(Query, Mutation, Subscription);
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
let doc = r#"
query {
nonExistentField
Expand All @@ -152,24 +142,25 @@ async fn async_field_validation_error() {
assert!(is_validation_error);
}

#[tokio::test]
async fn resolve_into_stream_validation_error() {
let schema = RootNode::new(Query, Mutation, Subscription);
let doc = r#"
subscription {
nonExistent
}
"#;
let vars = Default::default();
let result = juniper::resolve_into_stream(doc, None, &schema, &vars, &()).await;
assert!(result.is_err());

let error = result.err().unwrap();
let is_validation_error = match error {
GraphQLError::ValidationError(_) => true,
_ => false,
};
assert!(is_validation_error);
}
// FIXME: test seems broken by design, re-enable later
// #[tokio::test]
// async fn resolve_into_stream_validation_error() {
// let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
// let doc = r#"
// subscription {
// nonExistent
// }
// "#;
// let vars = Default::default();
// let result = juniper::resolve_into_stream(doc, None, &schema, &vars, &()).await;
// assert!(result.is_err());

// let error = result.err().unwrap();
// let is_validation_error = match error {
// GraphQLError::ValidationError(_) => true,
// _ => false,
// };
// assert!(is_validation_error);
// }

fn main() {}
14 changes: 14 additions & 0 deletions integration_tests/codegen_fail/Cargo.toml
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"
29 changes: 29 additions & 0 deletions integration_tests/codegen_fail/Makefile.toml
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"] }
4 changes: 4 additions & 0 deletions integration_tests/codegen_fail/fail/enum/derive_no_fields.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[derive(juniper::GraphQLEnum)]
pub enum Test {}

fn main() { }
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
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() {}
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[derive(juniper::GraphQLInputObject)]
struct Object {}

fn main() {}
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
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() {}
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
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() {}
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
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() {}
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)
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() {}
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() {}
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() {}
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() {}
Loading