Skip to content

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

License

Notifications You must be signed in to change notification settings

gabiseabra/hs-graphql

Repository files navigation

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:

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:

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:

instance GraphQLInputKind GraphQLScalar where
  readInputType Scalar = fromJSON
instance GraphQLOutputKind m GraphQLScalar where
  resolve Scalar = Leaf . toJson

todo

  • kinds
    • scalars
    • enums
    • objects
    • input objects
    • unions
    • interfaces
    • lists
    • nullable
  • parsing
  • validation
  • resolvers
    • resolve objects recursively
    • 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published