diff options
Diffstat (limited to 'Data/GraphQL/Schema.hs')
| -rw-r--r-- | Data/GraphQL/Schema.hs | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/Data/GraphQL/Schema.hs b/Data/GraphQL/Schema.hs index 37938ee..08ddaa1 100644 --- a/Data/GraphQL/Schema.hs +++ b/Data/GraphQL/Schema.hs @@ -1,33 +1,48 @@ module Data.GraphQL.Schema where -import Data.Text (Text) -import Data.HashMap.Lazy (HashMap) - -data Schema f = Schema (QueryRoot f) (Maybe (MutationRoot f)) +import Data.Maybe (catMaybes) +import Text.Show.Functions () -type QueryRoot f = Map f +import Data.Text (Text) +import Data.Aeson (ToJSON(toJSON)) -type MutationRoot f = Map f +data Schema = Schema QueryRoot -- (Maybe MutationRoot) -type Map f = HashMap Text (Resolver f) +type QueryRoot = Resolver -type Resolver f = Input -> Output f +type Resolver = Input -> Output -data Output f = OutputScalar (f Scalar) - | OutputMap (Map f) - | OutputUnion [Map f] - | OutputEnum (f Scalar) - | OutputList [Output f] - | OutputNonNull (Output f) - | InputError +data Output = OutputResolver Resolver + | OutputList [Output] + | OutputScalar Scalar + -- | OutputUnion [Output] + -- | OutputEnum [Scalar] + -- | OutputNonNull (Output) + | OutputError + deriving (Show) data Input = InputScalar Scalar - | InputEnum Scalar + | InputField Text | InputList [Input] - | InputNonNull Input - -data Scalar = ScalarInt Int - | ScalarFloat Double - | ScalarString Text - | ScalarBool Bool - | ScalarID Text + 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 |
