|
3 | 3 | [](https://circleci.com/gh/jml/graphql-api)
|
4 | 4 | [](http://haskell-graphql-api.readthedocs.io/en/latest/?badge=latest)
|
5 | 5 |
|
6 |
| -Sketch of GraphQL stuff |
| 6 | +This library provides type combinators to create a GraphQL schema, and functions to parse and evaluate queries against the schema. It is inspired by [servant](http://haskell-servant.readthedocs.io/en/stable/) but the two projects don't share any code. |
7 | 7 |
|
8 |
| -## What it is |
| 8 | +More specifically, `graphql-api` helps with implementing a robust GraphQL API in Haskell. By the time a query makes it to your handler you are dealing with strong, static types. All handlers are normal Haskell functions because we derive their type signature from the schema. |
9 | 9 |
|
10 |
| -Aim is to be [servant](http://haskell-servant.readthedocs.io/) for GraphQL. |
| 10 | +You can find the latest release on [hackage](https://hackage.haskell.org/package/graphql-api). |
11 | 11 |
|
12 |
| -To do this, we're going to need: |
| 12 | +Note that we're trying to implement the GraphQL standard as best as we can in Haskell. I.e. even if an alternative API or behaviour looks nicer we will defer to the standard. |
13 | 13 |
|
14 |
| -* Type-level definition of queries and schemas |
15 |
| -* Evaluation of GraphQL queries (and mutations) according to those types. |
| 14 | +## Hello world example |
16 | 15 |
|
17 |
| -We can build off the |
18 |
| -existing [graphql](http://hackage.haskell.org/package/graphql) library for |
19 |
| -parsing & representing queries. |
| 16 | +Below we define a `Hello` Schema that contains a single field, `greeting`, that takes a single, required argument `who`: |
20 | 17 |
|
21 |
| -## Why you might want it |
| 18 | +```haskell |
| 19 | +import Data.Text (Text) |
| 20 | +import Data.Monoid ((<>)) |
22 | 21 |
|
23 |
| -Right now, you don't. We're working on it. Please feel free to contribute by |
24 |
| -filing issues & submitting PRs. |
| 22 | +import GraphQL |
| 23 | +import GraphQL.API |
| 24 | +import GraphQL.Resolver (Handler) |
| 25 | + |
| 26 | +type Hello = Object "Hello" '[] |
| 27 | + '[ Argument "who" Text :> Field "greeting" Text ] |
| 28 | + |
| 29 | +hello :: Handler IO Hello |
| 30 | +hello = pure (\who -> pure ("Hello " <> who)) |
| 31 | + |
| 32 | +run :: Text -> IO Response |
| 33 | +run = interpretAnonymousQuery @Hello hello |
| 34 | +``` |
| 35 | + |
| 36 | +Note that we require GHC 8.0.2 or later for features like the `@Hello` type application, and for certain bug fixes. |
| 37 | + |
| 38 | +With the code above we can now run a query: |
| 39 | + |
| 40 | +```haskell |
| 41 | +run "{ greeting(who: \"mort\") }" |
| 42 | +``` |
| 43 | + |
| 44 | +## Current status |
| 45 | + |
| 46 | +This first release's goal is to gather feedback. We make **no** guarantees about API stability, or anything at all really. |
| 47 | + |
| 48 | +We are tracking open problem, missing features & wishlist-items in [GitHub's issue tracker](https://github.com/jml/graphql-api/issues). |
| 49 | + |
| 50 | +## Roadmap |
| 51 | + |
| 52 | +* Near future: |
| 53 | + - Complete lose ends in current implementation & gather feedback. |
| 54 | +* Medium future: |
| 55 | + - Implement introspection |
| 56 | +* Long term: |
| 57 | + - Derive client implementations from types |
| 58 | + - Allow users to implement their own type combinators |
25 | 59 |
|
26 | 60 | ## References
|
27 | 61 |
|
|
0 commit comments