Search in sources :

Example 1 with InvokeInfo

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);
        }
    }
}
Also used : Uni(io.smallrye.mutiny.Uni) InvokeInfo(io.smallrye.graphql.execution.event.InvokeInfo) Multi(io.smallrye.mutiny.Multi) GraphQLException(org.eclipse.microprofile.graphql.GraphQLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrivilegedActionException(java.security.PrivilegedActionException) GraphQLException(org.eclipse.microprofile.graphql.GraphQLException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvokeInfo (io.smallrye.graphql.execution.event.InvokeInfo)1 Multi (io.smallrye.mutiny.Multi)1 Uni (io.smallrye.mutiny.Uni)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 GraphQLException (org.eclipse.microprofile.graphql.GraphQLException)1