diff options
| author | Danny Navarro <j@dannynavarro.net> | 2017-03-03 20:39:03 -0300 |
|---|---|---|
| committer | Danny Navarro <j@dannynavarro.net> | 2017-03-03 17:02:19 -0300 |
| commit | 2b5648efda40e28ae652ff6c27ac012edda0472e (patch) | |
| tree | 664db4121ff56b516a87d6dd00df06951d971efa /Data/GraphQL/Schema.hs | |
| parent | fb071210cfd163bf8ee97448b7976ab4bdf1ed50 (diff) | |
| download | graphql-2b5648efda40e28ae652ff6c27ac012edda0472e.tar.gz | |
When argument is not found return null
The relevant test was restored too.
Diffstat (limited to 'Data/GraphQL/Schema.hs')
| -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 |
