diff options
| author | Eugen Wissner <belka@caraus.de> | 2021-09-01 08:51:20 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2021-09-01 09:27:12 +0200 |
| commit | 233a58094da9f5e02b4000dbef2c183d65a8017d (patch) | |
| tree | 47288dedf910f0a517bfdf84ec63a6494e672477 /src/Language | |
| parent | c0d41a56ce81bb8ce385a56a9e36ac8f0f05df23 (diff) | |
| download | graphql-233a58094da9f5e02b4000dbef2c183d65a8017d.tar.gz | |
Adjust value completion tests
Diffstat (limited to 'src/Language')
| -rw-r--r-- | src/Language/GraphQL/Execute.hs | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/Language/GraphQL/Execute.hs b/src/Language/GraphQL/Execute.hs index 1ccdee0..3321152 100644 --- a/src/Language/GraphQL/Execute.hs +++ b/src/Language/GraphQL/Execute.hs @@ -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) = |
