diff options
| author | Danny Navarro <j@dannynavarro.net> | 2015-09-22 13:53:37 +0200 |
|---|---|---|
| committer | Danny Navarro <j@dannynavarro.net> | 2015-09-22 14:02:49 +0200 |
| commit | 06b3302862e0c427439136241fb6299f215cec52 (patch) | |
| tree | 338b9ecc208b4b25dfeaab61d2d326e6020aa3a8 /Data/GraphQL | |
| parent | 45083642667fce8a1f6d1491f3487243416e8cc0 (diff) | |
| download | graphql-06b3302862e0c427439136241fb6299f215cec52.tar.gz | |
Add kitchen sink parse/encode unit test
This also includes the fixes to make it work. Golden tests have been
removed.
Diffstat (limited to 'Data/GraphQL')
| -rw-r--r-- | Data/GraphQL/Parser.hs | 16 | ||||
| -rw-r--r-- | Data/GraphQL/Printer.hs | 8 |
2 files changed, 10 insertions, 14 deletions
diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs index 3ff780c..00e4df1 100644 --- a/Data/GraphQL/Parser.hs +++ b/Data/GraphQL/Parser.hs @@ -14,7 +14,6 @@ import Data.Char import Data.Foldable (traverse_) import Data.Text (Text, append) -import qualified Data.Text as T import Data.Attoparsec.Text ( Parser , (<?>) @@ -29,7 +28,6 @@ import Data.Attoparsec.Text , peekChar , sepBy1 , signed - , takeText , takeWhile , takeWhile1 ) @@ -170,15 +168,9 @@ booleanValue :: Parser Bool booleanValue = True <$ tok "true" <|> False <$ tok "false" +-- TODO: Escape characters. Look at `jsstring_` in aeson package. stringValue :: Parser StringValue -stringValue = StringValue <$> quotes (T.foldl' step mempty <$> takeText) - where - -- TODO: Handle unicode and the rest of escaped chars. - step acc c - | T.null acc = T.singleton c - | T.last acc == '\\' = if c == '"' then T.init acc `T.snoc` '"' - else acc `T.snoc` c - | otherwise = acc `T.snoc` c +stringValue = StringValue <$> quotes (takeWhile (/= '"')) -- Notice it can be empty listValue :: Parser ListValue @@ -205,9 +197,9 @@ directive = Directive -- * Type Reference type_ :: Parser Type -type_ = TypeNamed <$> namedType - <|> TypeList <$> listType +type_ = TypeList <$> listType <|> TypeNonNull <$> nonNullType + <|> TypeNamed <$> namedType <?> "type_ error!" namedType :: Parser NamedType diff --git a/Data/GraphQL/Printer.hs b/Data/GraphQL/Printer.hs index 4a4d67e..f241220 100644 --- a/Data/GraphQL/Printer.hs +++ b/Data/GraphQL/Printer.hs @@ -10,8 +10,9 @@ import Data.GraphQL.AST -- * Document +-- TODO: Use query shorthand document :: Document -> Text -document (Document defs) = mconcat $ definition <$> defs +document (Document defs) = (`snoc` '\n') . mconcat $ definition <$> defs definition :: Definition -> Text definition (DefinitionOperation x) = operationDefinition x @@ -102,7 +103,7 @@ booleanValue False = "false" -- TODO: Escape characters stringValue :: StringValue -> Text -stringValue (StringValue x) = x +stringValue (StringValue v) = quotes v listValue :: ListValue -> Text listValue (ListValue vs) = bracketsCommas value vs @@ -222,6 +223,9 @@ brackets = between '[' ']' braces :: Text -> Text braces = between '{' '}' +quotes :: Text -> Text +quotes = between '"' '"' + spaces :: (a -> Text) -> [a] -> Text spaces f = intercalate "\SP" . fmap f |
