@@ -39,6 +39,9 @@ Which means we have base type, an _object_ called `Hello`, which has a single
39
39
_field_ `greeting`, which takes a non-nullable `String` called `who` and
40
40
returns a `String`.
41
41
42
+ Note that all the types here are GraphQL types, not Haskell types. `String`
43
+ here is a GraphQL `String`, not a Haskell one.
44
+
42
45
And we want to be able to send queries that look like:
43
46
44
47
`` `graphql
@@ -72,11 +75,14 @@ object (also named `"Hello"`) that implements no interfaces (hence `'[]`). It
72
75
has one field, called `" greeting" ` which returns some `Text` and takes a
73
76
single named argument `"who"` , which is also `Text`.
74
77
78
+ Note that the GraphQL `String` from above got translated into a Haskell
79
+ `Text`.
80
+
75
81
There are some noteworthy differences between this schema and the GraphQL
76
82
schema:
77
83
78
84
* The GraphQL schema requires a special annotation to say that a value cannot
79
- be null, `!`. In Haskell, we instead assume that everything can't be null.
85
+ be null, `!`. In Haskell, we instead assume that nothing can be null.
80
86
* In the GraphQL schema, the argument appears *after* the field name. In
81
87
Haskell, it appears *before*.
82
88
* In Haskell, we name the top-level type twice, once on left hand side of the
@@ -111,8 +117,8 @@ The second layer of the handler, the implementation of `greeting`, produces
111
117
the value of the `greeting` field. It is monadic so that it will only be
112
118
executed when the field was requested.
113
119
114
- Each handler is a separate monadic action so we only perform the side effects
115
- for fields present in the query.
120
+ Each field handler is a separate monadic action so we only perform the side
121
+ effects for fields present in the query.
116
122
117
123
This handler is in `Identity` because it doesn't do anything particularly
118
124
monadic. It could be in `IO` or `STM` or `ExceptT Text IO` or whatever you
@@ -127,8 +133,8 @@ queryHello :: IO Response
127
133
queryHello = interpretAnonymousQuery @Hello hello " { greeting(who: \" mort\" ) }"
128
134
`` `
129
135
130
- The actual `Response` type is fairly big , so we're most likely to turn it into
131
- JSON:
136
+ The actual `Response` type is fairly verbose , so we're most likely to turn it
137
+ into JSON:
132
138
133
139
`` `
134
140
λ Aeson.encode <$ > queryHello
@@ -255,13 +261,13 @@ union UserOrCalculator = User | Calculator
255
261
And now in Haskell:
256
262
257
263
```haskell
258
- type UserOrCalcualtor = Union "UserOrCalcualtor " '[User, Calculator]
264
+ type UserOrCalculator = Union "UserOrCalculator " '[User, Calculator]
259
265
```
260
266
261
- And let's define a very simple top-level object that uses `UserOrCalcualtor `:
267
+ And let's define a very simple top-level object that uses `UserOrCalculator `:
262
268
263
269
```haskell
264
- type UnionQuery = Object "UnionQuery" '[] '[Field "union" UserOrCalcualtor ]
270
+ type UnionQuery = Object "UnionQuery" '[] '[Field "union" UserOrCalculator ]
265
271
```
266
272
267
273
and a handler that randomly returns either a user or a calculator:
0 commit comments