2016-02-19 19:21:32 +01:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
{-# LANGUAGE LambdaCase #-}
|
2016-02-12 13:27:46 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Test.StarWars.Schema where
|
|
|
|
|
2016-02-19 19:21:32 +01:00
|
|
|
import Control.Applicative (Alternative, empty)
|
2016-02-12 13:27:46 +01:00
|
|
|
|
2016-02-19 19:21:32 +01:00
|
|
|
#if !MIN_VERSION_base(4,8,0)
|
|
|
|
import Control.Applicative ((<$>))
|
|
|
|
import Data.Traversable (traverse)
|
|
|
|
#endif
|
2016-02-12 13:27:46 +01:00
|
|
|
import Data.GraphQL.Schema
|
2016-02-19 19:21:32 +01:00
|
|
|
import qualified Data.GraphQL.Schema as Schema
|
2016-02-12 13:27:46 +01:00
|
|
|
|
|
|
|
import Test.StarWars.Data
|
|
|
|
|
|
|
|
-- * Schema
|
|
|
|
-- See https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsSchema.js
|
|
|
|
|
2016-02-19 19:21:32 +01:00
|
|
|
schema :: Alternative f => Schema f
|
|
|
|
schema = Schema [hero, human, droid]
|
|
|
|
|
|
|
|
hero :: Alternative f => Resolver f
|
|
|
|
hero = Schema.objectA "hero" $ \case
|
|
|
|
[] -> character artoo
|
|
|
|
[Argument "episode" (ValueInt n)] -> character $ getHero (fromIntegral n)
|
|
|
|
_ -> empty
|
|
|
|
|
|
|
|
human :: Alternative f => Resolver f
|
|
|
|
human = Schema.objectA "human" $ \case
|
2016-02-22 13:59:38 +01:00
|
|
|
[Argument "id" (ValueString i)] -> character =<< getHuman i
|
2016-02-19 19:21:32 +01:00
|
|
|
_ -> empty
|
|
|
|
|
|
|
|
droid :: Alternative f => Resolver f
|
|
|
|
droid = Schema.objectA "droid" $ \case
|
2016-02-22 13:59:38 +01:00
|
|
|
[Argument "id" (ValueString i)] -> character =<< getDroid i
|
2016-02-19 19:21:32 +01:00
|
|
|
_ -> empty
|
|
|
|
|
|
|
|
character :: Alternative f => Character -> [Resolver f]
|
|
|
|
character char =
|
|
|
|
[ Schema.scalar "id" $ id_ char
|
|
|
|
, Schema.scalar "name" $ name char
|
|
|
|
, Schema.array "friends" $ character <$> getFriends char
|
|
|
|
, Schema.enum "appearsIn" . traverse getEpisode $ appearsIn char
|
2016-07-08 23:50:31 +02:00
|
|
|
, Schema.scalar "secretBackstory" $ secretBackstory char
|
2016-02-19 19:21:32 +01:00
|
|
|
]
|