Validate repeatable directives
All checks were successful
Build / audit (push) Successful in 20s
Build / test (push) Successful in 6m7s
Build / doc (push) Successful in 5m5s

This commit is contained in:
2024-10-13 19:40:12 +02:00
parent 1834e5c41e
commit ba07f8298b
9 changed files with 52 additions and 23 deletions

View File

@ -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|