From 8b164c4844da128dc5119febc3defb1ebdf2cc3a Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 30 Jun 2020 10:28:10 +0200 Subject: [PATCH] Move Core module out of AST --- CHANGELOG.md | 6 ++++++ src/Language/GraphQL/AST.hs | 4 +++- src/Language/GraphQL/AST/Core.hs | 19 ------------------- src/Language/GraphQL/Execute/Execution.hs | 3 +-- src/Language/GraphQL/Execute/Transform.hs | 3 +-- src/Language/GraphQL/Trans.hs | 1 - src/Language/GraphQL/Type/Definition.hs | 13 ++++++++++++- src/Language/GraphQL/Type/Directive.hs | 1 - 8 files changed, 23 insertions(+), 27 deletions(-) delete mode 100644 src/Language/GraphQL/AST/Core.hs diff --git a/CHANGELOG.md b/CHANGELOG.md index c3609e5..5f3907c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,15 @@ and this project adheres to [Haskell Package Versioning Policy](https://pvp.haskell.org/). ## [Unreleased] +## Added +- `AST` reexports `AST.Parser`. + ## Changed - `Trans.ActionT` is renamed to `ResolverT`. Since `Type.Out.Resolver` has gone it is a better name for GraphQL resolvers. +- `AST.Core` contained only `Arguments` which was moved to `Type.Definition`. + `AST` provides now only functionality related to parsing and encoding, as it + should be. ## Removed - `Type.Out.Resolver`: It is an unneeded layer of complexity. Resolvers are a diff --git a/src/Language/GraphQL/AST.hs b/src/Language/GraphQL/AST.hs index aba6dfd..3d368d4 100644 --- a/src/Language/GraphQL/AST.hs +++ b/src/Language/GraphQL/AST.hs @@ -1,6 +1,8 @@ --- | Target AST for Parser. +-- | Target AST for parser. module Language.GraphQL.AST ( module Language.GraphQL.AST.Document + , module Language.GraphQL.AST.Parser ) where import Language.GraphQL.AST.Document +import Language.GraphQL.AST.Parser diff --git a/src/Language/GraphQL/AST/Core.hs b/src/Language/GraphQL/AST/Core.hs deleted file mode 100644 index 0fe3e03..0000000 --- a/src/Language/GraphQL/AST/Core.hs +++ /dev/null @@ -1,19 +0,0 @@ --- | This is the AST meant to be executed. -module Language.GraphQL.AST.Core - ( Arguments(..) - ) where - -import Data.HashMap.Strict (HashMap) -import Language.GraphQL.AST (Name) -import Language.GraphQL.Type.Definition - --- | Argument list. -newtype Arguments = Arguments (HashMap Name Value) - deriving (Eq, Show) - -instance Semigroup Arguments where - (Arguments x) <> (Arguments y) = Arguments $ x <> y - -instance Monoid Arguments where - mempty = Arguments mempty - diff --git a/src/Language/GraphQL/Execute/Execution.hs b/src/Language/GraphQL/Execute/Execution.hs index 0291bf8..5e53311 100644 --- a/src/Language/GraphQL/Execute/Execution.hs +++ b/src/Language/GraphQL/Execute/Execution.hs @@ -19,7 +19,6 @@ import Data.Maybe (fromMaybe) import Data.Sequence (Seq(..)) import Data.Text (Text) import Language.GraphQL.AST (Name) -import Language.GraphQL.AST.Core import Language.GraphQL.Error import Language.GraphQL.Execute.Coerce import qualified Language.GraphQL.Execute.Transform as Transform @@ -36,7 +35,7 @@ resolveFieldValue :: Monad m -> ResolverT m a -> m (Either Text a) resolveFieldValue result args = - flip runReaderT (Context {arguments = Arguments args, values = result}) + flip runReaderT (Context {arguments = Type.Arguments args, values = result}) . runExceptT . runResolverT diff --git a/src/Language/GraphQL/Execute/Transform.hs b/src/Language/GraphQL/Execute/Transform.hs index 733ac8c..79ee855 100644 --- a/src/Language/GraphQL/Execute/Transform.hs +++ b/src/Language/GraphQL/Execute/Transform.hs @@ -44,7 +44,6 @@ import Data.Text (Text) import qualified Data.Text as Text import qualified Language.GraphQL.AST as Full import Language.GraphQL.AST (Name) -import Language.GraphQL.AST.Core import qualified Language.GraphQL.Execute.Coerce as Coerce import Language.GraphQL.Type.Directive (Directive(..)) import qualified Language.GraphQL.Type.Directive as Directive @@ -341,7 +340,7 @@ directives :: [Full.Directive] -> State (Replacement m) [Directive] directives = traverse directive where directive (Full.Directive directiveName directiveArguments) - = Directive directiveName . Arguments + = Directive directiveName . Type.Arguments <$> foldM go HashMap.empty directiveArguments go arguments (Full.Argument name value') = do substitutedValue <- value value' diff --git a/src/Language/GraphQL/Trans.hs b/src/Language/GraphQL/Trans.hs index 2ec13be..a55ac49 100644 --- a/src/Language/GraphQL/Trans.hs +++ b/src/Language/GraphQL/Trans.hs @@ -15,7 +15,6 @@ import qualified Data.HashMap.Strict as HashMap import Data.Maybe (fromMaybe) import Data.Text (Text) import Language.GraphQL.AST (Name) -import Language.GraphQL.AST.Core import Language.GraphQL.Type.Definition import Prelude hiding (lookup) diff --git a/src/Language/GraphQL/Type/Definition.hs b/src/Language/GraphQL/Type/Definition.hs index 1379018..40055e7 100644 --- a/src/Language/GraphQL/Type/Definition.hs +++ b/src/Language/GraphQL/Type/Definition.hs @@ -2,7 +2,8 @@ -- | Types that can be used as both input and output types. module Language.GraphQL.Type.Definition - ( EnumType(..) + ( Arguments(..) + , EnumType(..) , EnumValue(..) , ScalarType(..) , Subs @@ -40,6 +41,16 @@ instance IsString Value where -- and the value is the variable value. type Subs = HashMap Name Value +-- | Argument list. +newtype Arguments = Arguments (HashMap Name Value) + deriving (Eq, Show) + +instance Semigroup Arguments where + (Arguments x) <> (Arguments y) = Arguments $ x <> y + +instance Monoid Arguments where + mempty = Arguments mempty + -- | Scalar type definition. -- -- The leaf values of any request and input values to arguments are Scalars (or diff --git a/src/Language/GraphQL/Type/Directive.hs b/src/Language/GraphQL/Type/Directive.hs index 017132c..6ff73d4 100644 --- a/src/Language/GraphQL/Type/Directive.hs +++ b/src/Language/GraphQL/Type/Directive.hs @@ -7,7 +7,6 @@ module Language.GraphQL.Type.Directive import qualified Data.HashMap.Strict as HashMap import Language.GraphQL.AST (Name) -import Language.GraphQL.AST.Core import Language.GraphQL.Type.Definition -- | Directive.