diff options
Diffstat (limited to 'Data')
| -rw-r--r-- | Data/GraphQL/Schema.hs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Data/GraphQL/Schema.hs b/Data/GraphQL/Schema.hs index 2646bac..e451981 100644 --- a/Data/GraphQL/Schema.hs +++ b/Data/GraphQL/Schema.hs @@ -24,7 +24,7 @@ module Data.GraphQL.Schema , Value(..) ) where -import Control.Applicative (Alternative(empty)) +import Control.Applicative (Alternative(empty), (<|>)) import Data.Foldable (fold) import Data.List.NonEmpty (NonEmpty) import Data.Maybe (fromMaybe) @@ -66,6 +66,7 @@ objectA => Name -> (Arguments -> Resolvers f) -> Resolver f objectA name f fld@(Field _ _ args flds) = withField name (resolve (f args) flds) fld + -- | Create a named 'Resolver' from a list of 'Resolver's. object' :: (Alternative f, Monad f) => Text -> f [Resolver f] -> Resolver f object' name resolvs = objectA' name $ \case @@ -136,9 +137,11 @@ enumA _ _ _ = empty withField :: (Alternative f, Aeson.ToJSON a) => Name -> f a -> Field -> f (HashMap Text Aeson.Value) -withField name f (Field alias name' _ _) = +withField name v (Field alias name' _ _) = if name == name' - then fmap (HashMap.singleton aliasOrName . Aeson.toJSON) f + then fmap (HashMap.singleton aliasOrName . Aeson.toJSON) v + -- TODO: Report error when Non-Nullable type for field argument. + <|> pure (HashMap.singleton aliasOrName Aeson.Null) else empty where aliasOrName = fromMaybe name alias |
