diff options
Diffstat (limited to 'tests/Language')
| -rw-r--r-- | tests/Language/GraphQL/AST/EncoderSpec.hs | 2 | ||||
| -rw-r--r-- | tests/Language/GraphQL/AST/ParserSpec.hs | 6 | ||||
| -rw-r--r-- | tests/Language/GraphQL/THSpec.hs | 24 | ||||
| -rw-r--r-- | tests/Language/GraphQL/Validate/RulesSpec.hs | 48 |
4 files changed, 37 insertions, 43 deletions
diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs index e98d5ef..82d059a 100644 --- a/tests/Language/GraphQL/AST/EncoderSpec.hs +++ b/tests/Language/GraphQL/AST/EncoderSpec.hs @@ -181,7 +181,7 @@ spec = do argument = Full.InputValueDefinition mempty "arg" someType Nothing mempty arguments = Full.ArgumentsDefinition [argument] definition' = Full.TypeDefinition - $ Full.InterfaceTypeDefinition mempty "UUID" mempty + $ Full.InterfaceTypeDefinition mempty "UUID" (Full.ImplementsInterfaces []) mempty $ pure $ Full.FieldDefinition mempty "value" arguments someType mempty expected = "interface UUID {\n\ diff --git a/tests/Language/GraphQL/AST/ParserSpec.hs b/tests/Language/GraphQL/AST/ParserSpec.hs index 3bd2576..9f992bb 100644 --- a/tests/Language/GraphQL/AST/ParserSpec.hs +++ b/tests/Language/GraphQL/AST/ParserSpec.hs @@ -103,6 +103,12 @@ spec = describe "Parser" $ do \ name: String\n\ \}" + it "parses ImplementsInterfaces on interfaces" $ + parse document "" `shouldSucceedOn` + "interface Person implements NamedEntity & ValuedEntity {\n\ + \ name: String\n\ + \}" + it "parses minimal enum type definition" $ parse document "" `shouldSucceedOn` "enum Direction {\n\ diff --git a/tests/Language/GraphQL/THSpec.hs b/tests/Language/GraphQL/THSpec.hs deleted file mode 100644 index 2858ab2..0000000 --- a/tests/Language/GraphQL/THSpec.hs +++ /dev/null @@ -1,24 +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 QuasiQuotes #-} - -module Language.GraphQL.THSpec - ( spec - ) where - -import Language.GraphQL.TH (gql) -import Test.Hspec (Spec, describe, it, shouldBe) - -spec :: Spec -spec = - describe "gql" $ - it "replaces CRNL with NL" $ - let expected = "line1\nline2\nline3" - actual = [gql|
- line1
- line2
- line3
- |] - in actual `shouldBe` expected diff --git a/tests/Language/GraphQL/Validate/RulesSpec.hs b/tests/Language/GraphQL/Validate/RulesSpec.hs index c48b329..9ec74c3 100644 --- a/tests/Language/GraphQL/Validate/RulesSpec.hs +++ b/tests/Language/GraphQL/Validate/RulesSpec.hs @@ -94,7 +94,7 @@ dogType = ObjectType "Dog" Nothing [petType] $ HashMap.fromList , ("nickname", nicknameResolver) , ("barkVolume", barkVolumeResolver) , ("doesKnowCommand", doesKnowCommandResolver) - , ("isHousetrained", isHousetrainedResolver) + , ("isHouseTrained", isHouseTrainedResolver) , ("owner", ownerResolver) ] where @@ -105,10 +105,10 @@ dogType = ObjectType "Dog" Nothing [petType] $ HashMap.fromList $ In.Argument Nothing (In.NonNullEnumType dogCommandType) Nothing doesKnowCommandResolver = ValueResolver doesKnowCommandField $ pure $ Boolean True - isHousetrainedField = Field Nothing (Out.NonNullScalarType boolean) + isHouseTrainedField = Field Nothing (Out.NonNullScalarType boolean) $ HashMap.singleton "atOtherHomes" $ In.Argument Nothing (In.NamedScalarType boolean) Nothing - isHousetrainedResolver = ValueResolver isHousetrainedField + isHouseTrainedResolver = ValueResolver isHouseTrainedField $ pure $ Boolean True ownerField = Field Nothing (Out.NamedObjectType humanType) mempty ownerResolver = ValueResolver ownerField $ pure Null @@ -206,6 +206,18 @@ spec = } in validate queryString `shouldContain` [expected] + it "rejects an introspection field as the subscription root" $ + let queryString = "subscription sub {\n\ + \ __typename\n\ + \}" + expected = Error + { message = + "Subscription \"sub\" must select exactly one top \ + \level field, which must not be an introspection field." + , locations = [AST.Location 1 1] + } + in validate queryString `shouldContain` [expected] + it "rejects multiple subscription root fields coming from a fragment" $ let queryString = "subscription sub {\n\ \ ...multipleSubscriptions\n\ @@ -455,7 +467,7 @@ spec = it "rejects duplicate field arguments" $ let queryString = "{\n\ \ dog {\n\ - \ isHousetrained(atOtherHomes: true, atOtherHomes: true)\n\ + \ isHouseTrained(atOtherHomes: true, atOtherHomes: true)\n\ \ }\n\ \}" expected = Error @@ -492,7 +504,7 @@ spec = it "rejects duplicate variables" $ let queryString = "query houseTrainedQuery($atOtherHomes: Boolean, $atOtherHomes: Boolean) {\n\ \ dog {\n\ - \ isHousetrained(atOtherHomes: $atOtherHomes)\n\ + \ isHouseTrained(atOtherHomes: $atOtherHomes)\n\ \ }\n\ \}" expected = Error @@ -507,7 +519,7 @@ spec = it "rejects non-input types as variables" $ let queryString = "query takesDogBang($dog: Dog!) {\n\ \ dog {\n\ - \ isHousetrained(atOtherHomes: $dog)\n\ + \ isHouseTrained(atOtherHomes: $dog)\n\ \ }\n\ \}" expected = Error @@ -522,12 +534,12 @@ spec = it "rejects undefined variables" $ let queryString = "query variableIsNotDefinedUsedInSingleFragment {\n\ \ dog {\n\ - \ ...isHousetrainedFragment\n\ + \ ...isHouseTrainedFragment\n\ \ }\n\ \}\n\ \\n\ - \fragment isHousetrainedFragment on Dog {\n\ - \ isHousetrained(atOtherHomes: $atOtherHomes)\n\ + \fragment isHouseTrainedFragment on Dog {\n\ + \ isHouseTrained(atOtherHomes: $atOtherHomes)\n\ \}" expected = Error { message = @@ -566,7 +578,7 @@ spec = it "rejects unused variables" $ let queryString = "query variableUnused($atOtherHomes: Boolean) {\n\ \ dog {\n\ - \ isHousetrained\n\ + \ isHouseTrained\n\ \ }\n\ \}" expected = Error @@ -648,7 +660,7 @@ spec = it "rejects directive arguments missing in the definition" $ let queryString = "{\n\ \ dog {\n\ - \ isHousetrained(atOtherHomes: true) @include(unless: false, if: true)\n\ + \ isHouseTrained(atOtherHomes: true) @include(unless: false, if: true)\n\ \ }\n\ \}" expected = Error @@ -663,7 +675,7 @@ spec = it "rejects undefined directives" $ let queryString = "{\n\ \ dog {\n\ - \ isHousetrained(atOtherHomes: true) @ignore(if: true)\n\ + \ isHouseTrained(atOtherHomes: true) @ignore(if: true)\n\ \ }\n\ \}" expected = Error @@ -740,13 +752,13 @@ spec = let queryString = "{\n\ \ dog {\n\ \ doesKnowCommand(dogCommand: SIT)\n\ - \ doesKnowCommand: isHousetrained(atOtherHomes: true)\n\ + \ doesKnowCommand: isHouseTrained(atOtherHomes: true)\n\ \ }\n\ \}" expected = Error { message = "Fields \"doesKnowCommand\" conflict because \ - \\"doesKnowCommand\" and \"isHousetrained\" are \ + \\"doesKnowCommand\" and \"isHouseTrained\" are \ \different fields. Use different aliases on the \ \fields to fetch both if this was intentional." , locations = [AST.Location 3 5, AST.Location 4 5] @@ -761,13 +773,13 @@ spec = \ }\n\ \ dog {\n\ \ name\n\ - \ doesKnowCommand: isHousetrained(atOtherHomes: true)\n\ + \ doesKnowCommand: isHouseTrained(atOtherHomes: true)\n\ \ }\n\ \}" expected = Error { message = "Fields \"doesKnowCommand\" conflict because \ - \\"doesKnowCommand\" and \"isHousetrained\" are \ + \\"doesKnowCommand\" and \"isHouseTrained\" are \ \different fields. Use different aliases on the \ \fields to fetch both if this was intentional." , locations = [AST.Location 4 5, AST.Location 8 5] @@ -860,7 +872,7 @@ spec = it "rejects wrongly typed variable arguments" $ let queryString = "query intCannotGoIntoBoolean($intArg: Int) {\n\ \ dog {\n\ - \ isHousetrained(atOtherHomes: $intArg)\n\ + \ isHouseTrained(atOtherHomes: $intArg)\n\ \ }\n\ \}" expected = Error @@ -875,7 +887,7 @@ spec = it "rejects values of incorrect types" $ let queryString = "{\n\ \ dog {\n\ - \ isHousetrained(atOtherHomes: 3)\n\ + \ isHouseTrained(atOtherHomes: 3)\n\ \ }\n\ \}" expected = Error |
