diff options
| author | Danny Navarro <j@dannynavarro.net> | 2016-02-11 14:24:31 +0100 |
|---|---|---|
| committer | Danny Navarro <j@dannynavarro.net> | 2016-02-12 12:51:18 +0100 |
| commit | a088c819442800cf9cf4a2e95d5cb4bc16584029 (patch) | |
| tree | cb1eda5b7a81e9fd146dc067c2d7b62ed55e8aa2 /Data/GraphQL/Schema.hs | |
| parent | 70fbaf359ec5b3a88573fdbc5bd90c402a3ebce0 (diff) | |
| download | graphql-a088c819442800cf9cf4a2e95d5cb4bc16584029.tar.gz | |
Handle Field arguments in Schema definition
The `Schema` has been overhauled to make `Output` monomorphic.
Traversing the `GraphQL` document is handled implicitly while defining
the `Schema`.
The 4th end-to-end test from `graphql-js` has been ported.
Diffstat (limited to 'Data/GraphQL/Schema.hs')
| -rw-r--r-- | Data/GraphQL/Schema.hs | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/Data/GraphQL/Schema.hs b/Data/GraphQL/Schema.hs index 8a6e625..8ceb11f 100644 --- a/Data/GraphQL/Schema.hs +++ b/Data/GraphQL/Schema.hs @@ -1,35 +1,34 @@ +{-# LANGUAGE CPP #-} module Data.GraphQL.Schema where -import Data.Maybe (catMaybes) +#if !MIN_VERSION_base(4,8,0) +import Control.Applicative ((<$>)) +#endif -import Data.Text (Text) import Data.Aeson (ToJSON(toJSON)) +import Data.HashMap.Strict (HashMap) +import Data.Text (Text) data Schema f = Schema (QueryRoot f) -- (Maybe MutationRoot) type QueryRoot f = Resolver f -type Resolver f = Input -> f (Output f) +type Resolver f = Input -> f Output -data Output f = OutputResolver (Resolver f) - | OutputList (f [Output f]) - | OutputScalar (f Scalar) - | OutputEnum (f Text) +data Output = OutputObject (HashMap Text Output) + | OutputList [Output] + | OutputScalar Scalar + | OutputEnum Text + deriving (Show) -- | OutputUnion [Output] -- | OutputNonNull (Output) -data Input = InputScalar Scalar - | InputField Text - | InputList [Input] - deriving (Show) - -field :: Input -> Maybe Text -field (InputField x) = Just x -field _ = Nothing +type Argument = (Text, Scalar) -fields :: [Input] -> [Text] -fields = catMaybes . fmap field +data Input = InputField Text [Argument] [Input] + deriving (Show) +-- TODO: Make ScalarInt Int32 data Scalar = ScalarInt Int | ScalarFloat Double | ScalarString Text @@ -43,3 +42,10 @@ instance ToJSON Scalar where toJSON (ScalarString x) = toJSON x toJSON (ScalarBoolean x) = toJSON x toJSON (ScalarID x) = toJSON x + +instance ToJSON Output where + toJSON (OutputObject x) = toJSON $ toJSON <$> x + toJSON (OutputList x) = toJSON $ toJSON <$> x + toJSON (OutputScalar x) = toJSON x + toJSON (OutputEnum x) = toJSON x + |
