diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-10-13 19:40:12 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-10-13 19:40:12 +0200 |
| commit | ba07f8298bda9b18ea0408988cc2cd2239ce9726 (patch) | |
| tree | 91059533eb750040e74f75e325399a1b4fe282d2 /tests | |
| parent | 1834e5c41e8eb7bccd391d54db9453ba2ecfa3b6 (diff) | |
| download | graphql-ba07f8298bda9b18ea0408988cc2cd2239ce9726.tar.gz | |
Validate repeatable directives
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Language/GraphQL/AST/ParserSpec.hs | 4 | ||||
| -rw-r--r-- | tests/Language/GraphQL/Validate/RulesSpec.hs | 18 |
2 files changed, 18 insertions, 4 deletions
diff --git a/tests/Language/GraphQL/AST/ParserSpec.hs b/tests/Language/GraphQL/AST/ParserSpec.hs index 0e7c28a..455c99a 100644 --- a/tests/Language/GraphQL/AST/ParserSpec.hs +++ b/tests/Language/GraphQL/AST/ParserSpec.hs @@ -82,8 +82,8 @@ spec = describe "Parser" $ do it "accepts any arguments" $ mapSize (const 10) $ property $ \xs -> let query' :: Text - arguments = map printArgument $ getNonEmpty (xs :: NonEmptyList (AnyArgument AnyValue)) - query' = "query(" <> Text.intercalate ", " arguments <> ")" in + arguments' = map printArgument $ getNonEmpty (xs :: NonEmptyList (AnyArgument AnyValue)) + query' = "query(" <> Text.intercalate ", " arguments' <> ")" in parse document "" `shouldSucceedOn` ("{ " <> query' <> " }") it "parses minimal schema definition" $ diff --git a/tests/Language/GraphQL/Validate/RulesSpec.hs b/tests/Language/GraphQL/Validate/RulesSpec.hs index 7bdbd86..07ab2f6 100644 --- a/tests/Language/GraphQL/Validate/RulesSpec.hs +++ b/tests/Language/GraphQL/Validate/RulesSpec.hs @@ -15,6 +15,8 @@ import Data.Text (Text) import qualified Language.GraphQL.AST as AST import Language.GraphQL.TH import Language.GraphQL.Type +import qualified Language.GraphQL.Type.Schema as Schema +import qualified Language.GraphQL.AST.DirectiveLocation as DirectiveLocation import qualified Language.GraphQL.Type.In as In import qualified Language.GraphQL.Type.Out as Out import Language.GraphQL.Validate @@ -22,7 +24,9 @@ import Test.Hspec (Spec, context, describe, it, shouldBe, shouldContain) import Text.Megaparsec (parse, errorBundlePretty) petSchema :: Schema IO -petSchema = schema queryType Nothing (Just subscriptionType) mempty +petSchema = schema queryType Nothing (Just subscriptionType) + $ HashMap.singleton "repeat" + $ Schema.Directive Nothing mempty True [DirectiveLocation.ExecutableDirectiveLocation DirectiveLocation.Field] queryType :: ObjectType IO queryType = ObjectType "Query" Nothing [] $ HashMap.fromList @@ -494,7 +498,7 @@ spec = } in validate queryString `shouldBe` [expected] - context "uniqueDirectiveNamesRule" $ + context "uniqueDirectiveNamesRule" $ do it "rejects more than one directive per location" $ let queryString = [gql| query ($foo: Boolean = true, $bar: Boolean = false) { @@ -510,6 +514,16 @@ spec = } in validate queryString `shouldBe` [expected] + it "allows repeating repeatable directives" $ + let queryString = [gql| + query { + dog @repeat @repeat { + name + } + } + |] + in validate queryString `shouldBe` [] + context "uniqueVariableNamesRule" $ it "rejects duplicate variables" $ let queryString = [gql| |
