diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-08-25 21:03:42 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-08-25 21:03:42 +0200 |
| commit | 73555332681a3702db5e277f21a53c628c3a524f (patch) | |
| tree | 8d558dca6df02dd55eaaae035e8dc608c50f53dd /src/Language/GraphQL/AST/Parser.hs | |
| parent | 54dbf1df16038c9f583c1b53ab4fac1d71b194fd (diff) | |
| download | graphql-73555332681a3702db5e277f21a53c628c3a524f.tar.gz | |
Validate single root field in subscriptions
Diffstat (limited to 'src/Language/GraphQL/AST/Parser.hs')
| -rw-r--r-- | src/Language/GraphQL/AST/Parser.hs | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/Language/GraphQL/AST/Parser.hs b/src/Language/GraphQL/AST/Parser.hs index 687d8f5..7bc51cb 100644 --- a/src/Language/GraphQL/AST/Parser.hs +++ b/src/Language/GraphQL/AST/Parser.hs @@ -21,7 +21,8 @@ import Language.GraphQL.AST.DirectiveLocation import Language.GraphQL.AST.Document import Language.GraphQL.AST.Lexer import Text.Megaparsec - ( SourcePos(..) + ( MonadParsec(..) + , SourcePos(..) , getSourcePos , lookAhead , option @@ -37,15 +38,11 @@ document = unicodeBOM *> lexeme (NonEmpty.some definition) definition :: Parser Definition -definition = executableDefinition' +definition = ExecutableDefinition <$> executableDefinition <|> typeSystemDefinition' <|> typeSystemExtension' <?> "Definition" where - executableDefinition' = do - location <- getLocation - definition' <- executableDefinition - pure $ ExecutableDefinition definition' location typeSystemDefinition' = do location <- getLocation definition' <- typeSystemDefinition @@ -349,16 +346,22 @@ operationTypeDefinition = OperationTypeDefinition <?> "OperationTypeDefinition" operationDefinition :: Parser OperationDefinition -operationDefinition = SelectionSet <$> selectionSet +operationDefinition = shorthand <|> operationDefinition' <?> "OperationDefinition" where - operationDefinition' - = OperationDefinition <$> operationType - <*> optional name - <*> variableDefinitions - <*> directives - <*> selectionSet + shorthand = do + location <- getLocation + selectionSet' <- selectionSet + pure $ SelectionSet selectionSet' location + operationDefinition' = do + location <- getLocation + operationType' <- operationType + operationName <- optional name + variableDefinitions' <- variableDefinitions + directives' <- directives + selectionSet' <- selectionSet + pure $ OperationDefinition operationType' operationName variableDefinitions' directives' selectionSet' location operationType :: Parser OperationType operationType = Query <$ symbol "query" @@ -412,13 +415,15 @@ inlineFragment = InlineFragment <?> "InlineFragment" fragmentDefinition :: Parser FragmentDefinition -fragmentDefinition = FragmentDefinition - <$ symbol "fragment" - <*> name - <*> typeCondition - <*> directives - <*> selectionSet - <?> "FragmentDefinition" +fragmentDefinition = label "FragmentDefinition" $ do + location <- getLocation + _ <- symbol "fragment" + fragmentName' <- name + typeCondition' <- typeCondition + directives' <- directives + selectionSet' <- selectionSet + pure $ FragmentDefinition + fragmentName' typeCondition' directives' selectionSet' location fragmentName :: Parser Name fragmentName = but (symbol "on") *> name <?> "FragmentName" |
