Implement __typename for GraphQL objects

Fixes #22.
This commit is contained in:
Magnus Hallin 2017-02-04 10:45:25 +01:00
parent d87c6e4fa4
commit d8b07e8c68
2 changed files with 25 additions and 0 deletions

View file

@ -378,6 +378,10 @@ macro_rules! graphql_object {
mt.into_meta()
}
fn concrete_type_name(&self, _: &Self::Context) -> String {
$outname.to_owned()
}
#[allow(unused_variables)]
#[allow(unused_mut)]
fn resolve_field(

View file

@ -362,3 +362,24 @@ fn test_query_inline_fragments_human() {
].into_iter().collect()),
vec![])));
}
#[test]
fn test_object_typename() {
let doc = r#"
{
human(id: "1000") {
__typename
}
}"#;
let database = Database::new();
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
assert_eq!(
::execute(doc, None, &schema, &Variables::new(), &database),
Ok((Value::object(vec![
("human", Value::object(vec![
("__typename", Value::string("Human")),
].into_iter().collect())),
].into_iter().collect()),
vec![])));
}