Home<!-- --> | Morpheus GraphQL<!-
Morpheus GraphQL

Build GraphQL APIs with your favorite functional language!
Morpheus GraphQL (Server & Client) helps you to build GraphQL APIs in Haskell with native Haskell types. Morpheus will convert your Haskell types to a GraphQL schema and all your resolvers are just native Haskell functions. Morpheus GraphQL can also convert your GraphQL Schema or Query to Haskell types and validate them in compile time.
Morpheus is still in an early stage of development, so any feedback is more than welcome, and we appreciate any contribution! Just open an issue here on GitHub, or join our Slack channel to get in touch.
Getting Started
Setup
To get started with Morpheus, you first need to add it to your project's dependencies, as follows (assuming you're using hpack):
package.yml
Additionally, you should tell stack which version to pick:
stack.yml
As Morpheus is quite new, make sure stack can find morpheus-graphql by running stack upgrade and stack update
Building your first GraphQL API
with GraphQL syntax
schema.gql
API.hs
Template Haskell Generates types: Query , Deity, DeityArgs, that can be used by rootResolver
descriptions and deprecations will be displayed in introspection.
importGQLDocumentWithNamespace will generate Types with namespaced fields. If you don't need namespace use importGQLDocument
with Native Haskell Types
To define a GraphQL API with Morpheus we start by defining the API Schema as a native Haskell data type,
which derives the Generic typeClass. Lazily resolvable fields on this Query type are defined via a -> ResolverQ () IO b, representing resolving a set of arguments a to a concrete value b.
For each field in the Query type defined via a -> m b (like deity) we will define a resolver implementation that provides the values during runtime by referring to
some data source, e.g. a database or another API. Fields that are defined without a -> m b you can just provide a value.
In above example, the field of DeityArgs could also be named using reserved identities (such as: type, where, etc), in order to avoid conflict, a prime symbol (') must be attached. For example, you can have:
The field name in the final request will be type instead of type'. The Morpheus request parser converts each of the reserved identities in Haskell 2010 to their corresponding names internally. This also applies to selections.
To make this Query type available as an API, we define a RootResolver and feed it to the Morpheus interpreter. A RootResolver consists of query, mutation and subscription definitions, while we omit the latter for this example:
As you can see, the API is defined as ByteString -> IO ByteString which we can either invoke directly or use inside an arbitrary web framework
such as scotty or serverless-haskell. We'll go for scotty in this example:
If we now send a POST request to http://localhost:3000/api with a GraphQL Query as body for example in a tool like Insomnia:
our query will be resolved!
Advanced topics
Introspection
Morpheus converts your schema to a GraphQL introspection automatically. You can use tools like Insomnia to take a
look at the introspection and validate your schema.
If you need a description for your GQLType inside of the introspection you can define the GQLType instance manually
and apply Describe directive to it:
screenshots from Insomnia

About
The name
Morpheus is the greek god of sleep and dreams whose name comes from the Greek word μορφή meaning form or shape. He is said to be able to mimic different forms and GraphQL is good at doing exactly that: Transforming data in the shape of many different APIs.
Team
Morpheus is written and maintained by nalchevanidze
Roadmap
- Medium future:
- Stabilize API
- Specification-isomorphic error handling
- Long term:
- Support all possible GQL features
- Performance optimization