forked from OSS/graphql
Provide location information for interface errors
This commit is contained in:
parent
c311cb0070
commit
2ce2be5d91
@ -132,12 +132,13 @@ completeValue (Out.ObjectBaseType objectType) fields result =
|
||||
completeValue (Out.InterfaceBaseType interfaceType) fields result
|
||||
| Type.Object objectMap <- result = do
|
||||
let abstractType = Internal.AbstractInterfaceType interfaceType
|
||||
let Transform.Field _ _ _ _ location = NonEmpty.head fields
|
||||
concreteType <- resolveAbstractType abstractType objectMap
|
||||
case concreteType of
|
||||
Just objectType -> executeSelectionSet result objectType
|
||||
$ mergeSelectionSets fields
|
||||
Nothing -> addError null
|
||||
$ Error "Interface value completion failed." [] []
|
||||
$ Error "Interface value completion failed." [location] []
|
||||
completeValue (Out.UnionBaseType unionType) fields result
|
||||
| Type.Object objectMap <- result = do
|
||||
let abstractType = Internal.AbstractUnionType unionType
|
||||
@ -148,7 +149,8 @@ completeValue (Out.UnionBaseType unionType) fields result
|
||||
$ mergeSelectionSets fields
|
||||
Nothing -> addError null
|
||||
$ Error "Union value completion failed." [location] []
|
||||
completeValue _ _ _ = addError null $ Error "Value completion failed." [] []
|
||||
completeValue _ (Transform.Field _ _ _ _ location :| _) _ =
|
||||
addError null $ Error "Value completion failed." [location] []
|
||||
|
||||
mergeSelectionSets :: MonadCatch m
|
||||
=> NonEmpty (Transform.Field m)
|
||||
|
@ -218,7 +218,7 @@ spec =
|
||||
$ parse document "" "{ philosopher { school } }"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "gives location information for invalid interfaces" $
|
||||
it "gives location information for non-null unions" $
|
||||
let data'' = Aeson.object
|
||||
[ "philosopher" .= Aeson.object
|
||||
[ "interest" .= Aeson.Null
|
||||
@ -234,6 +234,22 @@ spec =
|
||||
$ parse document "" "{ philosopher { interest } }"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "gives location information for invalid interfaces" $
|
||||
let data'' = Aeson.object
|
||||
[ "philosopher" .= Aeson.object
|
||||
[ "majorWork" .= Aeson.Null
|
||||
]
|
||||
]
|
||||
executionErrors = pure $ Error
|
||||
{ message = "Interface value completion failed."
|
||||
, locations = [Location 1 17]
|
||||
, path = []
|
||||
}
|
||||
expected = Response data'' executionErrors
|
||||
Right (Right actual) = either (pure . parseError) execute'
|
||||
$ parse document "" "{ philosopher { majorWork { title } } }"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
context "Subscription" $
|
||||
it "subscribes" $
|
||||
let data'' = Aeson.object
|
||||
|
Loading…
Reference in New Issue
Block a user