summaryrefslogtreecommitdiff
path: root/Data/GraphQL
diff options
context:
space:
mode:
Diffstat (limited to 'Data/GraphQL')
-rw-r--r--Data/GraphQL/Parser.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs
index 3b72104..29a051d 100644
--- a/Data/GraphQL/Parser.hs
+++ b/Data/GraphQL/Parser.hs
@@ -9,6 +9,7 @@ import Control.Applicative ((<|>), Alternative, empty, many, optional)
import Control.Monad (when)
import Data.Char (isDigit, isSpace)
import Data.Foldable (traverse_)
+import Data.Int (Int32)
import Data.Monoid ((<>))
import Data.List.NonEmpty (NonEmpty((:|)))
import Data.Scientific (floatingOrInteger)
@@ -130,7 +131,7 @@ typeCondition = tok "on" *> name
value :: Parser Value
value = ValueVariable <$> variable
- <|> tok (either ValueFloat ValueInt . floatingOrInteger <$> scientific)
+ <|> tok floatOrInt32Value
<|> ValueBoolean <$> booleanValue
<|> ValueNull <$ tok "null"
<|> ValueString <$> stringValue
@@ -143,6 +144,16 @@ value = ValueVariable <$> variable
booleanValue = True <$ tok "true"
<|> False <$ tok "false"
+ floatOrInt32Value :: Parser Value
+ floatOrInt32Value = do
+ n <- scientific
+ case (floatingOrInteger n :: Either Double Integer) of
+ Left dbl -> return $ ValueFloat dbl
+ Right i ->
+ if i < (-2147483648) || i >= 2147483648
+ then fail "Integer value is out of range."
+ else return $ ValueInt (fromIntegral i :: Int32)
+
-- TODO: Escape characters. Look at `jsstring_` in aeson package.
stringValue :: Parser Text
stringValue = quotes (takeWhile (/= '"'))