From 0cbe69736be1ce4e7e4d82ba70f97d5a2bdcdd0c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 17 Dec 2019 09:03:18 +0100 Subject: Move Execute.Directive to Type.Directive Just to roughly follow the structure of the reference implementation. --- package.yaml | 2 +- src/Language/GraphQL/Execute/Directive.hs | 50 ------------------------------- src/Language/GraphQL/Execute/Transform.hs | 2 +- src/Language/GraphQL/Type/Directive.hs | 50 +++++++++++++++++++++++++++++++ stack.yaml | 2 +- 5 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 src/Language/GraphQL/Execute/Directive.hs create mode 100644 src/Language/GraphQL/Type/Directive.hs diff --git a/package.yaml b/package.yaml index dff96d4..88a7238 100644 --- a/package.yaml +++ b/package.yaml @@ -38,7 +38,7 @@ library: source-dirs: src other-modules: - Language.GraphQL.Execute.Transform - - Language.GraphQL.Execute.Directive + - Language.GraphQL.Type.Directive tests: tasty: diff --git a/src/Language/GraphQL/Execute/Directive.hs b/src/Language/GraphQL/Execute/Directive.hs deleted file mode 100644 index 733b6cf..0000000 --- a/src/Language/GraphQL/Execute/Directive.hs +++ /dev/null @@ -1,50 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Language.GraphQL.Execute.Directive - ( selection - ) where - -import qualified Data.HashMap.Strict as HashMap -import Language.GraphQL.AST.Core - --- | Directive processing status. -data Status - = Skip -- ^ Skip the selection and stop directive processing - | Include Directive -- ^ The directive was processed, try other handlers - | Continue Directive -- ^ Directive handler mismatch, try other handlers - --- | Takes a list of directives, handles supported directives and excludes them --- from the result. If the selection should be skipped, returns 'Nothing'. -selection :: [Directive] -> Maybe [Directive] -selection = foldr go (Just []) - where - go directive' directives' = - case (skip . include) (Continue directive') of - (Include _) -> directives' - Skip -> Nothing - (Continue x) -> (x :) <$> directives' - -handle :: (Directive -> Status) -> Status -> Status -handle _ Skip = Skip -handle handler (Continue directive) = handler directive -handle handler (Include directive) = handler directive - --- * Directive implementations - -skip :: Status -> Status -skip = handle skip' - where - skip' directive'@(Directive "skip" (Arguments arguments)) = - case HashMap.lookup "if" arguments of - (Just (Boolean True)) -> Skip - _ -> Include directive' - skip' directive' = Continue directive' - -include :: Status -> Status -include = handle include' - where - include' directive'@(Directive "include" (Arguments arguments)) = - case HashMap.lookup "if" arguments of - (Just (Boolean True)) -> Include directive' - _ -> Skip - include' directive' = Continue directive' diff --git a/src/Language/GraphQL/Execute/Transform.hs b/src/Language/GraphQL/Execute/Transform.hs index 9bcb3b2..882b324 100644 --- a/src/Language/GraphQL/Execute/Transform.hs +++ b/src/Language/GraphQL/Execute/Transform.hs @@ -19,8 +19,8 @@ import qualified Data.List.NonEmpty as NonEmpty import Data.Sequence (Seq, (<|), (><)) import qualified Language.GraphQL.AST as Full import qualified Language.GraphQL.AST.Core as Core -import qualified Language.GraphQL.Execute.Directive as Directive import qualified Language.GraphQL.Schema as Schema +import qualified Language.GraphQL.Type.Directive as Directive -- | Associates a fragment name with a list of 'Core.Field's. data Replacement = Replacement diff --git a/src/Language/GraphQL/Type/Directive.hs b/src/Language/GraphQL/Type/Directive.hs new file mode 100644 index 0000000..afd97da --- /dev/null +++ b/src/Language/GraphQL/Type/Directive.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Language.GraphQL.Type.Directive + ( selection + ) where + +import qualified Data.HashMap.Strict as HashMap +import Language.GraphQL.AST.Core + +-- | Directive processing status. +data Status + = Skip -- ^ Skip the selection and stop directive processing + | Include Directive -- ^ The directive was processed, try other handlers + | Continue Directive -- ^ Directive handler mismatch, try other handlers + +-- | Takes a list of directives, handles supported directives and excludes them +-- from the result. If the selection should be skipped, returns 'Nothing'. +selection :: [Directive] -> Maybe [Directive] +selection = foldr go (Just []) + where + go directive' directives' = + case (skip . include) (Continue directive') of + (Include _) -> directives' + Skip -> Nothing + (Continue x) -> (x :) <$> directives' + +handle :: (Directive -> Status) -> Status -> Status +handle _ Skip = Skip +handle handler (Continue directive) = handler directive +handle handler (Include directive) = handler directive + +-- * Directive implementations + +skip :: Status -> Status +skip = handle skip' + where + skip' directive'@(Directive "skip" (Arguments arguments)) = + case HashMap.lookup "if" arguments of + (Just (Boolean True)) -> Skip + _ -> Include directive' + skip' directive' = Continue directive' + +include :: Status -> Status +include = handle include' + where + include' directive'@(Directive "include" (Arguments arguments)) = + case HashMap.lookup "if" arguments of + (Just (Boolean True)) -> Include directive' + _ -> Skip + include' directive' = Continue directive' diff --git a/stack.yaml b/stack.yaml index 90cad4f..d488fa3 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-14.16 +resolver: lts-14.17 packages: - . -- cgit v1.2.3