Purescript Graphql Save

End to End typesafe GraphQL with PureScript

Project README

Purescript GraphQL

License

PureScript GraphQL is a GraphQL 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.

To follow the roadmap to version 2 check out the milestone

Getting started

If you are new to PureScript GraphQL I highly recommend to follow the tutorial. 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.

module Main where

import Prelude

import Data.Argonaut (stringify)
import Data.Map as Map
import Effect (Effect)
import Effect.Console as Console
import GraphQL ((!>), (.>), (:>), (?>), graphql)
import GraphQL as GraphQL

main :: 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 <> "!")
Open Source Agenda is not affiliated with "Purescript Graphql" Project. README Source: hendrikniemann/purescript-graphql
Stars
95
Open Issues
12
Last Commit
1 month ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating