commit
40f9024b51
@ -74,6 +74,7 @@ code > span.in { color: #008000; } /* Information */
|
|||||||
<span class="kw">import qualified</span> <span class="dt">Data.GraphQL.Schema</span> <span class="kw">as</span> <span class="dt">Schema</span>
|
<span class="kw">import qualified</span> <span class="dt">Data.GraphQL.Schema</span> <span class="kw">as</span> <span class="dt">Schema</span>
|
||||||
|
|
||||||
<span class="kw">import </span><span class="dt">Control.Applicative</span>
|
<span class="kw">import </span><span class="dt">Control.Applicative</span>
|
||||||
|
<span class="kw">import </span><span class="dt">Data.List.NonEmpty</span> (<span class="dt">NonEmpty</span>((:|)))
|
||||||
<span class="kw">import </span><span class="dt">Data.Text</span> <span class="kw">hiding</span> (empty)
|
<span class="kw">import </span><span class="dt">Data.Text</span> <span class="kw">hiding</span> (empty)
|
||||||
<span class="kw">import </span><span class="dt">Data.Aeson</span>
|
<span class="kw">import </span><span class="dt">Data.Aeson</span>
|
||||||
<span class="kw">import </span><span class="dt">Data.ByteString.Lazy.Char8</span> (putStrLn)
|
<span class="kw">import </span><span class="dt">Data.ByteString.Lazy.Char8</span> (putStrLn)
|
||||||
@ -86,7 +87,7 @@ code > span.in { color: #008000; } /* Information */
|
|||||||
<p>Now, as our first example, we are going to look at the example from <a href="https://github.com/graphql/graphql-js">graphql.js</a>.</p>
|
<p>Now, as our first example, we are going to look at the example from <a href="https://github.com/graphql/graphql-js">graphql.js</a>.</p>
|
||||||
<p>First we build a GraphQL schema.</p>
|
<p>First we build a GraphQL schema.</p>
|
||||||
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">schema1 ::</span> <span class="dt">Alternative</span> f <span class="ot">=></span> <span class="dt">Schema</span> f
|
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">schema1 ::</span> <span class="dt">Alternative</span> f <span class="ot">=></span> <span class="dt">Schema</span> f
|
||||||
schema1 <span class="fu">=</span> <span class="dt">Schema</span> [hello]
|
schema1 <span class="fu">=</span> hello <span class="fu">:|</span> []
|
||||||
|
|
||||||
<span class="ot">hello ::</span> <span class="dt">Alternative</span> f <span class="ot">=></span> <span class="dt">Resolver</span> f
|
<span class="ot">hello ::</span> <span class="dt">Alternative</span> f <span class="ot">=></span> <span class="dt">Resolver</span> f
|
||||||
hello <span class="fu">=</span> Schema.scalar <span class="st">"hello"</span> (<span class="st">"it's me"</span><span class="ot"> ::</span> <span class="dt">Text</span>)</code></pre></div>
|
hello <span class="fu">=</span> Schema.scalar <span class="st">"hello"</span> (<span class="st">"it's me"</span><span class="ot"> ::</span> <span class="dt">Text</span>)</code></pre></div>
|
||||||
@ -104,7 +105,7 @@ main1 <span class="fu">=</span> putStrLn <span class="fu">=<<</span> encod
|
|||||||
<h3>Monadic actions</h3>
|
<h3>Monadic actions</h3>
|
||||||
<p>For this example, we’re going to be using time.</p>
|
<p>For this example, we’re going to be using time.</p>
|
||||||
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">schema2 ::</span> <span class="dt">Schema</span> <span class="dt">IO</span>
|
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">schema2 ::</span> <span class="dt">Schema</span> <span class="dt">IO</span>
|
||||||
schema2 <span class="fu">=</span> <span class="dt">Schema</span> [time]
|
schema2 <span class="fu">=</span> time <span class="fu">:|</span> []
|
||||||
|
|
||||||
<span class="ot">time ::</span> <span class="dt">Resolver</span> <span class="dt">IO</span>
|
<span class="ot">time ::</span> <span class="dt">Resolver</span> <span class="dt">IO</span>
|
||||||
time <span class="fu">=</span> Schema.scalarA <span class="st">"time"</span> <span class="fu">$</span> \<span class="kw">case</span>
|
time <span class="fu">=</span> Schema.scalarA <span class="st">"time"</span> <span class="fu">$</span> \<span class="kw">case</span>
|
||||||
@ -144,7 +145,7 @@ This will fail
|
|||||||
<h3>Combining resolvers</h3>
|
<h3>Combining resolvers</h3>
|
||||||
<p>Now that we have two resolvers, we can define a schema which uses them both.</p>
|
<p>Now that we have two resolvers, we can define a schema which uses them both.</p>
|
||||||
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">schema3 ::</span> <span class="dt">Schema</span> <span class="dt">IO</span>
|
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">schema3 ::</span> <span class="dt">Schema</span> <span class="dt">IO</span>
|
||||||
schema3 <span class="fu">=</span> <span class="dt">Schema</span> [hello, time]
|
schema3 <span class="fu">=</span> hello <span class="fu">:|</span> [time]
|
||||||
|
|
||||||
<span class="ot">query3 ::</span> <span class="dt">Text</span>
|
<span class="ot">query3 ::</span> <span class="dt">Text</span>
|
||||||
query3 <span class="fu">=</span> <span class="st">"query timeAndHello { time hello }"</span>
|
query3 <span class="fu">=</span> <span class="st">"query timeAndHello { time hello }"</span>
|
||||||
|
@ -21,6 +21,7 @@ Since this file is a literate haskell file, we start by importing some dependenc
|
|||||||
> import qualified Data.GraphQL.Schema as Schema
|
> import qualified Data.GraphQL.Schema as Schema
|
||||||
>
|
>
|
||||||
> import Control.Applicative
|
> import Control.Applicative
|
||||||
|
> import Data.List.NonEmpty (NonEmpty((:|)))
|
||||||
> import Data.Text hiding (empty)
|
> import Data.Text hiding (empty)
|
||||||
> import Data.Aeson
|
> import Data.Aeson
|
||||||
> import Data.ByteString.Lazy.Char8 (putStrLn)
|
> import Data.ByteString.Lazy.Char8 (putStrLn)
|
||||||
@ -37,7 +38,7 @@ example from [graphql.js](https://github.com/graphql/graphql-js).
|
|||||||
First we build a GraphQL schema.
|
First we build a GraphQL schema.
|
||||||
|
|
||||||
> schema1 :: Alternative f => Schema f
|
> schema1 :: Alternative f => Schema f
|
||||||
> schema1 = Schema [hello]
|
> schema1 = hello :| []
|
||||||
>
|
>
|
||||||
> hello :: Alternative f => Resolver f
|
> hello :: Alternative f => Resolver f
|
||||||
> hello = Schema.scalar "hello" ("it's me" :: Text)
|
> hello = Schema.scalar "hello" ("it's me" :: Text)
|
||||||
@ -67,7 +68,7 @@ returning
|
|||||||
For this example, we're going to be using time.
|
For this example, we're going to be using time.
|
||||||
|
|
||||||
> schema2 :: Schema IO
|
> schema2 :: Schema IO
|
||||||
> schema2 = Schema [time]
|
> schema2 = time :| []
|
||||||
>
|
>
|
||||||
> time :: Resolver IO
|
> time :: Resolver IO
|
||||||
> time = Schema.scalarA "time" $ \case
|
> time = Schema.scalarA "time" $ \case
|
||||||
@ -127,7 +128,7 @@ This will fail
|
|||||||
Now that we have two resolvers, we can define a schema which uses them both.
|
Now that we have two resolvers, we can define a schema which uses them both.
|
||||||
|
|
||||||
> schema3 :: Schema IO
|
> schema3 :: Schema IO
|
||||||
> schema3 = Schema [hello, time]
|
> schema3 = hello :| [time]
|
||||||
>
|
>
|
||||||
> query3 :: Text
|
> query3 :: Text
|
||||||
> query3 = "query timeAndHello { time hello }"
|
> query3 = "query timeAndHello { time hello }"
|
||||||
|
Binary file not shown.
@ -29,6 +29,7 @@ dependencies.
|
|||||||
import qualified Data.GraphQL.Schema as Schema
|
import qualified Data.GraphQL.Schema as Schema
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
import Data.List.NonEmpty (NonEmpty((:|)))
|
||||||
import Data.Text hiding (empty)
|
import Data.Text hiding (empty)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.ByteString.Lazy.Char8 (putStrLn)
|
import Data.ByteString.Lazy.Char8 (putStrLn)
|
||||||
@ -48,7 +49,7 @@ First we build a GraphQL schema.
|
|||||||
.. code:: haskell
|
.. code:: haskell
|
||||||
|
|
||||||
schema1 :: Alternative f => Schema f
|
schema1 :: Alternative f => Schema f
|
||||||
schema1 = Schema [hello]
|
schema1 = hello :| []
|
||||||
|
|
||||||
hello :: Alternative f => Resolver f
|
hello :: Alternative f => Resolver f
|
||||||
hello = Schema.scalar "hello" ("it's me" :: Text)
|
hello = Schema.scalar "hello" ("it's me" :: Text)
|
||||||
@ -82,7 +83,7 @@ For this example, we're going to be using time.
|
|||||||
.. code:: haskell
|
.. code:: haskell
|
||||||
|
|
||||||
schema2 :: Schema IO
|
schema2 :: Schema IO
|
||||||
schema2 = Schema [time]
|
schema2 = time :| []
|
||||||
|
|
||||||
time :: Resolver IO
|
time :: Resolver IO
|
||||||
time = Schema.scalarA "time" $ \case
|
time = Schema.scalarA "time" $ \case
|
||||||
@ -150,7 +151,7 @@ both.
|
|||||||
.. code:: haskell
|
.. code:: haskell
|
||||||
|
|
||||||
schema3 :: Schema IO
|
schema3 :: Schema IO
|
||||||
schema3 = Schema [hello, time]
|
schema3 = hello :| [time]
|
||||||
|
|
||||||
query3 :: Text
|
query3 :: Text
|
||||||
query3 = "query timeAndHello { time hello }"
|
query3 = "query timeAndHello { time hello }"
|
||||||
|
Loading…
Reference in New Issue
Block a user