diff --git a/CHANGELOG.md b/CHANGELOG.md index dca4622..9494208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 document. `Schema` name should be free to provide a data type for the real 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 ### Added diff --git a/src/Language/GraphQL/Schema.hs b/src/Language/GraphQL/Schema.hs index 3170a32..428b80e 100644 --- a/src/Language/GraphQL/Schema.hs +++ b/src/Language/GraphQL/Schema.hs @@ -111,18 +111,17 @@ wrappedScalar :: (MonadIO m, Aeson.ToJSON a) => Name -> ActionT m (Wrapping a) -> Resolver m wrappedScalar name = wrappedScalarA name . const --- | Represents one of a finite set of possible values. --- Used in place of a 'scalar' when the possible responses are easily enumerable. +{-# DEPRECATED enum "Use scalar instead" #-} enum :: MonadIO m => Name -> ActionT m [Text] -> Resolver m 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 name f = Resolver name $ resolveFieldValue f resolveRight where 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 => Name -> (Arguments -> ActionT m (Wrapping [Text])) -> Resolver m 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 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 name = wrappedEnumA name . const diff --git a/stack.yaml b/stack.yaml index 68eb5fc..8d94ebc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-14.3 +resolver: lts-14.4 packages: - '.' extra-deps: [] diff --git a/tests/Test/StarWars/Data.hs b/tests/Test/StarWars/Data.hs index 55ff207..6a514c5 100644 --- a/tests/Test/StarWars/Data.hs +++ b/tests/Test/StarWars/Data.hs @@ -26,6 +26,7 @@ import Control.Monad.Trans.Except (throwE) import Data.Maybe (catMaybes) import Data.Text (Text) import Language.GraphQL.Trans +import Language.GraphQL.Type -- * Data -- See https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsData.js @@ -190,8 +191,8 @@ getDroid' _ = empty getFriends :: Character -> [Character] getFriends char = catMaybes $ liftA2 (<|>) getDroid getHuman <$> friends char -getEpisode :: Alternative f => Int -> f Text -getEpisode 4 = pure "NEWHOPE" -getEpisode 5 = pure "EMPIRE" -getEpisode 6 = pure "JEDI" +getEpisode :: Int -> Maybe (Wrapping Text) +getEpisode 4 = pure $ Named "NEWHOPE" +getEpisode 5 = pure $ Named "EMPIRE" +getEpisode 6 = pure $ Named "JEDI" getEpisode _ = empty diff --git a/tests/Test/StarWars/Schema.hs b/tests/Test/StarWars/Schema.hs index 0a19085..f516f2a 100644 --- a/tests/Test/StarWars/Schema.hs +++ b/tests/Test/StarWars/Schema.hs @@ -12,6 +12,7 @@ import Control.Monad.Trans.Except (throwE) import Control.Monad.Trans.Class (lift) import Control.Monad.IO.Class (MonadIO(..)) import Data.List.NonEmpty (NonEmpty(..)) +import Data.Maybe (catMaybes) import qualified Language.GraphQL.Schema as Schema import Language.GraphQL.Trans import Language.GraphQL.Type @@ -50,7 +51,8 @@ character char = return , Schema.scalar "name" $ return $ name char , Schema.wrappedObject "friends" $ 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 "homePlanet" $ return $ either mempty homePlanet char , Schema.scalar "__typename" $ return $ typeName char