2015-10-17 13:19:00 +02:00
|
|
|
module Data.GraphQL.Schema where
|
|
|
|
|
2016-01-26 12:43:18 +01:00
|
|
|
import Data.Maybe (catMaybes)
|
|
|
|
import Text.Show.Functions ()
|
2015-10-17 13:19:00 +02:00
|
|
|
|
2016-01-26 12:43:18 +01:00
|
|
|
import Data.Text (Text)
|
|
|
|
import Data.Aeson (ToJSON(toJSON))
|
2015-10-17 13:19:00 +02:00
|
|
|
|
2016-01-26 13:38:02 +01:00
|
|
|
-- TODO: Support side-effects
|
|
|
|
|
2016-01-26 12:43:18 +01:00
|
|
|
data Schema = Schema QueryRoot -- (Maybe MutationRoot)
|
2015-10-17 13:19:00 +02:00
|
|
|
|
2016-01-26 12:43:18 +01:00
|
|
|
type QueryRoot = Resolver
|
2015-10-17 13:19:00 +02:00
|
|
|
|
2016-01-26 12:43:18 +01:00
|
|
|
type Resolver = Input -> Output
|
2015-10-17 13:19:00 +02:00
|
|
|
|
2016-01-26 12:43:18 +01:00
|
|
|
data Output = OutputResolver Resolver
|
|
|
|
| OutputList [Output]
|
|
|
|
| OutputScalar Scalar
|
|
|
|
-- | OutputUnion [Output]
|
|
|
|
-- | OutputEnum [Scalar]
|
|
|
|
-- | OutputNonNull (Output)
|
|
|
|
| OutputError
|
|
|
|
deriving (Show)
|
2015-10-17 13:19:00 +02:00
|
|
|
|
|
|
|
data Input = InputScalar Scalar
|
2016-01-26 12:43:18 +01:00
|
|
|
| InputField Text
|
2015-10-19 12:19:39 +02:00
|
|
|
| InputList [Input]
|
2016-01-26 12:43:18 +01:00
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
field :: Input -> Maybe Text
|
|
|
|
field (InputField x) = Just x
|
|
|
|
field _ = Nothing
|
|
|
|
|
|
|
|
fields :: [Input] -> [Text]
|
|
|
|
fields = catMaybes . fmap field
|
|
|
|
|
|
|
|
data Scalar = ScalarInt Int
|
|
|
|
| ScalarFloat Double
|
|
|
|
| ScalarString Text
|
|
|
|
| ScalarBoolean Bool
|
|
|
|
| ScalarID Text
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
instance ToJSON Scalar where
|
|
|
|
toJSON (ScalarInt x) = toJSON x
|
|
|
|
toJSON (ScalarFloat x) = toJSON x
|
|
|
|
toJSON (ScalarString x) = toJSON x
|
|
|
|
toJSON (ScalarBoolean x) = toJSON x
|
|
|
|
toJSON (ScalarID x) = toJSON x
|