Export resolver exceptions
This commit is contained in:
parent
1b9d8af932
commit
4bd243b7ec
@ -9,6 +9,9 @@ and this project adheres to
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
- `ToGraphQL` and `FromGraphQL` instances for `Word`.
|
- `ToGraphQL` and `FromGraphQL` instances for `Word`.
|
||||||
|
- `Resolver`: Export `ServerException`.
|
||||||
|
- `Resolver.defaultResolver`: Throw `FieldNotResolvedException` if the requested
|
||||||
|
field is not in the parent object.
|
||||||
|
|
||||||
## [1.0.1.0] - 2023-02-17
|
## [1.0.1.0] - 2023-02-17
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
packages:
|
|
||||||
.
|
|
||||||
|
|
||||||
constraints: graphql -json
|
|
@ -38,7 +38,7 @@ library
|
|||||||
containers ^>= 0.6.2,
|
containers ^>= 0.6.2,
|
||||||
exceptions ^>= 0.10.4,
|
exceptions ^>= 0.10.4,
|
||||||
hspec-expectations >= 0.8.2 && < 0.9,
|
hspec-expectations >= 0.8.2 && < 0.9,
|
||||||
graphql >= 1.0,
|
graphql >= 1.2,
|
||||||
megaparsec >= 9.0 && < 10,
|
megaparsec >= 9.0 && < 10,
|
||||||
scientific ^>= 0.3.7,
|
scientific ^>= 0.3.7,
|
||||||
text >= 1.2 && < 3,
|
text >= 1.2 && < 3,
|
||||||
|
@ -6,13 +6,14 @@
|
|||||||
|
|
||||||
-- | Helper functions and exceptions to write resolvers.
|
-- | Helper functions and exceptions to write resolvers.
|
||||||
module Language.GraphQL.Resolver
|
module Language.GraphQL.Resolver
|
||||||
( argument
|
( ServerException(..)
|
||||||
|
, argument
|
||||||
, defaultResolver
|
, defaultResolver
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Catch (Exception(..), MonadCatch(..), MonadThrow(..))
|
import Control.Monad.Catch (Exception(..), MonadCatch(..), MonadThrow(..))
|
||||||
import Control.Monad.Trans.Reader (ReaderT, asks)
|
import Control.Monad.Trans.Reader (ReaderT, asks)
|
||||||
import Data.HashMap.Strict ((!))
|
import qualified Data.HashMap.Strict as HashMap
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import Data.Typeable (cast)
|
import Data.Typeable (cast)
|
||||||
@ -49,7 +50,8 @@ defaultResolver :: MonadCatch m => Name -> Type.Resolve m
|
|||||||
defaultResolver fieldName = do
|
defaultResolver fieldName = do
|
||||||
values' <- asks Type.values
|
values' <- asks Type.values
|
||||||
case values' of
|
case values' of
|
||||||
Type.Object objectValue -> pure $ objectValue ! fieldName
|
Type.Object objectValue
|
||||||
|
| Just result <- HashMap.lookup fieldName objectValue -> pure result
|
||||||
_nonObject -> throwM $ FieldNotResolvedException fieldName
|
_nonObject -> throwM $ FieldNotResolvedException fieldName
|
||||||
|
|
||||||
-- | Takes an argument name, validates that the argument exists, and optionally
|
-- | Takes an argument name, validates that the argument exists, and optionally
|
||||||
|
Loading…
Reference in New Issue
Block a user