-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into jj--ui-run-summary
- Loading branch information
Showing
88 changed files
with
5,725 additions
and
980 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/MutableTypeBatchResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.linkedin.datahub.graphql.resolvers.mutate; | ||
|
||
import com.codahale.metrics.Timer; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.types.BatchMutableType; | ||
import com.linkedin.metadata.utils.metrics.MetricUtils; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
/** | ||
* Generic GraphQL resolver responsible for performing updates against particular types. | ||
* | ||
* @param <I> the generated GraphQL POJO corresponding to the input type. | ||
* @param <T> the generated GraphQL POJO corresponding to the return type. | ||
*/ | ||
public class MutableTypeBatchResolver<I, B, T> implements DataFetcher<CompletableFuture<List<T>>> { | ||
|
||
private static final Logger _logger = LoggerFactory.getLogger(MutableTypeBatchResolver.class.getName()); | ||
|
||
private final BatchMutableType<I, B, T> _batchMutableType; | ||
|
||
public MutableTypeBatchResolver(final BatchMutableType<I, B, T> batchMutableType) { | ||
_batchMutableType = batchMutableType; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<List<T>> get(DataFetchingEnvironment environment) throws Exception { | ||
final B[] input = bindArgument(environment.getArgument("input"), _batchMutableType.batchInputClass()); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
Timer.Context timer = MetricUtils.timer(this.getClass(), "batchMutate").time(); | ||
|
||
try { | ||
return _batchMutableType.batchUpdate(input, environment.getContext()); | ||
} catch (AuthorizationException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
_logger.error("Failed to perform batchUpdate", e); | ||
throw new IllegalArgumentException(e); | ||
} finally { | ||
timer.stop(); | ||
} | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/types/BatchMutableType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.linkedin.datahub.graphql.types; | ||
|
||
import com.linkedin.datahub.graphql.QueryContext; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
|
||
public interface BatchMutableType<I, B, T> extends MutableType<I, T> { | ||
default Class<B[]> batchInputClass() throws UnsupportedOperationException { | ||
throw new UnsupportedOperationException(this.getClass().getName() + " does not implement batchInputClass method"); | ||
} | ||
|
||
default List<T> batchUpdate(@Nonnull final B[] updateInput, QueryContext context) throws Exception { | ||
throw new UnsupportedOperationException(this.getClass().getName() + " does not implement batchUpdate method"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.