diff options
Diffstat (limited to 'tests/Language/GraphQL/Validate')
| -rw-r--r-- | tests/Language/GraphQL/Validate/RulesSpec.hs | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/tests/Language/GraphQL/Validate/RulesSpec.hs b/tests/Language/GraphQL/Validate/RulesSpec.hs index 7a5f4cc..7bdbd86 100644 --- a/tests/Language/GraphQL/Validate/RulesSpec.hs +++ b/tests/Language/GraphQL/Validate/RulesSpec.hs @@ -29,6 +29,7 @@ queryType = ObjectType "Query" Nothing [] $ HashMap.fromList [ ("dog", dogResolver) , ("cat", catResolver) , ("findDog", findDogResolver) + , ("findCats", findCatsResolver) ] where dogField = Field Nothing (Out.NamedObjectType dogType) mempty @@ -39,6 +40,11 @@ queryType = ObjectType "Query" Nothing [] $ HashMap.fromList findDogResolver = ValueResolver findDogField $ pure Null catField = Field Nothing (Out.NamedObjectType catType) mempty catResolver = ValueResolver catField $ pure Null + findCatsArguments = HashMap.singleton "commands" + $ In.Argument Nothing (In.NonNullListType $ In.NonNullEnumType catCommandType) + $ Just $ List [] + findCatsField = Field Nothing (Out.NonNullListType $ Out.NonNullObjectType catType) findCatsArguments + findCatsResolver = ValueResolver findCatsField $ pure $ List [] catCommandType :: EnumType catCommandType = EnumType "CatCommand" Nothing $ HashMap.fromList @@ -538,7 +544,7 @@ spec = } in validate queryString `shouldContain` [expected] - context "noUndefinedVariablesRule" $ + context "noUndefinedVariablesRule" $ do it "rejects undefined variables" $ let queryString = [gql| query variableIsNotDefinedUsedInSingleFragment { @@ -560,7 +566,35 @@ spec = } in validate queryString `shouldBe` [expected] - context "noUnusedVariablesRule" $ + it "gets variable location inside an input object" $ + let queryString = [gql| + query { + findDog (complex: { name: $name }) { + name + } + } + |] + expected = Error + { message = "Variable \"$name\" is not defined." + , locations = [AST.Location 2 29] + } + in validate queryString `shouldBe` [expected] + + it "gets variable location inside an array" $ + let queryString = [gql| + query { + findCats (commands: [JUMP, $command]) { + name + } + } + |] + expected = Error + { message = "Variable \"$command\" is not defined." + , locations = [AST.Location 2 30] + } + in validate queryString `shouldBe` [expected] + + context "noUnusedVariablesRule" $ do it "rejects unused variables" $ let queryString = [gql| query variableUnused($atOtherHomes: Boolean) { @@ -577,6 +611,16 @@ spec = } in validate queryString `shouldBe` [expected] + it "detects variables in properties of input objects" $ + let queryString = [gql| + query withVar ($name: String!) { + findDog (complex: { name: $name }) { + name + } + } + |] + in validate queryString `shouldBe` [] + context "uniqueInputFieldNamesRule" $ it "rejects duplicate fields in input objects" $ let queryString = [gql| @@ -878,7 +922,7 @@ spec = { message = "Variable \"$dogCommandArg\" of type \ \\"DogCommand\" used in position expecting type \ - \\"!DogCommand\"." + \\"DogCommand!\"." , locations = [AST.Location 1 26] } in validate queryString `shouldBe` [expected] @@ -925,7 +969,7 @@ spec = |] expected = Error { message = - "Value 3 cannot be coerced to type \"!CatCommand\"." + "Value 3 cannot be coerced to type \"CatCommand!\"." , locations = [AST.Location 3 36] } in validate queryString `shouldBe` [expected] @@ -940,7 +984,7 @@ spec = |] expected = Error { message = - "Value 3 cannot be coerced to type \"!String\"." + "Value 3 cannot be coerced to type \"String!\"." , locations = [AST.Location 2 28] } in validate queryString `shouldBe` [expected] |
