Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hendrikniemann/purescript-graphql
End to End typesafe GraphQL with PureScript
https://github.com/hendrikniemann/purescript-graphql
api graphql purescript typesafe
Last synced: 3 months ago
JSON representation
End to End typesafe GraphQL with PureScript
- Host: GitHub
- URL: https://github.com/hendrikniemann/purescript-graphql
- Owner: hendrikniemann
- License: mit
- Created: 2018-08-05T23:21:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-14T12:26:24.000Z (7 months ago)
- Last Synced: 2024-04-14T14:04:06.876Z (7 months ago)
- Topics: api, graphql, purescript, typesafe
- Language: PureScript
- Homepage: https://hendrikniemann.github.io/purescript-graphql
- Size: 286 KB
- Stars: 95
- Watchers: 8
- Forks: 10
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - purescript-graphql
README
# Purescript GraphQL
[![License](https://img.shields.io/github/license/hendrikniemann/purescript-graphql.svg)](https://github.com/hendrikniemann/purescript-graphql/blob/master/LICENSE)
PureScript GraphQL is a [GraphQL](https://graphql.org) implementation written in PureScript. It features a powerful DSL that makes building GraphQL servers as typesafe as possible.
> ### 🚧 Full rewrite happening 🚧
>
> This is a complete rewrite of PureScript GraphQL. If you are looking for version 1 of PureScript GraphQL make sure to check out the [1.0.2 tag](https://github.com/hendrikniemann/purescript-graphql/tree/v1.0.2).To follow the roadmap to version 2 check out the [milestone](https://github.com/hendrikniemann/purescript-graphql/milestone/1)
## Getting started
If you are new to PureScript GraphQL I highly recommend to follow the [tutorial](https://hendrikniemann.github.io/purescript-graphql/). ~~If you know what you are doing you can simply install `purescript-graphql` with spago.~~ (Not in the package set yet, will be done as soon as beta is out)
```
spago install graphql
```## Basic example
This code creates a simple schema with one query field.
The field takes one argument `name` and returns a string.```purescript
module Main whereimport Prelude
import Data.Argonaut (stringify)
import Data.Map as Map
import Effect (Effect)
import Effect.Console as Console
import GraphQL ((!>), (.>), (:>), (?>), graphql)
import GraphQL as GraphQLmain :: Effect Unit
main = do
result <- graphql schema """{ hello(name: "world") }""" Map.empty Nothing unit
Console.log $ stringify result -- {"data":{"hello":"world"}}schema :: GraphQL.Schema Effect Unit
schema = GraphQL.Schema { query: queryType, mutation: Nothing }queryType :: GraphQL.ObjectType (ReaderT String Effect) Unit
queryType =
GraphQL.objectType "Query"
:> "The root query type."
.> GraphQL.field "hello" GraphQL.string
?> GraphQL.arg @"name" GraphQL.string
:> "A simple field that returns a greeting."
!> (\{ name } _ -> pure $ "Hello, " <> name <> "!")
```