diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-09-14 07:49:33 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-09-15 08:06:07 +0200 |
| commit | 4c10ce92041dc73a95aeb64aca241dd937ffaa5c (patch) | |
| tree | 6a1742eaf6ff3ae3a4f4d0e2a3c5afbe9a146f4b /src/Language/GraphQL/AST | |
| parent | 08998dbd935e65aab10ff53c249cb214af2522f2 (diff) | |
| download | graphql-4c10ce92041dc73a95aeb64aca241dd937ffaa5c.tar.gz | |
Use Seq as base monad in the validator
It is more natural to implement the logic: try to apply each rule to
each node.
Diffstat (limited to 'src/Language/GraphQL/AST')
| -rw-r--r-- | src/Language/GraphQL/AST/Document.hs | 10 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Encoder.hs | 2 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Lexer.hs | 4 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Parser.hs | 7 |
4 files changed, 14 insertions, 9 deletions
diff --git a/src/Language/GraphQL/AST/Document.hs b/src/Language/GraphQL/AST/Document.hs index cc657f4..7d0bcd0 100644 --- a/src/Language/GraphQL/AST/Document.hs +++ b/src/Language/GraphQL/AST/Document.hs @@ -49,7 +49,7 @@ import Data.Int (Int32) import Data.List.NonEmpty (NonEmpty) import Data.Text (Text) import qualified Data.Text as Text -import Language.GraphQL.AST.DirectiveLocation +import Language.GraphQL.AST.DirectiveLocation (DirectiveLocation) -- * Language @@ -126,7 +126,7 @@ data Selection | InlineFragmentSelection InlineFragment deriving (Eq, Show) --- The only required property of a field is its name. Optionally it can also +-- | The only required property of a field is its name. Optionally it can also -- have an alias, arguments, directives and a list of subfields. -- -- In the following query "user" is a field with two subfields, "id" and "name": @@ -143,7 +143,7 @@ data Field = Field (Maybe Name) Name [Argument] [Directive] SelectionSetOpt Location deriving (Eq, Show) --- Inline fragments don't have any name and the type condition ("on UserType") +-- | Inline fragments don't have any name and the type condition ("on UserType") -- is optional. -- -- @ @@ -159,7 +159,7 @@ data InlineFragment = InlineFragment (Maybe TypeCondition) [Directive] SelectionSet Location deriving (Eq, Show) --- A fragment spread refers to a fragment defined outside the operation and is +-- | A fragment spread refers to a fragment defined outside the operation and is -- expanded at the execution time. -- -- @ @@ -190,7 +190,7 @@ data FragmentSpread = FragmentSpread Name [Directive] Location -- @ -- -- Here "id" is an argument for the field "user" and its value is 4. -data Argument = Argument Name Value deriving (Eq,Show) +data Argument = Argument Name Value Location deriving (Eq,Show) -- ** Fragments diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs index dcc24fe..342a45f 100644 --- a/src/Language/GraphQL/AST/Encoder.hs +++ b/src/Language/GraphQL/AST/Encoder.hs @@ -159,7 +159,7 @@ arguments :: Formatter -> [Argument] -> Lazy.Text arguments formatter = parensCommas formatter $ argument formatter argument :: Formatter -> Argument -> Lazy.Text -argument formatter (Argument name value') +argument formatter (Argument name value' _) = Lazy.Text.fromStrict name <> colon formatter <> value formatter value' diff --git a/src/Language/GraphQL/AST/Lexer.hs b/src/Language/GraphQL/AST/Lexer.hs index 17d3f9c..cd2bd89 100644 --- a/src/Language/GraphQL/AST/Lexer.hs +++ b/src/Language/GraphQL/AST/Lexer.hs @@ -100,8 +100,8 @@ amp :: Parser T.Text amp = symbol "&" -- | Parser for ":". -colon :: Parser T.Text -colon = symbol ":" +colon :: Parser () +colon = symbol ":" >> pure () -- | Parser for "=". equals :: Parser T.Text diff --git a/src/Language/GraphQL/AST/Parser.hs b/src/Language/GraphQL/AST/Parser.hs index 136067b..f6d1539 100644 --- a/src/Language/GraphQL/AST/Parser.hs +++ b/src/Language/GraphQL/AST/Parser.hs @@ -398,7 +398,12 @@ arguments :: Parser [Argument] arguments = listOptIn parens argument <?> "Arguments" argument :: Parser Argument -argument = Argument <$> name <* colon <*> value <?> "Argument" +argument = label "Argument" $ do + location <- getLocation + name' <- name + colon + value' <- value + pure $ Argument name' value' location fragmentSpread :: Parser FragmentSpread fragmentSpread = label "FragmentSpread" $ do |
