Updated book for master ***NO_CI***
This commit is contained in:
parent
492354b25d
commit
25ce7d0c8e
5 changed files with 86 additions and 2 deletions
|
@ -183,6 +183,7 @@ your Schemas automatically.</p>
|
|||
<p>Juniper has not reached 1.0 yet, thus some API instability should be expected.</p>
|
||||
<a class="header" href="#quickstart" id="quickstart"><h1>Quickstart</h1></a>
|
||||
<p>This page will give you a short introduction to the concepts in Juniper.</p>
|
||||
<p>Juniper follows a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">code-first approach</a> to defining GraphQL schemas. If you would like to use a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">schema-first approach</a> instead, consider <a href="https://github.com/davidpdrsn/juniper-from-schema">juniper-from-schema</a> for generating code from a schema file.</p>
|
||||
<a class="header" href="#installation" id="installation"><h2>Installation</h2></a>
|
||||
<p>!FILENAME Cargo.toml</p>
|
||||
<pre><code class="language-toml">[dependencies]
|
||||
|
@ -2002,6 +2003,7 @@ enum Character {
|
|||
# fn main() {}
|
||||
</code></pre></pre>
|
||||
<a class="header" href="#schemas" id="schemas"><h1>Schemas</h1></a>
|
||||
<p>Juniper follows a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">code-first approach</a> to defining GraphQL schemas. If you would like to use a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">schema-first approach</a> instead, consider <a href="https://github.com/davidpdrsn/juniper-from-schema">juniper-from-schema</a> for generating code from a schema file.</p>
|
||||
<p>A schema consists of three types: a query object, a mutation object, and a subscription object.
|
||||
These three define the root query fields, mutations and subscriptions of the schema, respectively.</p>
|
||||
<p>The usage of subscriptions is a little different from the mutation and query objects, so there is a specific <a href="../advanced/subscriptions.html">section</a> that discusses them.</p>
|
||||
|
@ -2049,6 +2051,46 @@ impl Mutations {
|
|||
|
||||
# fn main() { }
|
||||
</code></pre></pre>
|
||||
<a class="header" href="#outputting-schemas-in-the-a-hrefhttpsgraphqlorglearnschematype-languagegraphql-schema-languagea" id="outputting-schemas-in-the-a-hrefhttpsgraphqlorglearnschematype-languagegraphql-schema-languagea"><h1>Outputting schemas in the <a href="https://graphql.org/learn/schema/#type-language">GraphQL Schema Language</a></h1></a>
|
||||
<p>Many tools in the GraphQL ecosystem require the schema to be defined in the <a href="https://graphql.org/learn/schema/#type-language">GraphQL Schema Language</a>. You can generate a <a href="https://graphql.org/learn/schema/#type-language">GraphQL Schema Language</a> representation of your schema defined in Rust using the <code>schema-language</code> feature (on by default):</p>
|
||||
<pre><pre class="playpen"><code class="language-rust"># // Only needed due to 2018 edition because the macro is not accessible.
|
||||
# #[macro_use] extern crate juniper;
|
||||
use juniper::{FieldResult, EmptyMutation, EmptySubscription, RootNode};
|
||||
|
||||
struct Query;
|
||||
|
||||
#[juniper::graphql_object]
|
||||
impl Query {
|
||||
fn hello(&self) -> FieldResult<&str> {
|
||||
Ok("hello world")
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Define our schema in Rust.
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
EmptyMutation::<()>::new(),
|
||||
EmptySubscription::<()>::new(),
|
||||
);
|
||||
|
||||
// Convert the Rust schema into the GraphQL Schema Language.
|
||||
let result = schema.as_schema_language();
|
||||
|
||||
let expected = "\
|
||||
type Query {
|
||||
hello: String!
|
||||
}
|
||||
|
||||
schema {
|
||||
query: Query
|
||||
}
|
||||
";
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
</code></pre></pre>
|
||||
<p>Note the <code>schema-language</code> feature may be turned off if you do not need this functionality to reduce dependencies and speed up
|
||||
compile times.</p>
|
||||
<!--TODO: Fix This URL when the EmptySubscription become available in the Documentation -->
|
||||
[EmptySubscription]: https://docs.rs/juniper/0.14.2/juniper/struct.EmptySubscription.html
|
||||
<a class="header" href="#adding-a-server" id="adding-a-server"><h1>Adding A Server</h1></a>
|
||||
|
|
|
@ -138,6 +138,7 @@
|
|||
<main>
|
||||
<a class="header" href="#quickstart" id="quickstart"><h1>Quickstart</h1></a>
|
||||
<p>This page will give you a short introduction to the concepts in Juniper.</p>
|
||||
<p>Juniper follows a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">code-first approach</a> to defining GraphQL schemas. If you would like to use a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">schema-first approach</a> instead, consider <a href="https://github.com/davidpdrsn/juniper-from-schema">juniper-from-schema</a> for generating code from a schema file.</p>
|
||||
<a class="header" href="#installation" id="installation"><h2>Installation</h2></a>
|
||||
<p>!FILENAME Cargo.toml</p>
|
||||
<pre><code class="language-toml">[dependencies]
|
||||
|
|
|
@ -137,6 +137,7 @@
|
|||
<div id="content" class="content">
|
||||
<main>
|
||||
<a class="header" href="#schemas" id="schemas"><h1>Schemas</h1></a>
|
||||
<p>Juniper follows a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">code-first approach</a> to defining GraphQL schemas. If you would like to use a <a href="https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/">schema-first approach</a> instead, consider <a href="https://github.com/davidpdrsn/juniper-from-schema">juniper-from-schema</a> for generating code from a schema file.</p>
|
||||
<p>A schema consists of three types: a query object, a mutation object, and a subscription object.
|
||||
These three define the root query fields, mutations and subscriptions of the schema, respectively.</p>
|
||||
<p>The usage of subscriptions is a little different from the mutation and query objects, so there is a specific <a href="../advanced/subscriptions.html">section</a> that discusses them.</p>
|
||||
|
@ -184,6 +185,46 @@ impl Mutations {
|
|||
|
||||
# fn main() { }
|
||||
</code></pre></pre>
|
||||
<a class="header" href="#outputting-schemas-in-the-a-hrefhttpsgraphqlorglearnschematype-languagegraphql-schema-languagea" id="outputting-schemas-in-the-a-hrefhttpsgraphqlorglearnschematype-languagegraphql-schema-languagea"><h1>Outputting schemas in the <a href="https://graphql.org/learn/schema/#type-language">GraphQL Schema Language</a></h1></a>
|
||||
<p>Many tools in the GraphQL ecosystem require the schema to be defined in the <a href="https://graphql.org/learn/schema/#type-language">GraphQL Schema Language</a>. You can generate a <a href="https://graphql.org/learn/schema/#type-language">GraphQL Schema Language</a> representation of your schema defined in Rust using the <code>schema-language</code> feature (on by default):</p>
|
||||
<pre><pre class="playpen"><code class="language-rust"># // Only needed due to 2018 edition because the macro is not accessible.
|
||||
# #[macro_use] extern crate juniper;
|
||||
use juniper::{FieldResult, EmptyMutation, EmptySubscription, RootNode};
|
||||
|
||||
struct Query;
|
||||
|
||||
#[juniper::graphql_object]
|
||||
impl Query {
|
||||
fn hello(&self) -> FieldResult<&str> {
|
||||
Ok("hello world")
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Define our schema in Rust.
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
EmptyMutation::<()>::new(),
|
||||
EmptySubscription::<()>::new(),
|
||||
);
|
||||
|
||||
// Convert the Rust schema into the GraphQL Schema Language.
|
||||
let result = schema.as_schema_language();
|
||||
|
||||
let expected = "\
|
||||
type Query {
|
||||
hello: String!
|
||||
}
|
||||
|
||||
schema {
|
||||
query: Query
|
||||
}
|
||||
";
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
</code></pre></pre>
|
||||
<p>Note the <code>schema-language</code> feature may be turned off if you do not need this functionality to reduce dependencies and speed up
|
||||
compile times.</p>
|
||||
<!--TODO: Fix This URL when the EmptySubscription become available in the Documentation -->
|
||||
[EmptySubscription]: https://docs.rs/juniper/0.14.2/juniper/struct.EmptySubscription.html
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue