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): Adding resolved users and groups to policies #4272

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -8,6 +8,7 @@
import com.linkedin.datahub.graphql.analytics.resolver.GetMetadataAnalyticsResolver;
import com.linkedin.datahub.graphql.analytics.resolver.IsAnalyticsEnabledResolver;
import com.linkedin.datahub.graphql.analytics.service.AnalyticsService;
import com.linkedin.datahub.graphql.generated.ActorFilter;
import com.linkedin.datahub.graphql.generated.AggregationMetadata;
import com.linkedin.datahub.graphql.generated.Aspect;
import com.linkedin.datahub.graphql.generated.BrowseResults;
Expand Down Expand Up @@ -455,6 +456,7 @@ public void configureRuntimeWiring(final RuntimeWiring.Builder builder) {
configureContainerResolvers(builder);
configureGlossaryTermResolvers(builder);
configureDomainResolvers(builder);
configurePolicyResolvers(builder);
}

public GraphQLEngine.Builder builder() {
Expand Down Expand Up @@ -1112,6 +1114,24 @@ private void configureDomainResolvers(final RuntimeWiring.Builder builder) {
);
}

private void configurePolicyResolvers(final RuntimeWiring.Builder builder) {
// Register resolvers for "resolvedUsers" and "resolvedGroups" field of the Policy type.
builder.type("ActorFilter", typeWiring -> typeWiring
.dataFetcher("resolvedUsers", new LoadableTypeBatchResolver<>(corpUserType,
(env) -> {
final ActorFilter filter = env.getSource();
return filter.getUsers();
}
))
.dataFetcher("resolvedGroups", new LoadableTypeBatchResolver<>(corpGroupType,
(env) -> {
final ActorFilter filter = env.getSource();
return filter.getGroups();
}
))
);
}

private <T> DataLoader<String, DataFetcherResult<T>> createDataLoader(final LoadableType<T> graphType, final QueryContext queryContext) {
BatchLoaderContextProvider contextProvider = () -> queryContext;
DataLoaderOptions loaderOptions = DataLoaderOptions.newOptions().setBatchLoaderContextProvider(contextProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public LoadableTypeBatchResolver(final LoadableType<T> loadableType, final Funct
@Override
public CompletableFuture<List<T>> get(DataFetchingEnvironment environment) {
final List<String> urns = _urnProvider.apply(environment);
if (urns == null) {
return null;
}
final DataLoader<String, T> loader = environment.getDataLoaderRegistry().getDataLoader(_loadableType.name());
return loader.loadMany(urns);
}
Expand Down
10 changes: 10 additions & 0 deletions datahub-graphql-core/src/main/resources/entity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4724,6 +4724,16 @@ type ActorFilter {
Whether the filter should apply to all groups
"""
allGroups: Boolean!

"""
The list of users on the Policy, resolved.
"""
resolvedUsers: [CorpUser!]

"""
The list of groups on the Policy, resolved.
"""
resolvedGroups: [CorpGroup!]
}

"""
Expand Down
31 changes: 31 additions & 0 deletions datahub-web-react/src/graphql/policy.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@ query listPolicies($input: ListPoliciesInput!) {
allUsers
allGroups
resourceOwners
resolvedUsers {
username
properties {
active
displayName
title
firstName
lastName
fullName
email
}
editableProperties {
displayName
pictureLink
teams
title
skills
}
}
resolvedGroups {
properties {
displayName
description
email
}
editableProperties {
description
slack
email
}
}
}
editable
}
Expand Down