Integration tests: impl_object refactor
This commit is contained in:
parent
a993c16b85
commit
bf50c3eb86
8 changed files with 109 additions and 64 deletions
|
@ -4,15 +4,7 @@ version = "0.1.0"
|
|||
publish = false
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
juniper = { version = "0.11.0", path = "../../juniper" }
|
||||
serde_json = { version = "1" }
|
||||
|
||||
[dev-dependencies]
|
||||
juniper = { path = "../../juniper" }
|
||||
serde_json = { version = "1" }
|
||||
fnv = "1.0.3"
|
||||
indexmap = "1.0"
|
||||
|
||||
[[test]]
|
||||
name = "integration_tests"
|
||||
path = "src/lib.rs"
|
||||
harness = true
|
||||
|
|
|
@ -19,7 +19,7 @@ enum DocEnum {
|
|||
Foo,
|
||||
}
|
||||
|
||||
/// Doc 1.
|
||||
/// Doc 1.\
|
||||
/// Doc 2.
|
||||
///
|
||||
/// Doc 4.
|
||||
|
@ -85,7 +85,7 @@ fn test_multi_doc_comment() {
|
|||
let meta = MultiDocEnum::meta(&(), &mut registry);
|
||||
assert_eq!(
|
||||
meta.description(),
|
||||
Some(&"Doc 1. Doc 2.\nDoc 4.".to_string())
|
||||
Some(&"Doc 1. Doc 2.\n\nDoc 4.".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ struct DocComment {
|
|||
regular_field: bool,
|
||||
}
|
||||
|
||||
/// Doc 1.
|
||||
/// Doc 1.\
|
||||
/// Doc 2.
|
||||
///
|
||||
/// Doc 4.
|
||||
|
@ -151,7 +151,7 @@ fn test_multi_doc_comment() {
|
|||
let meta = MultiDocComment::meta(&(), &mut registry);
|
||||
assert_eq!(
|
||||
meta.description(),
|
||||
Some(&"Doc 1. Doc 2.\nDoc 4.".to_string())
|
||||
Some(&"Doc 1. Doc 2.\n\nDoc 4.".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,20 +12,20 @@ use juniper::{self, execute, EmptyMutation, GraphQLType, RootNode, Value, Variab
|
|||
#[graphql(
|
||||
name = "MyObj",
|
||||
description = "obj descr",
|
||||
scalar = "DefaultScalarValue"
|
||||
scalar = DefaultScalarValue
|
||||
)]
|
||||
struct Obj {
|
||||
regular_field: bool,
|
||||
#[graphql(
|
||||
name = "renamedField",
|
||||
description = "descr",
|
||||
deprecation = "field descr"
|
||||
deprecated = "field deprecation"
|
||||
)]
|
||||
c: i32,
|
||||
}
|
||||
|
||||
#[derive(GraphQLObject, Debug, PartialEq)]
|
||||
#[graphql(scalar = "DefaultScalarValue")]
|
||||
#[graphql(scalar = DefaultScalarValue)]
|
||||
struct Nested {
|
||||
obj: Obj,
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ struct DocComment {
|
|||
regular_field: bool,
|
||||
}
|
||||
|
||||
/// Doc 1.
|
||||
/// Doc 1.\
|
||||
/// Doc 2.
|
||||
///
|
||||
/// Doc 4.
|
||||
|
@ -75,56 +75,57 @@ struct Context;
|
|||
impl juniper::Context for Context {}
|
||||
|
||||
#[derive(GraphQLObject, Debug)]
|
||||
#[graphql(Context = "Context")]
|
||||
#[graphql(Context = Context)]
|
||||
struct WithCustomContext {
|
||||
a: bool,
|
||||
}
|
||||
|
||||
juniper::graphql_object!(Query: () |&self| {
|
||||
field obj() -> Obj {
|
||||
Obj{
|
||||
regular_field: true,
|
||||
c: 22,
|
||||
}
|
||||
}
|
||||
|
||||
field nested() -> Nested {
|
||||
Nested{
|
||||
obj: Obj{
|
||||
regular_field: false,
|
||||
c: 333,
|
||||
}
|
||||
#[juniper::impl_object]
|
||||
impl Query {
|
||||
fn obj() -> Obj {
|
||||
Obj {
|
||||
regular_field: true,
|
||||
c: 22,
|
||||
}
|
||||
}
|
||||
|
||||
field doc() -> DocComment {
|
||||
DocComment{
|
||||
regular_field: true,
|
||||
}
|
||||
fn nested() -> Nested {
|
||||
Nested {
|
||||
obj: Obj {
|
||||
regular_field: false,
|
||||
c: 333,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
field multi_doc() -> MultiDocComment {
|
||||
MultiDocComment{
|
||||
regular_field: true,
|
||||
}
|
||||
fn doc() -> DocComment {
|
||||
DocComment {
|
||||
regular_field: true,
|
||||
}
|
||||
}
|
||||
|
||||
field override_doc() -> OverrideDocComment {
|
||||
OverrideDocComment{
|
||||
regular_field: true,
|
||||
}
|
||||
fn multi_doc() -> MultiDocComment {
|
||||
MultiDocComment {
|
||||
regular_field: true,
|
||||
}
|
||||
}
|
||||
|
||||
field skipped_field_obj() -> SkippedFieldObj {
|
||||
SkippedFieldObj{
|
||||
fn override_doc() -> OverrideDocComment {
|
||||
OverrideDocComment {
|
||||
regular_field: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn skipped_field_obj() -> SkippedFieldObj {
|
||||
SkippedFieldObj {
|
||||
regular_field: false,
|
||||
skipped: 42,
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_doc_comment() {
|
||||
fn test_doc_comment_simple() {
|
||||
let mut registry: juniper::Registry = juniper::Registry::new(FnvHashMap::default());
|
||||
let meta = DocComment::meta(&(), &mut registry);
|
||||
assert_eq!(meta.description(), Some(&"Object comment.".to_string()));
|
||||
|
@ -143,14 +144,14 @@ fn test_multi_doc_comment() {
|
|||
let meta = MultiDocComment::meta(&(), &mut registry);
|
||||
assert_eq!(
|
||||
meta.description(),
|
||||
Some(&"Doc 1. Doc 2.\nDoc 4.".to_string())
|
||||
Some(&"Doc 1. Doc 2.\n\nDoc 4.".to_string())
|
||||
);
|
||||
|
||||
check_descriptions(
|
||||
"MultiDocComment",
|
||||
&Value::scalar("Doc 1. Doc 2.\nDoc 4."),
|
||||
&Value::scalar("Doc 1. Doc 2.\n\nDoc 4."),
|
||||
"regularField",
|
||||
&Value::scalar("Field 1. Field 2."),
|
||||
&Value::scalar("Field 1.\nField 2."),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
mod util;
|
||||
|
||||
mod derive_enum;
|
||||
mod derive_input_object;
|
||||
mod derive_object;
|
||||
|
|
54
integration_tests/juniper_tests/src/codegen/util.rs
Normal file
54
integration_tests/juniper_tests/src/codegen/util.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use juniper::{DefaultScalarValue, GraphQLType, RootNode, Value, Variables};
|
||||
use std::default::Default;
|
||||
|
||||
pub fn run_query<Query, Mutation, Context>(query: &str) -> Value
|
||||
where
|
||||
Query: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
|
||||
Mutation: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
|
||||
Context: Default,
|
||||
{
|
||||
let schema = RootNode::new(Query::default(), Mutation::default());
|
||||
let (result, errs) =
|
||||
juniper::execute(query, None, &schema, &Variables::new(), &Context::default())
|
||||
.expect("Execution failed");
|
||||
|
||||
assert_eq!(errs, []);
|
||||
result
|
||||
}
|
||||
|
||||
pub fn run_info_query<Query, Mutation, Context>(type_name: &str) -> Value
|
||||
where
|
||||
Query: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
|
||||
Mutation: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
|
||||
Context: Default,
|
||||
{
|
||||
let query = format!(
|
||||
r#"
|
||||
{{
|
||||
__type(name: "{}") {{
|
||||
name,
|
||||
description,
|
||||
fields {{
|
||||
name
|
||||
description
|
||||
args {{
|
||||
name
|
||||
description
|
||||
type {{
|
||||
name
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
"#,
|
||||
type_name
|
||||
);
|
||||
let result = run_query::<Query, Mutation, Context>(&query);
|
||||
result
|
||||
.as_object_value()
|
||||
.expect("Result is not an object")
|
||||
.get_field_value("__type")
|
||||
.expect("__type field missing")
|
||||
.clone()
|
||||
}
|
|
@ -151,15 +151,18 @@ juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue {
|
|||
|
||||
struct TestType;
|
||||
|
||||
juniper::graphql_object!(TestType: () where Scalar = MyScalarValue |&self| {
|
||||
field long_field() -> i64 {
|
||||
#[juniper::impl_object(
|
||||
Scalar = MyScalarValue
|
||||
)]
|
||||
impl TestType {
|
||||
fn long_field() -> i64 {
|
||||
(::std::i32::MAX as i64) + 1
|
||||
}
|
||||
|
||||
field long_with_arg(long_arg: i64) -> i64 {
|
||||
fn long_with_arg(long_arg: i64) -> i64 {
|
||||
long_arg
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn run_variable_query<F>(query: &str, vars: Variables<MyScalarValue>, f: F)
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
extern crate juniper;
|
||||
#[cfg(test)]
|
||||
extern crate serde_json;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate fnv;
|
||||
#[cfg(test)]
|
||||
extern crate indexmap;
|
||||
|
||||
mod codegen;
|
||||
#[cfg(test)]
|
||||
mod custom_scalar;
|
||||
|
|
Loading…
Reference in a new issue