summaryrefslogtreecommitdiff
path: root/tests/Language/GraphQL/AST/ParserSpec.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-08-27 10:51:01 +0200
committerEugen Wissner <belka@caraus.de>2024-08-27 10:51:01 +0200
commitb40d8a7e1ef03e6ccbe990572add58cfaa6d8ed9 (patch)
treef803e634f92953b457c8418747d67678754e77c3 /tests/Language/GraphQL/AST/ParserSpec.hs
parent4b5e25a4d84e992910ad4bdf92b0f8a2213493a8 (diff)
downloadgraphql-b40d8a7e1ef03e6ccbe990572add58cfaa6d8ed9.tar.gz
Parse repeatable directive definitions
Diffstat (limited to 'tests/Language/GraphQL/AST/ParserSpec.hs')
-rw-r--r--tests/Language/GraphQL/AST/ParserSpec.hs87
1 files changed, 46 insertions, 41 deletions
diff --git a/tests/Language/GraphQL/AST/ParserSpec.hs b/tests/Language/GraphQL/AST/ParserSpec.hs
index 13faa21..80c2663 100644
--- a/tests/Language/GraphQL/AST/ParserSpec.hs
+++ b/tests/Language/GraphQL/AST/ParserSpec.hs
@@ -12,7 +12,12 @@ import qualified Language.GraphQL.AST.DirectiveLocation as DirLoc
import Language.GraphQL.AST.Parser
import Language.GraphQL.TH
import Test.Hspec (Spec, describe, it, context)
-import Test.Hspec.Megaparsec (shouldParse, shouldFailOn, shouldSucceedOn)
+import Test.Hspec.Megaparsec
+ ( shouldParse
+ , shouldFailOn
+ , parseSatisfies
+ , shouldSucceedOn
+ )
import Text.Megaparsec (parse)
import Test.QuickCheck (property, NonEmptyList (..), mapSize)
import Language.GraphQL.AST.Arbitrary
@@ -143,22 +148,20 @@ spec = describe "Parser" $ do
|]
it "parses two minimal directive definitions" $
- let directive nm loc =
- TypeSystemDefinition
- (DirectiveDefinition
- (Description Nothing)
- nm
- (ArgumentsDefinition [])
- (loc :| []))
- example1 =
- directive "example1"
- (DirLoc.TypeSystemDirectiveLocation DirLoc.FieldDefinition)
- (Location {line = 1, column = 1})
- example2 =
- directive "example2"
- (DirLoc.ExecutableDirectiveLocation DirLoc.Field)
- (Location {line = 2, column = 1})
- testSchemaExtension = example1 :| [ example2 ]
+ let directive name' loc = TypeSystemDefinition
+ $ DirectiveDefinition
+ (Description Nothing)
+ name'
+ (ArgumentsDefinition [])
+ False
+ (loc :| [])
+ example1 = directive "example1"
+ (DirLoc.TypeSystemDirectiveLocation DirLoc.FieldDefinition)
+ (Location {line = 1, column = 1})
+ example2 = directive "example2"
+ (DirLoc.ExecutableDirectiveLocation DirLoc.Field)
+ (Location {line = 2, column = 1})
+ testSchemaExtension = example1 :| [example2]
query = [gql|
directive @example1 on FIELD_DEFINITION
directive @example2 on FIELD
@@ -166,31 +169,26 @@ spec = describe "Parser" $ do
in parse document "" query `shouldParse` testSchemaExtension
it "parses a directive definition with a default empty list argument" $
- let directive nm loc args =
- TypeSystemDefinition
- (DirectiveDefinition
- (Description Nothing)
- nm
- (ArgumentsDefinition
- [ InputValueDefinition
- (Description Nothing)
- argName
- argType
- argValue
- []
- | (argName, argType, argValue) <- args])
- (loc :| []))
- defn =
- directive "test"
- (DirLoc.TypeSystemDirectiveLocation DirLoc.FieldDefinition)
- [("foo",
- TypeList (TypeNamed "String"),
- Just
- $ Node (ConstList [])
- $ Location {line = 1, column = 33})]
- (Location {line = 1, column = 1})
+ let argumentValue = Just
+ $ Node (ConstList [])
+ $ Location{ line = 1, column = 33 }
+ loc = DirLoc.TypeSystemDirectiveLocation DirLoc.FieldDefinition
+ argumentValueDefinition = InputValueDefinition
+ (Description Nothing)
+ "foo"
+ (TypeList (TypeNamed "String"))
+ argumentValue
+ []
+ definition = DirectiveDefinition
+ (Description Nothing)
+ "test"
+ (ArgumentsDefinition [argumentValueDefinition] )
+ False
+ (loc :| [])
+ directive = TypeSystemDefinition definition
+ $ Location{ line = 1, column = 1 }
query = [gql|directive @test(foo: [String] = []) on FIELD_DEFINITION|]
- in parse document "" query `shouldParse` (defn :| [ ])
+ in parse document "" query `shouldParse` (directive :| [])
it "parses schema extension with a new directive" $
parse document "" `shouldSucceedOn`[gql|
@@ -210,6 +208,13 @@ spec = describe "Parser" $ do
query = [gql|extend schema @newDirective { query: Query }|]
in parse document "" query `shouldParse` (testSchemaExtension :| [])
+ it "parses a repeatable directive definition" $
+ let given = [gql|directive @test repeatable on FIELD_DEFINITION|]
+ isRepeatable (TypeSystemDefinition definition' _ :| [])
+ | DirectiveDefinition _ _ _ repeatable _ <- definition' = repeatable
+ isRepeatable _ = False
+ in parse document "" given `parseSatisfies` isRepeatable
+
it "parses an object extension" $
parse document "" `shouldSucceedOn` [gql|
extend type Story {