Validate directives are unique per location
This commit is contained in:
@ -280,7 +280,7 @@ data NonNullType
|
||||
--
|
||||
-- Directives begin with "@", can accept arguments, and can be applied to the
|
||||
-- most GraphQL elements, providing additional information.
|
||||
data Directive = Directive Name [Argument] deriving (Eq, Show)
|
||||
data Directive = Directive Name [Argument] Location deriving (Eq, Show)
|
||||
|
||||
-- * Type System
|
||||
|
||||
|
@ -191,7 +191,7 @@ fragmentDefinition formatter (FragmentDefinition name tc dirs sels _)
|
||||
|
||||
-- | Converts a 'Directive' into a string.
|
||||
directive :: Formatter -> Directive -> Lazy.Text
|
||||
directive formatter (Directive name args)
|
||||
directive formatter (Directive name args _)
|
||||
= "@" <> Lazy.Text.fromStrict name <> optempty (arguments formatter) args
|
||||
|
||||
directives :: Formatter -> [Directive] -> Lazy.Text
|
||||
|
@ -92,8 +92,8 @@ dollar :: Parser T.Text
|
||||
dollar = symbol "$"
|
||||
|
||||
-- | Parser for "@".
|
||||
at :: Parser Text
|
||||
at = symbol "@"
|
||||
at :: Parser ()
|
||||
at = symbol "@" >> pure ()
|
||||
|
||||
-- | Parser for "&".
|
||||
amp :: Parser T.Text
|
||||
|
@ -520,11 +520,12 @@ directives :: Parser [Directive]
|
||||
directives = many directive <?> "Directives"
|
||||
|
||||
directive :: Parser Directive
|
||||
directive = Directive
|
||||
<$ at
|
||||
<*> name
|
||||
<*> arguments
|
||||
<?> "Directive"
|
||||
directive = label "Directive" $ do
|
||||
location <- getLocation
|
||||
at
|
||||
directiveName <- name
|
||||
directiveArguments <- arguments
|
||||
pure $ Directive directiveName directiveArguments location
|
||||
|
||||
listOptIn :: (Parser [a] -> Parser [a]) -> Parser a -> Parser [a]
|
||||
listOptIn surround = option [] . surround . some
|
||||
|
Reference in New Issue
Block a user