use of io.smallrye.graphql.execution.event.InvokeInfo in project smallrye-graphql by smallrye.
the class ReflectionInvoker method invoke.
public <T> T invoke(Object... arguments) throws Exception {
if (this.injectContextAt > -1) {
arguments = injectContext(arguments);
}
try {
ManagedInstance<?> operationInstance = lookupService.getInstance(operationClass);
Object operationInstance1 = operationInstance.get();
eventEmitter.fireBeforeMethodInvoke(new InvokeInfo(operationInstance1, method, arguments));
T result = (T) method.invoke(operationInstance1, arguments);
if (result instanceof Uni) {
return (T) ((Uni) result).onTermination().invoke(() -> {
operationInstance.destroyIfNecessary();
});
} else if (result instanceof Multi) {
return (T) ((Multi) result).onTermination().invoke(() -> {
operationInstance.destroyIfNecessary();
});
} else {
operationInstance.destroyIfNecessary();
return result;
}
} catch (InvocationTargetException ex) {
// Invoked method has thrown something, unwrap
Throwable throwable = ex.getCause();
if (throwable instanceof Error) {
throw (Error) throwable;
} else if (throwable instanceof GraphQLException) {
throw (GraphQLException) throwable;
} else if (throwable instanceof Exception) {
throw (Exception) throwable;
} else {
throw msg.generalDataFetcherException(operationClass.getName() + ": " + method.getName(), throwable);
}
}
}
Aggregations