All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sentry.spring.jakarta.graphql.SentryDataFetcherExceptionResolverAdapter Maven / Gradle / Ivy

There is a newer version: 8.0.0-rc.3
Show newest version
package io.sentry.spring.jakarta.graphql;

import graphql.GraphQLError;
import graphql.execution.DataFetcherExceptionHandlerResult;
import graphql.schema.DataFetchingEnvironment;
import io.sentry.graphql.SentryGraphqlExceptionHandler;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter;

@ApiStatus.Internal
public final class SentryDataFetcherExceptionResolverAdapter
    extends DataFetcherExceptionResolverAdapter {
  private final @NotNull SentryGraphqlExceptionHandler handler;

  public SentryDataFetcherExceptionResolverAdapter() {
    this.handler = new SentryGraphqlExceptionHandler(null);
  }

  @Override
  public boolean isThreadLocalContextAware() {
    return true;
  }

  @Override
  protected @Nullable GraphQLError resolveToSingleError(Throwable ex, DataFetchingEnvironment env) {
    List errors = resolveToMultipleErrors(ex, env);
    if (errors != null && !errors.isEmpty()) {
      return errors.get(0);
    }
    return null;
  }

  @Override
  protected @Nullable List resolveToMultipleErrors(
      Throwable ex, DataFetchingEnvironment env) {
    @Nullable
    CompletableFuture result =
        handler.handleException(ex, env, null);
    if (result != null) {
      return result.join().getErrors();
    }
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy