From 5b36373eb9f0ef1792cd99211a8897cb513f5a88 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Wed, 10 Apr 2019 02:26:56 +0200 Subject: [PATCH] Updated book for master --- master/advanced/index.html | 13 +- master/advanced/introspection.html | 263 ++++++++++++++++++ master/advanced/multiple_ops_per_request.html | 2 +- master/advanced/non_struct_objects.html | 6 +- master/advanced/objects_and_generics.html | 2 +- master/css/variables.css | 58 ++-- master/index.html | 2 +- master/print.html | 148 +++++++--- master/quickstart.html | 13 +- master/schema/schemas_and_mutations.html | 6 +- master/searchindex.js | 2 +- master/searchindex.json | 2 +- master/servers/hyper.html | 2 +- master/servers/index.html | 15 +- master/servers/iron.html | 5 +- master/servers/official.html | 10 +- master/servers/rocket.html | 2 +- master/servers/third-party.html | 2 +- master/servers/warp.html | 2 +- master/types/enums.html | 4 +- master/types/index.html | 22 +- master/types/input_objects.html | 4 +- master/types/interfaces.html | 2 +- master/types/objects/complex_fields.html | 2 +- master/types/objects/defining_objects.html | 2 +- master/types/objects/error_handling.html | 2 +- master/types/objects/using_contexts.html | 4 +- master/types/other-index.html | 12 +- master/types/scalars.html | 2 +- master/types/unions.html | 2 +- 30 files changed, 474 insertions(+), 139 deletions(-) create mode 100644 master/advanced/introspection.html diff --git a/master/advanced/index.html b/master/advanced/index.html index 4a5eb4e4..aad31557 100644 --- a/master/advanced/index.html +++ b/master/advanced/index.html @@ -72,7 +72,7 @@
@@ -139,9 +139,10 @@

Advanced Topics

The chapters below cover some more advanced scenarios.

@@ -155,7 +156,7 @@ - @@ -173,7 +174,7 @@ - diff --git a/master/advanced/introspection.html b/master/advanced/introspection.html new file mode 100644 index 00000000..b0c75b6c --- /dev/null +++ b/master/advanced/introspection.html @@ -0,0 +1,263 @@ + + + + + + Introspection - Juniper - GraphQL Server for Rust + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + +
+
+

Introspection

+

GraphQL defines a special built-in top-level field called __schema. Querying +for this field allows one to introspect the schema +at runtime to see what queries and mutations the GraphQL server supports.

+

Because introspection queries are just regular GraphQL queries, Juniper supports +them natively. For example, to get all the names of the types supported one +could execute the following query against Juniper:

+
{
+  __schema {
+    types {
+      name
+    }
+  }
+}
+
+

Schema introspection output as JSON

+

Many client libraries and tools in the GraphQL ecosystem require a complete +representation of the server schema. Often this representation is in JSON and +referred to as schema.json. A complete representation of the schema can be +produced by issuing a specially crafted introspection query.

+

Juniper provides a convenience function to introspect the entire schema. The +result can then be converted to JSON for use with tools and libraries such as +graphql-client:

+
# // Only needed due to 2018 edition because the macro is not accessible.
+# extern crate juniper;
+# extern crate serde_json;
+use juniper::{EmptyMutation, FieldResult, IntrospectionFormat};
+
+// Define our schema.
+
+#[derive(juniper::GraphQLObject)]
+struct Example {
+  id: String,
+}
+
+struct Context;
+impl juniper::Context for Context {}
+
+struct Query;
+
+juniper::graphql_object!(Query: Context |&self| {
+   field example(&executor, id: String) -> FieldResult<Example> {
+       unimplemented!()
+   }
+});
+
+type Schema = juniper::RootNode<'static, Query, EmptyMutation<Context>>;
+
+fn main() {
+    // Create a context object.
+    let ctx = Context{};
+
+    // Run the built-in introspection query.
+    let (res, _errors) = juniper::introspect(
+        &Schema::new(Query, EmptyMutation::new()),
+        &ctx,
+        IntrospectionFormat::default(),
+    ).unwrap();
+
+    // Convert introspection result to json.
+    let json_result = serde_json::to_string_pretty(&res);
+    assert!(json_result.is_ok());
+}
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/master/advanced/multiple_ops_per_request.html b/master/advanced/multiple_ops_per_request.html index 2e4f25fc..951c0734 100644 --- a/master/advanced/multiple_ops_per_request.html +++ b/master/advanced/multiple_ops_per_request.html @@ -72,7 +72,7 @@
diff --git a/master/advanced/non_struct_objects.html b/master/advanced/non_struct_objects.html index 94c70b1a..ab163302 100644 --- a/master/advanced/non_struct_objects.html +++ b/master/advanced/non_struct_objects.html @@ -72,7 +72,7 @@
@@ -191,7 +191,7 @@ be used, and how to model expected errors.