From cbf9b11fcb052dcacbae31cfcd4e111c04c381d7 Mon Sep 17 00:00:00 2001 From: John Joyce Date: Mon, 28 Feb 2022 11:52:04 -0800 Subject: [PATCH] Adding resolved users and groups to policies --- .../datahub/graphql/GmsGraphQLEngine.java | 20 ++++++++++++ .../load/LoadableTypeBatchResolver.java | 3 ++ .../src/main/resources/entity.graphql | 10 ++++++ datahub-web-react/src/graphql/policy.graphql | 31 +++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/GmsGraphQLEngine.java b/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/GmsGraphQLEngine.java index 6614d9f0de5653..0433c3d3e4146a 100644 --- a/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/GmsGraphQLEngine.java +++ b/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/GmsGraphQLEngine.java @@ -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; @@ -455,6 +456,7 @@ public void configureRuntimeWiring(final RuntimeWiring.Builder builder) { configureContainerResolvers(builder); configureGlossaryTermResolvers(builder); configureDomainResolvers(builder); + configurePolicyResolvers(builder); } public GraphQLEngine.Builder builder() { @@ -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 DataLoader> createDataLoader(final LoadableType graphType, final QueryContext queryContext) { BatchLoaderContextProvider contextProvider = () -> queryContext; DataLoaderOptions loaderOptions = DataLoaderOptions.newOptions().setBatchLoaderContextProvider(contextProvider); diff --git a/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/load/LoadableTypeBatchResolver.java b/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/load/LoadableTypeBatchResolver.java index e227f153bac5f2..be932011fbb224 100644 --- a/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/load/LoadableTypeBatchResolver.java +++ b/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/load/LoadableTypeBatchResolver.java @@ -33,6 +33,9 @@ public LoadableTypeBatchResolver(final LoadableType loadableType, final Funct @Override public CompletableFuture> get(DataFetchingEnvironment environment) { final List urns = _urnProvider.apply(environment); + if (urns == null) { + return null; + } final DataLoader loader = environment.getDataLoaderRegistry().getDataLoader(_loadableType.name()); return loader.loadMany(urns); } diff --git a/datahub-graphql-core/src/main/resources/entity.graphql b/datahub-graphql-core/src/main/resources/entity.graphql index 5940cd2c247c71..b2310b5126b332 100644 --- a/datahub-graphql-core/src/main/resources/entity.graphql +++ b/datahub-graphql-core/src/main/resources/entity.graphql @@ -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!] } """ diff --git a/datahub-web-react/src/graphql/policy.graphql b/datahub-web-react/src/graphql/policy.graphql index f1eac2905c8ed8..d988cc4d7ddfa1 100644 --- a/datahub-web-react/src/graphql/policy.graphql +++ b/datahub-web-react/src/graphql/policy.graphql @@ -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 }