Parse repeatable directive definitions
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user