juniper/integration_tests/juniper_tests/src/issue_398.rs
Kai Ren a4871887bb
Default to generic ScalarValue in #[graphql_object] macro (#779)
* Change codegen ScalarValue defaults for #[graphql_object] macro

* Fix integration tests

* Fix codegen failure tests

* Fix 'juniper' crate tests

* Fix integration crates tests

* Fix 'juniper_benchmarks' crate

* Fix examples

* Fix Book

* Fix

* Add CHANGELOG entry

* Some Book corrections

* Fix

* Bootstrap coercion machinery

* Reimpl coercion

* Correct tests, vol.1

* Correct tests, vol.2

* Correct tests, vol.3

* Correct tests, vol.4

* Correct tests, vol.5

* Fix coercion for subscriptions

* README fixes

Co-authored-by: Christian Legnitto <christian@legnitto.com>
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-11-06 18:15:18 -08:00

69 lines
1.3 KiB
Rust

// Original author of this test is <https://github.com/davidpdrsn>.
use juniper::{graphql_object, EmptyMutation, EmptySubscription, RootNode, Variables};
struct Query;
#[graphql_object]
impl Query {
fn users(executor: &Executor) -> Vec<User> {
// This doesn't cause a panic
executor.look_ahead();
vec![User {
country: Country { id: 1 },
}]
}
}
struct User {
country: Country,
}
#[graphql_object]
impl User {
fn country(&self, executor: &Executor) -> &Country {
// This panics!
executor.look_ahead();
&self.country
}
}
struct Country {
id: i32,
}
#[graphql_object]
impl Country {
fn id(&self) -> i32 {
self.id
}
}
type Schema = RootNode<'static, Query, EmptyMutation<()>, EmptySubscription<()>>;
#[tokio::test]
async fn test_lookahead_from_fragment_with_nested_type() {
let _ = juniper::execute(
r#"
query Query {
users {
...userFields
}
}
fragment userFields on User {
country {
id
}
}
"#,
None,
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
&Variables::new(),
&(),
)
.await
.unwrap();
}