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

@ -122,7 +122,8 @@ spec = do
describe "definition" $
it "indents block strings in arguments" $
let location = Location 0 0
arguments = [Argument "message" (String "line1\nline2") location]
argumentValue = Node (String "line1\nline2") location
arguments = [Argument "message" argumentValue location]
field = Field Nothing "field" arguments [] [] location
operation = DefinitionOperation
$ SelectionSet (pure $ FieldSelection field) location

View File

@ -471,3 +471,24 @@ spec =
, locations = [AST.Location 2 34]
}
in validate queryString `shouldBe` Seq.singleton expected
it "rejects undefined variables" $
let queryString = [r|
query variableIsNotDefinedUsedInSingleFragment {
dog {
...isHousetrainedFragment
}
}
fragment isHousetrainedFragment on Dog {
isHousetrained(atOtherHomes: $atOtherHomes)
}
|]
expected = Error
{ message =
"Variable \"$atOtherHomes\" is not defined by \
\operation \
\\"variableIsNotDefinedUsedInSingleFragment\"."
, locations = [AST.Location 9 46]
}
in validate queryString `shouldBe` Seq.singleton expected