Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(graphql): add MutableTypeBatchResolver #4976

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8cae5ea
feat(graphql): add MutableType.batchUpdate method
noahfrn May 23, 2022
c40c672
feat(graphql): add MutableTypeBatchResolver.java
noahfrn May 23, 2022
6cbdda8
feat(graphql): add MutableType.arrayInputClass method
noahfrn May 24, 2022
6076b0c
fix(graphql): correct typos
noahfrn May 24, 2022
87f17af
fix(graphql): throw exception when batchUpdate is called without bein…
noahfrn May 24, 2022
88c046b
fix(graphql): fix typo
noahfrn May 25, 2022
ad65a42
feat(graphql): implement arrayInputClass for mutable types
noahfrn May 25, 2022
4ac9b6f
test(graphql): add failure tests for MutableTypeBatchResolver
noahfrn May 25, 2022
44d6afe
Merge branch 'datahub-project:master' into graphql-mutable-batch-reso…
noahfrn Jul 8, 2022
759a9b0
feat(graphql): add batchUpdate support for Datasets
noahfrn Jul 8, 2022
7ba0d97
fix(graphql): fix graphql checktyle violations
noahfrn Jul 8, 2022
9f5845f
fix(graphql): fix typo
noahfrn Jul 8, 2022
ca09967
Merge branch 'datahub-project:master' into graphql-mutable-batch-reso…
noahfrn Jul 27, 2022
db7cc51
Add BatchDatasetUpdateInput and BatchMutableType
noahfrn Jul 28, 2022
20de27d
fix(graphql): Add BatchMutableType
noahfrn Jul 28, 2022
38f995a
fix(graphql): Revert whitespace change
noahfrn Jul 28, 2022
98ce1d9
docs(graphql): Add field descriptions for BatchDatasetUpdateInput
noahfrn Jul 29, 2022
04562fc
fix(graphql): Use more generic Urn class instead of CorpuserUrn
noahfrn Jul 29, 2022
33a1957
test(graphql): Add MutableTypeBatchResolverTest success case
noahfrn Jul 29, 2022
ba8b8b1
style(graphql): Fix test checkstyle
noahfrn Aug 2, 2022
f638785
Merge branch 'master' into graphql-mutable-batch-resolver
noahfrn Aug 2, 2022
a11015b
Merge branch 'master' into graphql-mutable-batch-resolver
noahfrn Aug 4, 2022
be04661
Merge branch 'master' into graphql-mutable-batch-resolver
jjoyce0510 Aug 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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.MutableType;
import com.linkedin.metadata.utils.metrics.MetricUtils;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
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, T> implements DataFetcher<CompletableFuture<T>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Do you mind adding a unit test for this one?


private static final Logger _logger = LoggerFactory.getLogger(MutableTypeResolverBatch.class.getName());

private final MutableType<I> _mutableType;

public MutableTypeResolverBatch(final MutableType<I> mutableType) {
_mutableType = mutableType;
}

@Override
public CompletableFuture<T> get(DataFetchingEnvironment environment) throws Exception {
final I[] inputs = bindArgument(environment.getArgument("inputs"), _mutableType.arrayInputClass());

return CompletableFuture.supplyAsync(() -> {
Timer.Context timer = MetricUtils.timer(this.getClass(), "batchMutate").time();

try {
return _mutableType.batchUpdate(inputs, environment.getContext());
} catch (AuthorizationException e) {
throw e;
} catch (Exception e) {
_logger.error("Failed to perform batchUpdate", e);
throw new IllegalArgumentException(e);
} finally {
timer.stop();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ public interface MutableType<I, T> {
* @param context the {@link QueryContext} corresponding to the request.
*/
T update(@Nonnull final String urn, @Nonnull final I input, @Nonnull final QueryContext context) throws Exception;

/**
* Update many entities
*
* @param input input type
* @param context the {@link QueryContext} corresponding to the request.
*/
default <T> T batchUpdate(@Nonnull final I[] input, @Nonnull final QueryContext context) throws Exception {
return null;
noahfrn marked this conversation as resolved.
Show resolved Hide resolved
}
}