https://github.com/gabiseabra/hs-graphql
[WIP] An experimental library for deriving GraphQL schema documents, parsing requests and type-checking them against the schema, and executing the requests against Haskell handlers compatible with the type declarations, all inferred from Haskell types and compliant with GraphQL specs.
https://github.com/gabiseabra/hs-graphql
graphql graphql-server haskell
Last synced: 6 months ago
JSON representation
[WIP] An experimental library for deriving GraphQL schema documents, parsing requests and type-checking them against the schema, and executing the requests against Haskell handlers compatible with the type declarations, all inferred from Haskell types and compliant with GraphQL specs.
- Host: GitHub
- URL: https://github.com/gabiseabra/hs-graphql
- Owner: gabiseabra
- License: bsd-3-clause
- Created: 2021-07-14T02:56:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-04T17:34:07.000Z (about 3 years ago)
- Last Synced: 2025-01-05T23:22:53.488Z (about 1 year ago)
- Topics: graphql, graphql-server, haskell
- Language: Haskell
- Homepage:
- Size: 278 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hs-graphql
wip
## components of the type system
### types
This is the public api through which haskell data types may implement a GraphQL type of some kind.
This is done by implementing an instance of `GraphQLType`:
```hs
newtype ID = ID String deriving (FromJSON, ToJSON)
instance GraphQLType ID where
type KindOf ID = GraphQLScalar
typename _ = "ID"
```
### kinds
A graphql kind is a proxy type, such as the `GraphQLScalar` in the example above, that generally carries a dictionary of instances from its carrier type to be used for resolution and introspection.
Type kinds can also be extended by implementing `GraphQLKind`, which translates its argument into a graphql type definition, and `GraphQLTypeable` which defines how to instantiate the proxy data type:
```hs
data GraphQLScalar a where
Scalar :: (FromJSON a, ToJSON a) => Scalar a
instance GraphQLKind GraphQLScalar where
type Kind GraphQLScalar = SCALAR
typeDef Scalar = ScalarDef
instance (FromJSON a , ToJSON a) => GraphQLTypeable GraphQLScalar a where
typeOf = Scalar
```
To plug its carrier type into an executable resolver it must further implement `GraphQLInputKind`, `GraphQLOutputKind`, or both depending on its `Kind` type. Such is the case for scalars:
```hs
instance GraphQLInputKind GraphQLScalar where
readInputType Scalar = fromJSON
instance GraphQLOutputKind m GraphQLScalar where
resolve Scalar = Leaf . toJson
```
## todo
- [ ] kinds
- [x] scalars
- [x] enums
- [x] objects
- [x] input objects
- [x] unions
- [ ] interfaces
- [x] lists
- [x] nullable
- [x] parsing
- [x] validation
- [x] resolvers
- [x] resolve objects recursively
- [x] apply inputs
- [ ] error handling
- [ ] batching
- [ ] subscriptions
- [ ] root resolver
- [ ] map operation types to their respective resolvers
- [ ] extract all types defined in the resolvers recursively
- [ ] schema introspection