diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-09-18 07:32:58 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-09-18 07:32:58 +0200 |
| commit | 9a08aa5de73e225a9a76017aee4886ce7f6eccec (patch) | |
| tree | 6cdeadc16c994bcb3bd13764c1a7104c2cb56c09 /src/Language/GraphQL/AST | |
| parent | 497b93c41b2534ec2b92b49e93267178417bef56 (diff) | |
| download | graphql-9a08aa5de73e225a9a76017aee4886ce7f6eccec.tar.gz | |
Validate directives are unique per location
Diffstat (limited to 'src/Language/GraphQL/AST')
| -rw-r--r-- | src/Language/GraphQL/AST/Document.hs | 2 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Encoder.hs | 2 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Lexer.hs | 4 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Parser.hs | 11 |
4 files changed, 10 insertions, 9 deletions
diff --git a/src/Language/GraphQL/AST/Document.hs b/src/Language/GraphQL/AST/Document.hs index 7d0bcd0..5d21ca0 100644 --- a/src/Language/GraphQL/AST/Document.hs +++ b/src/Language/GraphQL/AST/Document.hs @@ -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 diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs index 342a45f..fcd415e 100644 --- a/src/Language/GraphQL/AST/Encoder.hs +++ b/src/Language/GraphQL/AST/Encoder.hs @@ -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 diff --git a/src/Language/GraphQL/AST/Lexer.hs b/src/Language/GraphQL/AST/Lexer.hs index cd2bd89..ecefaf6 100644 --- a/src/Language/GraphQL/AST/Lexer.hs +++ b/src/Language/GraphQL/AST/Lexer.hs @@ -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 diff --git a/src/Language/GraphQL/AST/Parser.hs b/src/Language/GraphQL/AST/Parser.hs index f6d1539..62a247d 100644 --- a/src/Language/GraphQL/AST/Parser.hs +++ b/src/Language/GraphQL/AST/Parser.hs @@ -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 |
