Deprecate enum, enumA, wrappedEnum, wrappedEnumA

These functions are from Language.GraphQL.Schema.
There are actually only two generic types in GraphQL: Scalars and objects.
Enum is a scalar value. According to the specification enums may be
serailized to strings. And in the current implementation they used
untyped strings anyway, so there is no point to have differently named
functions with the same implementation as their scalar counterparts.
This commit is contained in:
Eugen Wissner 2019-09-01 02:53:15 +02:00
parent 22313d05df
commit 63d4de485d
5 changed files with 16 additions and 11 deletions

View File

@ -12,6 +12,9 @@ All notable changes to this project will be documented in this file.
the user separately, because the schema can originate from a GraphQL the user separately, because the schema can originate from a GraphQL
document. `Schema` name should be free to provide a data type for the real document. `Schema` name should be free to provide a data type for the real
schema later. schema later.
- `Language.GraphQL.Schema`: `enum`, `enumA`, `wrappedEnum` and `wrappedEnumA`.
There are actually only two generic types in GraphQL: Scalars and objects.
Enum is a scalar value.
## [0.5.0.0] - 2019-08-14 ## [0.5.0.0] - 2019-08-14
### Added ### Added

View File

@ -111,18 +111,17 @@ wrappedScalar :: (MonadIO m, Aeson.ToJSON a)
=> Name -> ActionT m (Wrapping a) -> Resolver m => Name -> ActionT m (Wrapping a) -> Resolver m
wrappedScalar name = wrappedScalarA name . const wrappedScalar name = wrappedScalarA name . const
-- | Represents one of a finite set of possible values. {-# DEPRECATED enum "Use scalar instead" #-}
-- Used in place of a 'scalar' when the possible responses are easily enumerable.
enum :: MonadIO m => Name -> ActionT m [Text] -> Resolver m enum :: MonadIO m => Name -> ActionT m [Text] -> Resolver m
enum name = enumA name . const enum name = enumA name . const
-- | Like 'enum' but also taking 'Argument's. {-# DEPRECATED enumA "Use scalarA instead" #-}
enumA :: MonadIO m => Name -> (Arguments -> ActionT m [Text]) -> Resolver m enumA :: MonadIO m => Name -> (Arguments -> ActionT m [Text]) -> Resolver m
enumA name f = Resolver name $ resolveFieldValue f resolveRight enumA name f = Resolver name $ resolveFieldValue f resolveRight
where where
resolveRight fld resolver = withField (return resolver) fld resolveRight fld resolver = withField (return resolver) fld
-- | Like 'enum' but also taking 'Argument's and can be null or a list of enums. {-# DEPRECATED wrappedEnumA "Use wrappedScalarA instead" #-}
wrappedEnumA :: MonadIO m wrappedEnumA :: MonadIO m
=> Name -> (Arguments -> ActionT m (Wrapping [Text])) -> Resolver m => Name -> (Arguments -> ActionT m (Wrapping [Text])) -> Resolver m
wrappedEnumA name f = Resolver name $ resolveFieldValue f resolveRight wrappedEnumA name f = Resolver name $ resolveFieldValue f resolveRight
@ -132,7 +131,7 @@ wrappedEnumA name f = Resolver name $ resolveFieldValue f resolveRight
= return $ HashMap.singleton (aliasOrName fld) Aeson.Null = return $ HashMap.singleton (aliasOrName fld) Aeson.Null
resolveRight fld (List resolver) = withField (return resolver) fld resolveRight fld (List resolver) = withField (return resolver) fld
-- | Like 'enum' but can be null or a list of enums. {-# DEPRECATED wrappedEnum "Use wrappedScalar instead" #-}
wrappedEnum :: MonadIO m => Name -> ActionT m (Wrapping [Text]) -> Resolver m wrappedEnum :: MonadIO m => Name -> ActionT m (Wrapping [Text]) -> Resolver m
wrappedEnum name = wrappedEnumA name . const wrappedEnum name = wrappedEnumA name . const

View File

@ -1,4 +1,4 @@
resolver: lts-14.3 resolver: lts-14.4
packages: packages:
- '.' - '.'
extra-deps: [] extra-deps: []

View File

@ -26,6 +26,7 @@ import Control.Monad.Trans.Except (throwE)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)
import Data.Text (Text) import Data.Text (Text)
import Language.GraphQL.Trans import Language.GraphQL.Trans
import Language.GraphQL.Type
-- * Data -- * Data
-- See https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsData.js -- See https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsData.js
@ -190,8 +191,8 @@ getDroid' _ = empty
getFriends :: Character -> [Character] getFriends :: Character -> [Character]
getFriends char = catMaybes $ liftA2 (<|>) getDroid getHuman <$> friends char getFriends char = catMaybes $ liftA2 (<|>) getDroid getHuman <$> friends char
getEpisode :: Alternative f => Int -> f Text getEpisode :: Int -> Maybe (Wrapping Text)
getEpisode 4 = pure "NEWHOPE" getEpisode 4 = pure $ Named "NEWHOPE"
getEpisode 5 = pure "EMPIRE" getEpisode 5 = pure $ Named "EMPIRE"
getEpisode 6 = pure "JEDI" getEpisode 6 = pure $ Named "JEDI"
getEpisode _ = empty getEpisode _ = empty

View File

@ -12,6 +12,7 @@ import Control.Monad.Trans.Except (throwE)
import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Class (lift)
import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.IO.Class (MonadIO(..))
import Data.List.NonEmpty (NonEmpty(..)) import Data.List.NonEmpty (NonEmpty(..))
import Data.Maybe (catMaybes)
import qualified Language.GraphQL.Schema as Schema import qualified Language.GraphQL.Schema as Schema
import Language.GraphQL.Trans import Language.GraphQL.Trans
import Language.GraphQL.Type import Language.GraphQL.Type
@ -50,7 +51,8 @@ character char = return
, Schema.scalar "name" $ return $ name char , Schema.scalar "name" $ return $ name char
, Schema.wrappedObject "friends" , Schema.wrappedObject "friends"
$ traverse character $ List $ Named <$> getFriends char $ traverse character $ List $ Named <$> getFriends char
, Schema.enum "appearsIn" $ return $ foldMap getEpisode $ appearsIn char , Schema.wrappedScalar "appearsIn" $ return . List
$ catMaybes (getEpisode <$> appearsIn char)
, Schema.scalar "secretBackstory" $ secretBackstory char , Schema.scalar "secretBackstory" $ secretBackstory char
, Schema.scalar "homePlanet" $ return $ either mempty homePlanet char , Schema.scalar "homePlanet" $ return $ either mempty homePlanet char
, Schema.scalar "__typename" $ return $ typeName char , Schema.scalar "__typename" $ return $ typeName char