forked from OSS/graphql
Traverse input object properties once
This commit is contained in:
parent
d6dda14cfd
commit
5654b78935
@ -14,8 +14,10 @@ and this project adheres to
|
|||||||
### Fixed
|
### Fixed
|
||||||
- Parser now accepts empty lists and objects.
|
- Parser now accepts empty lists and objects.
|
||||||
- Parser now accepts all directive locations.
|
- Parser now accepts all directive locations.
|
||||||
- `valuesOfCorrectTypeRule` doesn't check list items recursively since the
|
- `valuesOfCorrectTypeRule` doesn't check lists recursively since the
|
||||||
validation traverser calls it on all list items.
|
validation traverser calls it on all list items.
|
||||||
|
- `valuesOfCorrectTypeRule` doesn't check objects recursively since the
|
||||||
|
validation traverser calls it on all object properties.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- `AST.Document.Value.List` and `AST.Document.ConstValue.ConstList` contain
|
- `AST.Document.Value.List` and `AST.Document.ConstValue.ConstList` contain
|
||||||
|
@ -88,9 +88,6 @@ test-suite graphql-test
|
|||||||
Test.DirectiveSpec
|
Test.DirectiveSpec
|
||||||
Test.FragmentSpec
|
Test.FragmentSpec
|
||||||
Test.RootOperationSpec
|
Test.RootOperationSpec
|
||||||
Paths_graphql
|
|
||||||
autogen-modules:
|
|
||||||
Paths_graphql
|
|
||||||
hs-source-dirs:
|
hs-source-dirs:
|
||||||
tests
|
tests
|
||||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||||
|
@ -1582,24 +1582,20 @@ valuesOfCorrectTypeRule = ValueRule go constGo
|
|||||||
, Full.ConstEnum memberValue <- node
|
, Full.ConstEnum memberValue <- node
|
||||||
, HashMap.member memberValue members = mempty
|
, HashMap.member memberValue members = mempty
|
||||||
check (In.InputObjectBaseType objectType) Full.Node{ node }
|
check (In.InputObjectBaseType objectType) Full.Node{ node }
|
||||||
| In.InputObjectType _ _ typeFields <- objectType
|
-- Skip, objects are checked recursively by the validation traverser.
|
||||||
, Full.ConstObject valueFields <- node =
|
| In.InputObjectType{} <- objectType
|
||||||
foldMap (checkObjectField typeFields) valueFields
|
, Full.ConstObject{} <- node = mempty
|
||||||
check (In.ListBaseType listType) constValue@Full.Node{ .. }
|
check (In.ListBaseType listType) constValue@Full.Node{ .. }
|
||||||
-- Skip, lists are checked recursively by the validation traverser.
|
-- Skip, lists are checked recursively by the validation traverser.
|
||||||
| Full.ConstList _ <- node = mempty
|
| Full.ConstList{} <- node = mempty
|
||||||
| otherwise = check listType constValue
|
| otherwise = check listType constValue
|
||||||
check inputType Full.Node{ .. } = pure $ Error
|
check inputType Full.Node{ .. } = pure $ Error
|
||||||
{ message = concat
|
{ message = concat
|
||||||
[ "Value "
|
[ "Value "
|
||||||
, show node, " cannot be coerced to type \""
|
, show node
|
||||||
|
, " cannot be coerced to type \""
|
||||||
, show inputType
|
, show inputType
|
||||||
, "\"."
|
, "\"."
|
||||||
]
|
]
|
||||||
, locations = [location]
|
, locations = [location]
|
||||||
}
|
}
|
||||||
checkObjectField typeFields Full.ObjectField{..}
|
|
||||||
| Just typeField <- HashMap.lookup name typeFields
|
|
||||||
, In.InputField _ fieldType _ <- typeField =
|
|
||||||
check fieldType value
|
|
||||||
checkObjectField _ _ = mempty
|
|
||||||
|
@ -929,3 +929,18 @@ spec =
|
|||||||
, locations = [AST.Location 4 54]
|
, locations = [AST.Location 4 54]
|
||||||
}
|
}
|
||||||
in validate queryString `shouldBe` [expected]
|
in validate queryString `shouldBe` [expected]
|
||||||
|
|
||||||
|
it "validates input object properties once" $
|
||||||
|
let queryString = [r|
|
||||||
|
{
|
||||||
|
findDog(complex: { name: 3 }) {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
expected = Error
|
||||||
|
{ message =
|
||||||
|
"Value 3 cannot be coerced to type \"!String\"."
|
||||||
|
, locations = [AST.Location 3 46]
|
||||||
|
}
|
||||||
|
in validate queryString `shouldBe` [expected]
|
||||||
|
Loading…
Reference in New Issue
Block a user