From 8a84455b0ac7a8434643bd5ae14f34180ecce0db Mon Sep 17 00:00:00 2001 From: Sunli Date: Mon, 11 May 2020 12:23:23 +0800 Subject: [PATCH] Create a boilerplate test code for introspection. #66 --- tests/test_introspection.rs | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 tests/test_introspection.rs diff --git a/tests/test_introspection.rs b/tests/test_introspection.rs new file mode 100644 index 00000000..126db8f1 --- /dev/null +++ b/tests/test_introspection.rs @@ -0,0 +1,98 @@ +use async_graphql::*; + +/// Is SimpleObject +#[SimpleObject] +struct SimpleObject { + /// Value a + a: i32, + + #[field(desc = "Value b")] + b: String, + + #[field(deprecation = "Test deprecated")] + c: bool, +} + +struct Query; + +#[Object] +impl Query { + /// Get a simple object + async fn simple_object(&self) -> SimpleObject { + unimplemented!() + } +} + +#[async_std::test] +pub async fn test_introspection() { + let schema = Schema::new(Query, EmptyMutation, EmptySubscription); + + let res = schema + .execute( + r#" + { + __type(name: "SimpleObject") { + kind + name + description + fields(includeDeprecated: true) { + name + description + args { name } + type { name kind ofType { name kind } } + isDeprecated + deprecationReason + } + interfaces { name } + possibleTypes { name } + enumValues { name } + inputFields { name } + ofType { name } + } + }"#, + ) + .await + .unwrap() + .data; + assert_eq!( + res, + serde_json::json!({ + "__type": { + "kind": "OBJECT", + "name": "SimpleObject", + "description": "Is SimpleObject", + "fields": [ + { + "name": "a", + "description": "Value a", + "args": [], + "type": { "name": null, "kind": "NON_NULL", "ofType": { "name": "Int", "kind": "SCALAR" } }, + "isDeprecated": false, + "deprecationReason": null, + }, + { + "name": "b", + "description": "Value b", + "args": [], + "type": { "name": null, "kind": "NON_NULL", "ofType": { "name": "String", "kind": "SCALAR" } }, + "isDeprecated": false, + "deprecationReason": null, + }, + { + "name": "c", + "description": null, + "args": [], + "type": { "name": null, "kind": "NON_NULL", "ofType": { "name": "Boolean", "kind": "SCALAR" } }, + "isDeprecated": true, + "deprecationReason": "Test deprecated", + }, + ], + "interfaces": [], + "possibleTypes": null, + "enumValues": null, + "inputFields": null, + "ofType": null, + } + }) + ) +}