aboutsummaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/AST
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/GraphQL/AST')
-rw-r--r--src/Language/GraphQL/AST/Encoder.hs11
-rw-r--r--src/Language/GraphQL/AST/Lexer.hs7
2 files changed, 13 insertions, 5 deletions
diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs
index 0d448df..54967ea 100644
--- a/src/Language/GraphQL/AST/Encoder.hs
+++ b/src/Language/GraphQL/AST/Encoder.hs
@@ -11,6 +11,7 @@ module Language.GraphQL.AST.Encoder
, directive
, document
, minified
+ , operationType
, pretty
, type'
, value
@@ -34,7 +35,7 @@ import qualified Language.GraphQL.AST.Document as Full
-- Use 'pretty' or 'minified' to construct the formatter.
data Formatter
= Minified
- | Pretty Word
+ | Pretty !Word
-- | Constructs a formatter for pretty printing.
pretty :: Formatter
@@ -101,7 +102,7 @@ variableDefinition formatter variableDefinition' =
in variable variableName
<> eitherFormat formatter ": " ":"
<> type' variableType
- <> maybe mempty (defaultValue formatter) (Full.node <$> defaultValue')
+ <> maybe mempty (defaultValue formatter . Full.node) defaultValue'
defaultValue :: Formatter -> Full.ConstValue -> Lazy.Text
defaultValue formatter val
@@ -294,6 +295,12 @@ nonNullType :: Full.NonNullType -> Lazy.Text
nonNullType (Full.NonNullTypeNamed x) = Lazy.Text.fromStrict x <> "!"
nonNullType (Full.NonNullTypeList x) = listType x <> "!"
+-- | Produces lowercase operation type: query, mutation or subscription.
+operationType :: Formatter -> Full.OperationType -> Lazy.Text
+operationType _formatter Full.Query = "query"
+operationType _formatter Full.Mutation = "mutation"
+operationType _formatter Full.Subscription = "subscription"
+
-- * Internal
between :: Char -> Char -> Lazy.Text -> Lazy.Text
diff --git a/src/Language/GraphQL/AST/Lexer.hs b/src/Language/GraphQL/AST/Lexer.hs
index ecefaf6..ab1f36f 100644
--- a/src/Language/GraphQL/AST/Lexer.hs
+++ b/src/Language/GraphQL/AST/Lexer.hs
@@ -58,6 +58,7 @@ import qualified Text.Megaparsec.Char.Lexer as Lexer
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
+import Control.Monad (void)
-- | Standard parser.
-- Accepts the type of the parsed token.
@@ -93,7 +94,7 @@ dollar = symbol "$"
-- | Parser for "@".
at :: Parser ()
-at = symbol "@" >> pure ()
+at = void $ symbol "@"
-- | Parser for "&".
amp :: Parser T.Text
@@ -101,7 +102,7 @@ amp = symbol "&"
-- | Parser for ":".
colon :: Parser ()
-colon = symbol ":" >> pure ()
+colon = void $ symbol ":"
-- | Parser for "=".
equals :: Parser T.Text
@@ -220,7 +221,7 @@ escapeSequence = do
-- | Parser for the "Byte Order Mark".
unicodeBOM :: Parser ()
-unicodeBOM = optional (char '\xfeff') >> pure ()
+unicodeBOM = void $ optional $ char '\xfeff'
-- | Parses "extend" followed by a 'symbol'. It is used by schema extensions.
extend :: forall a. Text -> String -> NonEmpty (Parser a) -> Parser a