Adjust value completion tests
This commit is contained in:
parent
c0d41a56ce
commit
233a58094d
@ -142,14 +142,10 @@ instance Exception ResolverException where
|
||||
fromException = graphQLExceptionFromException
|
||||
|
||||
data FieldError
|
||||
= ArgumentTypeError
|
||||
| MissingArgumentError
|
||||
| ResultCoercionError
|
||||
= ResultCoercionError
|
||||
| NullResultError
|
||||
|
||||
instance Show FieldError where
|
||||
show ArgumentTypeError = "Invalid argument type."
|
||||
show MissingArgumentError = "Required argument not specified."
|
||||
show ResultCoercionError = "Result coercion failed."
|
||||
show NullResultError = "Non-Nullable field resolver returned Null."
|
||||
|
||||
@ -175,6 +171,30 @@ instance Exception ValueCompletionException where
|
||||
toException = graphQLExceptionToException
|
||||
fromException = graphQLExceptionFromException
|
||||
|
||||
data InputCoercionException = InputCoercionException String In.Type (Maybe (Full.Node Input))
|
||||
|
||||
instance Show InputCoercionException where
|
||||
show (InputCoercionException argumentName argumentType Nothing) = concat
|
||||
[ "Required argument \""
|
||||
, argumentName
|
||||
, "\" of type "
|
||||
, show argumentType
|
||||
, " not specified."
|
||||
]
|
||||
show (InputCoercionException argumentName argumentType (Just givenValue)) = concat
|
||||
[ "Argument \""
|
||||
, argumentName
|
||||
, "\" has invalid type. Expected type "
|
||||
, show argumentType
|
||||
, ", found: "
|
||||
, show givenValue
|
||||
, "."
|
||||
]
|
||||
|
||||
instance Exception InputCoercionException where
|
||||
toException = graphQLExceptionToException
|
||||
fromException = graphQLExceptionFromException
|
||||
|
||||
data QueryError
|
||||
= OperationNameRequired
|
||||
| OperationNotFound String
|
||||
@ -240,6 +260,7 @@ data Input
|
||||
| Enum Full.Name
|
||||
| List [Input]
|
||||
| Object (HashMap Full.Name Input)
|
||||
deriving Show
|
||||
|
||||
document :: Full.Document
|
||||
-> ([Full.OperationDefinition], HashMap Full.Name Full.FragmentDefinition)
|
||||
@ -541,7 +562,9 @@ executeField objectValue fields resolver errorPath =
|
||||
-> GraphQLException
|
||||
-> ExecutorT m a
|
||||
exceptionHandler fieldLocation e =
|
||||
let newError = Error (Text.pack $ displayException e) [fieldLocation] errorPath
|
||||
let newError = Error (Text.pack $ displayException e) [fieldLocation]
|
||||
$ reverse
|
||||
$ fieldsSegment fields : errorPath
|
||||
in ExecutorT (lift $ tell $ Seq.singleton newError) >> pure Coerce.null
|
||||
go fieldName inputArguments = do
|
||||
let (Out.Field _ fieldType argumentTypes, resolveFunction) =
|
||||
@ -681,9 +704,12 @@ coerceArgumentValues argumentDefinitions argumentValues =
|
||||
in case matchedMap of
|
||||
Just matchedValues -> pure matchedValues
|
||||
Nothing
|
||||
| Just _ <- HashMap.lookup argumentName argumentValues ->
|
||||
throwFieldError ArgumentTypeError
|
||||
| otherwise -> throwFieldError MissingArgumentError
|
||||
| Just inputValue <- HashMap.lookup argumentName argumentValues
|
||||
-> throwM
|
||||
$ InputCoercionException (Text.unpack argumentName) variableType
|
||||
$ Just inputValue
|
||||
| otherwise -> throwM
|
||||
$ InputCoercionException (Text.unpack argumentName) variableType Nothing
|
||||
matchFieldValues' = Coerce.matchFieldValues coerceArgumentValue
|
||||
$ Full.node <$> argumentValues
|
||||
coerceArgumentValue inputType (Int integer) =
|
||||
|
@ -235,9 +235,10 @@ spec =
|
||||
]
|
||||
]
|
||||
executionErrors = pure $ Error
|
||||
{ message = "Enum value completion failed."
|
||||
{ message =
|
||||
"Value completion error. Expected type !School, found: EXISTENTIALISM."
|
||||
, locations = [Location 1 17]
|
||||
, path = []
|
||||
, path = [Segment "philosopher", Segment "school"]
|
||||
}
|
||||
expected = Response data'' executionErrors
|
||||
Right (Right actual) = either (pure . parseError) execute'
|
||||
@ -251,9 +252,10 @@ spec =
|
||||
]
|
||||
]
|
||||
executionErrors = pure $ Error
|
||||
{ message = "Union value completion failed."
|
||||
{ message =
|
||||
"Value completion error. Expected type !Interest, found: { instrument: \"piano\" }."
|
||||
, locations = [Location 1 17]
|
||||
, path = []
|
||||
, path = [Segment "philosopher", Segment "interest"]
|
||||
}
|
||||
expected = Response data'' executionErrors
|
||||
Right (Right actual) = either (pure . parseError) execute'
|
||||
@ -267,9 +269,11 @@ spec =
|
||||
]
|
||||
]
|
||||
executionErrors = pure $ Error
|
||||
{ message = "Interface value completion failed."
|
||||
{ message
|
||||
= "Value completion error. Expected type !Work, found:\
|
||||
\ { title: \"Also sprach Zarathustra: Ein Buch f\252r Alle und Keinen\" }."
|
||||
, locations = [Location 1 17]
|
||||
, path = []
|
||||
, path = [Segment "philosopher", Segment "majorWork"]
|
||||
}
|
||||
expected = Response data'' executionErrors
|
||||
Right (Right actual) = either (pure . parseError) execute'
|
||||
|
Loading…
Reference in New Issue
Block a user