Skip to content

Commit 7a6caa5

Browse files
committed
Draft readme.
1 parent 6c4a6f4 commit 7a6caa5

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

README.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,59 @@
33
[![CircleCI](https://circleci.com/gh/jml/graphql-api.svg?style=shield)](https://circleci.com/gh/jml/graphql-api)
44
[![Documentation Status](https://readthedocs.org/projects/haskell-graphql-api/badge/?version=latest)](http://haskell-graphql-api.readthedocs.io/en/latest/?badge=latest)
55

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.
77

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.
99

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).
1111

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.
1313

14-
* Type-level definition of queries and schemas
15-
* Evaluation of GraphQL queries (and mutations) according to those types.
14+
## Hello world example
1615

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`:
2017

21-
## Why you might want it
18+
```haskell
19+
import Data.Text (Text)
20+
import Data.Monoid ((<>))
2221

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
2559

2660
## References
2761

0 commit comments

Comments
 (0)