Validate all variables are defined

This commit is contained in:
2020-09-21 07:28:40 +02:00
parent 38c3097bcf
commit 3e393004ae
8 changed files with 166 additions and 43 deletions

View File

@ -24,6 +24,7 @@ module Language.GraphQL.AST.Document
, Location(..)
, Name
, NamedType
, Node(..)
, NonNullType(..)
, ObjectField(..)
, OperationDefinition(..)
@ -70,6 +71,9 @@ instance Ord Location where
| thisLine > thatLine = GT
| otherwise = compare thisColumn thatColumn
-- | Contains some tree node with a location.
data Node a = Node a Location deriving (Eq, Show)
-- ** Document
-- | GraphQL document.
@ -190,7 +194,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 Location deriving (Eq,Show)
data Argument = Argument Name (Node Value) Location deriving (Eq, Show)
-- ** Fragments

View File

@ -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 (Node value' _) _)
= Lazy.Text.fromStrict name
<> colon formatter
<> value formatter value'

View File

@ -402,7 +402,7 @@ argument = label "Argument" $ do
location <- getLocation
name' <- name
colon
value' <- value
value' <- valueNode
pure $ Argument name' value' location
fragmentSpread :: Parser FragmentSpread
@ -439,6 +439,12 @@ fragmentName = but (symbol "on") *> name <?> "FragmentName"
typeCondition :: Parser TypeCondition
typeCondition = symbol "on" *> name <?> "TypeCondition"
valueNode :: Parser (Node Value)
valueNode = do
location <- getLocation
value' <- value
pure $ Node value' location
value :: Parser Value
value = Variable <$> variable
<|> Float <$> try float