From ecbe1a730afba7c654df3f8d01df2b23f06a2d1e Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Thu, 16 May 2019 19:32:33 -0700 Subject: [PATCH] Update current docs --- current/advanced/index.html | 13 +- current/advanced/introspection.html | 263 ++++++++++ .../advanced/multiple_ops_per_request.html | 2 +- current/advanced/non_struct_objects.html | 15 +- current/advanced/objects_and_generics.html | 24 +- current/css/variables.css | 58 +-- current/index.html | 2 +- current/print.html | 472 ++++++++++++------ current/quickstart.html | 76 +-- current/schema/schemas_and_mutations.html | 22 +- current/searchindex.js | 2 +- current/searchindex.json | 2 +- current/servers/hyper.html | 2 +- current/servers/index.html | 15 +- current/servers/iron.html | 25 +- current/servers/official.html | 10 +- current/servers/rocket.html | 2 +- current/servers/third-party.html | 2 +- current/servers/warp.html | 2 +- current/types/enums.html | 4 +- current/types/index.html | 22 +- current/types/input_objects.html | 20 +- current/types/interfaces.html | 8 +- current/types/objects/complex_fields.html | 102 +++- current/types/objects/defining_objects.html | 4 +- current/types/objects/error_handling.html | 21 +- current/types/objects/using_contexts.html | 45 +- current/types/other-index.html | 12 +- current/types/scalars.html | 2 +- current/types/unions.html | 12 +- 30 files changed, 902 insertions(+), 359 deletions(-) create mode 100644 current/advanced/introspection.html diff --git a/current/advanced/index.html b/current/advanced/index.html index 4a5eb4e4..aad31557 100644 --- a/current/advanced/index.html +++ b/current/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/current/advanced/introspection.html b/current/advanced/introspection.html new file mode 100644 index 00000000..7a1421f3 --- /dev/null +++ b/current/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:

+
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::object(
+  Context = Context,
+)]
+impl Query {
+   fn example(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/current/advanced/multiple_ops_per_request.html b/current/advanced/multiple_ops_per_request.html index 2e4f25fc..951c0734 100644 --- a/current/advanced/multiple_ops_per_request.html +++ b/current/advanced/multiple_ops_per_request.html @@ -72,7 +72,7 @@
diff --git a/current/advanced/non_struct_objects.html b/current/advanced/non_struct_objects.html index 94c70b1a..80fa8ba8 100644 --- a/current/advanced/non_struct_objects.html +++ b/current/advanced/non_struct_objects.html @@ -72,7 +72,7 @@
@@ -157,21 +157,22 @@ enum SignUpResult { Error(Vec<ValidationError>), } -juniper::graphql_object!(SignUpResult: () |&self| { - field user() -> Option<&User> { +#[juniper::object] +impl SignUpResult { + fn user(&self) -> Option<&User> { match *self { SignUpResult::Ok(ref user) => Some(user), SignUpResult::Error(_) => None, } } - field error() -> Option<&Vec<ValidationError>> { + fn error(&self) -> Option<&Vec<ValidationError>> { match *self { SignUpResult::Ok(_) => None, SignUpResult::Error(ref errors) => Some(errors) } } -}); +} # fn main() {} @@ -191,7 +192,7 @@ be used, and how to model expected errors.