From 0047a13bc0c056d3adc3bbee00284ee07d831cc6 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 22 Nov 2021 07:22:28 +0100 Subject: Move JSON tests to the upcoming extra package --- tests/Test/DirectiveSpec.hs | 92 --------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 tests/Test/DirectiveSpec.hs (limited to 'tests/Test/DirectiveSpec.hs') diff --git a/tests/Test/DirectiveSpec.hs b/tests/Test/DirectiveSpec.hs deleted file mode 100644 index 50caa5b..0000000 --- a/tests/Test/DirectiveSpec.hs +++ /dev/null @@ -1,92 +0,0 @@ -{- This Source Code Form is subject to the terms of the Mozilla Public License, - v. 2.0. If a copy of the MPL was not distributed with this file, You can - obtain one at https://mozilla.org/MPL/2.0/. -} - -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} -module Test.DirectiveSpec - ( spec - ) where - -import Data.Aeson (object, (.=)) -import qualified Data.Aeson as Aeson -import qualified Data.HashMap.Strict as HashMap -import Language.GraphQL -import Language.GraphQL.TH -import Language.GraphQL.Type -import qualified Language.GraphQL.Type.Out as Out -import Test.Hspec (Spec, describe, it) -import Test.Hspec.GraphQL - -experimentalResolver :: Schema IO -experimentalResolver = schema queryType Nothing Nothing mempty - where - queryType = Out.ObjectType "Query" Nothing [] - $ HashMap.singleton "experimentalField" - $ Out.ValueResolver (Out.Field Nothing (Out.NamedScalarType int) mempty) - $ pure $ Int 5 - -emptyObject :: Aeson.Object -emptyObject = HashMap.singleton "data" $ object [] - -spec :: Spec -spec = - describe "Directive executor" $ do - it "should be able to @skip fields" $ do - let sourceQuery = [gql| - { - experimentalField @skip(if: true) - } - |] - - actual <- graphql experimentalResolver sourceQuery - actual `shouldResolveTo` emptyObject - - it "should not skip fields if @skip is false" $ do - let sourceQuery = [gql| - { - experimentalField @skip(if: false) - } - |] - expected = HashMap.singleton "data" - $ object - [ "experimentalField" .= (5 :: Int) - ] - actual <- graphql experimentalResolver sourceQuery - actual `shouldResolveTo` expected - - it "should skip fields if @include is false" $ do - let sourceQuery = [gql| - { - experimentalField @include(if: false) - } - |] - - actual <- graphql experimentalResolver sourceQuery - actual `shouldResolveTo` emptyObject - - it "should be able to @skip a fragment spread" $ do - let sourceQuery = [gql| - { - ...experimentalFragment @skip(if: true) - } - - fragment experimentalFragment on Query { - experimentalField - } - |] - - actual <- graphql experimentalResolver sourceQuery - actual `shouldResolveTo` emptyObject - - it "should be able to @skip an inline fragment" $ do - let sourceQuery = [gql| - { - ... on Query @skip(if: true) { - experimentalField - } - } - |] - - actual <- graphql experimentalResolver sourceQuery - actual `shouldResolveTo` emptyObject -- cgit v1.2.3