diff options
| author | Danny Navarro <j@dannynavarro.net> | 2015-09-21 10:05:09 +0200 |
|---|---|---|
| committer | Danny Navarro <j@dannynavarro.net> | 2015-09-21 10:05:09 +0200 |
| commit | 3d97b3e2ff7cc6d5126c8c6c8b66eed3c1fe010b (patch) | |
| tree | 2c1304afd7b6401129f3a6ff7f2d182197534c63 /Data/GraphQL/Parser.hs | |
| parent | 88ca3d18664aa5fd64692491086b07876c5facae (diff) | |
| download | graphql-3d97b3e2ff7cc6d5126c8c6c8b66eed3c1fe010b.tar.gz | |
Introduce `Node` data type to simplify `OperationDefinition`
Thanks to @swolchok for the suggestion.
Diffstat (limited to 'Data/GraphQL/Parser.hs')
| -rw-r--r-- | Data/GraphQL/Parser.hs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs index 8f8e185..db22be9 100644 --- a/Data/GraphQL/Parser.hs +++ b/Data/GraphQL/Parser.hs @@ -45,7 +45,6 @@ name = tok $ append <$> takeWhile1 isA_z -- `isAlpha` handles many more Unicode Chars isA_z = inClass $ '_' : ['A'..'Z'] ++ ['a'..'z'] - -- * Document document :: Parser Document @@ -54,7 +53,8 @@ document = whiteSpace -- Try SelectionSet when no definition <|> (Document . pure . DefinitionOperation - . Query mempty empty empty + . Query + . Node mempty empty empty <$> selectionSet) <?> "document error!" @@ -66,14 +66,15 @@ definition = DefinitionOperation <$> operationDefinition operationDefinition :: Parser OperationDefinition operationDefinition = - op Query "query" - <|> op Mutation "mutation" + Query <$ tok "query" <*> node + <|> Mutation <$ tok "mutation" <*> node <?> "operationDefinition error!" - where - op f n = f <$ tok n <*> tok name - <*> optempty variableDefinitions - <*> optempty directives - <*> selectionSet + +node :: Parser Node +node = Node <$> name + <*> optempty variableDefinitions + <*> optempty directives + <*> selectionSet variableDefinitions :: Parser [VariableDefinition] variableDefinitions = parens (many1 variableDefinition) |
