Skip to content

Commit

Permalink
feat(views): Adding GraphQL resolvers and schema changes for views fe…
Browse files Browse the repository at this point in the history
…ature. (datahub-project#994)

- Adding GraphQL schemas, resolvers for supporting Views and related settings + privileges.
  • Loading branch information
jjoyce0510 committed Dec 6, 2022
1 parent 044e828 commit e1b0539
Show file tree
Hide file tree
Showing 57 changed files with 4,243 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.linkedin.datahub.graphql.generated.DashboardStatsSummary;
import com.linkedin.datahub.graphql.generated.DashboardUserUsageCounts;
import com.linkedin.datahub.graphql.generated.DataFlow;
import com.linkedin.datahub.graphql.generated.DataHubView;
import com.linkedin.datahub.graphql.generated.DataJob;
import com.linkedin.datahub.graphql.generated.DataJobInputOutput;
import com.linkedin.datahub.graphql.generated.DataPlatformInstance;
Expand All @@ -59,6 +60,7 @@
import com.linkedin.datahub.graphql.generated.ListAccessTokenResult;
import com.linkedin.datahub.graphql.generated.ListDomainsResult;
import com.linkedin.datahub.graphql.generated.ListTestsResult;
import com.linkedin.datahub.graphql.generated.ListViewsResult;
import com.linkedin.datahub.graphql.generated.MLFeature;
import com.linkedin.datahub.graphql.generated.MLFeatureProperties;
import com.linkedin.datahub.graphql.generated.MLFeatureTable;
Expand Down Expand Up @@ -174,6 +176,7 @@
import com.linkedin.datahub.graphql.resolvers.mutate.UpdateNameResolver;
import com.linkedin.datahub.graphql.resolvers.mutate.UpdateParentNodeResolver;
import com.linkedin.datahub.graphql.resolvers.mutate.UpdateUserSettingResolver;
import com.linkedin.datahub.graphql.resolvers.settings.user.UpdateCorpUserViewsSettingsResolver;
import com.linkedin.datahub.graphql.resolvers.operation.ReportOperationResolver;
import com.linkedin.datahub.graphql.resolvers.policy.DeletePolicyResolver;
import com.linkedin.datahub.graphql.resolvers.policy.GetGrantedPrivilegesResolver;
Expand All @@ -192,6 +195,8 @@
import com.linkedin.datahub.graphql.resolvers.search.SearchAcrossEntitiesResolver;
import com.linkedin.datahub.graphql.resolvers.search.SearchAcrossLineageResolver;
import com.linkedin.datahub.graphql.resolvers.search.SearchResolver;
import com.linkedin.datahub.graphql.resolvers.settings.view.GlobalViewsSettingsResolver;
import com.linkedin.datahub.graphql.resolvers.settings.view.UpdateGlobalViewsSettingsResolver;
import com.linkedin.datahub.graphql.resolvers.tag.CreateTagResolver;
import com.linkedin.datahub.graphql.resolvers.tag.DeleteTagResolver;
import com.linkedin.datahub.graphql.resolvers.tag.SetTagColorResolver;
Expand All @@ -212,6 +217,11 @@
import com.linkedin.datahub.graphql.resolvers.user.ListUsersResolver;
import com.linkedin.datahub.graphql.resolvers.user.RemoveUserResolver;
import com.linkedin.datahub.graphql.resolvers.user.UpdateUserStatusResolver;
import com.linkedin.datahub.graphql.resolvers.view.CreateViewResolver;
import com.linkedin.datahub.graphql.resolvers.view.DeleteViewResolver;
import com.linkedin.datahub.graphql.resolvers.view.ListGlobalViewsResolver;
import com.linkedin.datahub.graphql.resolvers.view.ListMyViewsResolver;
import com.linkedin.datahub.graphql.resolvers.view.UpdateViewResolver;
import com.linkedin.datahub.graphql.types.BrowsableEntityType;
import com.linkedin.datahub.graphql.types.EntityType;
import com.linkedin.datahub.graphql.types.LoadableType;
Expand Down Expand Up @@ -248,17 +258,21 @@
import com.linkedin.datahub.graphql.types.schemafield.SchemaFieldType;
import com.linkedin.datahub.graphql.types.tag.TagType;
import com.linkedin.datahub.graphql.types.test.TestType;
import com.linkedin.datahub.graphql.types.view.DataHubViewType;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.metadata.config.DataHubConfiguration;
import com.linkedin.metadata.config.IngestionConfiguration;
import com.linkedin.metadata.config.TestsConfiguration;
import com.linkedin.metadata.config.ViewsConfiguration;
import com.linkedin.metadata.config.VisualConfiguration;
import com.linkedin.metadata.entity.EntityService;
import com.linkedin.metadata.graph.GraphClient;
import com.linkedin.metadata.graph.SiblingGraphService;
import com.linkedin.metadata.models.registry.EntityRegistry;
import com.linkedin.metadata.recommendation.RecommendationsService;
import com.linkedin.metadata.secret.SecretService;
import com.linkedin.metadata.service.SettingsService;
import com.linkedin.metadata.service.ViewService;
import com.linkedin.metadata.telemetry.TelemetryConfiguration;
import com.linkedin.metadata.timeline.TimelineService;
import com.linkedin.metadata.timeseries.TimeseriesAspectService;
Expand Down Expand Up @@ -318,6 +332,8 @@ public class GmsGraphQLEngine {
private final RoleService roleService;
private final InviteTokenService inviteTokenService;
private final PostService postService;
private final SettingsService settingsService;
private final ViewService viewService;

private final FeatureFlags featureFlags;

Expand All @@ -328,6 +344,7 @@ public class GmsGraphQLEngine {
private final TelemetryConfiguration telemetryConfiguration;
private final TestsConfiguration testsConfiguration;
private final DataHubConfiguration datahubConfiguration;
private final ViewsConfiguration viewsConfiguration;

private final DatasetType datasetType;
private final CorpUserType corpUserType;
Expand Down Expand Up @@ -357,6 +374,7 @@ public class GmsGraphQLEngine {
private final DataHubPolicyType dataHubPolicyType;
private final DataHubRoleType dataHubRoleType;
private final SchemaFieldType schemaFieldType;
private final DataHubViewType dataHubViewType;

/**
* Configures the graph objects that can be fetched primary key.
Expand Down Expand Up @@ -394,8 +412,12 @@ public GmsGraphQLEngine(final EntityClient entityClient, final GraphClient graph
final TimelineService timelineService, final boolean supportsImpactAnalysis,
final VisualConfiguration visualConfiguration, final TelemetryConfiguration telemetryConfiguration,
final TestsConfiguration testsConfiguration, final DataHubConfiguration datahubConfiguration,
final SiblingGraphService siblingGraphService, final GroupService groupService, final RoleService roleService,
final InviteTokenService inviteTokenService, final PostService postService, final FeatureFlags featureFlags) {
final ViewsConfiguration viewsConfiguration, final SiblingGraphService siblingGraphService,
final GroupService groupService, final RoleService roleService,
final InviteTokenService inviteTokenService, final PostService postService,
final ViewService viewService,
final SettingsService settingsService,
final FeatureFlags featureFlags) {

this.entityClient = entityClient;
this.graphClient = graphClient;
Expand All @@ -417,6 +439,8 @@ public GmsGraphQLEngine(final EntityClient entityClient, final GraphClient graph
this.roleService = roleService;
this.inviteTokenService = inviteTokenService;
this.postService = postService;
this.viewService = viewService;
this.settingsService = settingsService;

this.ingestionConfiguration = Objects.requireNonNull(ingestionConfiguration);
this.authenticationConfiguration = Objects.requireNonNull(authenticationConfiguration);
Expand All @@ -425,6 +449,7 @@ public GmsGraphQLEngine(final EntityClient entityClient, final GraphClient graph
this.telemetryConfiguration = telemetryConfiguration;
this.testsConfiguration = testsConfiguration;
this.datahubConfiguration = datahubConfiguration;
this.viewsConfiguration = viewsConfiguration;
this.featureFlags = featureFlags;

this.datasetType = new DatasetType(entityClient);
Expand Down Expand Up @@ -455,6 +480,8 @@ public GmsGraphQLEngine(final EntityClient entityClient, final GraphClient graph
this.dataHubPolicyType = new DataHubPolicyType(entityClient);
this.dataHubRoleType = new DataHubRoleType(entityClient);
this.schemaFieldType = new SchemaFieldType();
this.dataHubViewType = new DataHubViewType(entityClient);

// Init Lists
this.entityTypes = ImmutableList.of(
datasetType,
Expand Down Expand Up @@ -483,7 +510,8 @@ public GmsGraphQLEngine(final EntityClient entityClient, final GraphClient graph
testType,
dataHubPolicyType,
dataHubRoleType,
schemaFieldType
schemaFieldType,
dataHubViewType
);
this.loadableTypes = new ArrayList<>(entityTypes);
this.ownerTypes = ImmutableList.of(corpUserType, corpGroupType);
Expand Down Expand Up @@ -544,6 +572,7 @@ public void configureRuntimeWiring(final RuntimeWiring.Builder builder) {
configureRoleResolvers(builder);
configureSchemaFieldResolvers(builder);
configureEntityPathResolvers(builder);
configureViewResolvers(builder);
}

public GraphQLEngine.Builder builder() {
Expand Down Expand Up @@ -632,7 +661,8 @@ private void configureQueryResolvers(final RuntimeWiring.Builder builder) {
this.visualConfiguration,
this.telemetryConfiguration,
this.testsConfiguration,
this.datahubConfiguration
this.datahubConfiguration,
this.viewsConfiguration
))
.dataFetcher("me", new MeResolver(this.entityClient, featureFlags))
.dataFetcher("search", new SearchResolver(this.entityClient))
Expand Down Expand Up @@ -691,6 +721,9 @@ private void configureQueryResolvers(final RuntimeWiring.Builder builder) {
.dataFetcher("listRoles", new ListRolesResolver(this.entityClient))
.dataFetcher("getInviteToken", new GetInviteTokenResolver(this.inviteTokenService))
.dataFetcher("listPosts", new ListPostsResolver(this.entityClient))
.dataFetcher("listMyViews", new ListMyViewsResolver(this.entityClient))
.dataFetcher("listGlobalViews", new ListGlobalViewsResolver(this.entityClient))

);
}

Expand Down Expand Up @@ -814,6 +847,12 @@ private void configureMutationResolvers(final RuntimeWiring.Builder builder) {
.dataFetcher("createInviteToken", new CreateInviteTokenResolver(this.inviteTokenService))
.dataFetcher("acceptRole", new AcceptRoleResolver(this.roleService, this.inviteTokenService))
.dataFetcher("createPost", new CreatePostResolver(this.postService))
.dataFetcher("createView", new CreateViewResolver(this.viewService))
.dataFetcher("updateView", new UpdateViewResolver(this.viewService))
.dataFetcher("deleteView", new DeleteViewResolver(this.viewService))
.dataFetcher("globalViewsSettings", new GlobalViewsSettingsResolver(this.settingsService))
.dataFetcher("updateGlobalViewsSettings", new UpdateGlobalViewsSettingsResolver(this.settingsService))
.dataFetcher("updateCorpUserViewsSettings", new UpdateCorpUserViewsSettingsResolver(this.settingsService))
);
}

Expand Down Expand Up @@ -1476,6 +1515,19 @@ private void configureRoleResolvers(final RuntimeWiring.Builder builder) {
typeWiring -> typeWiring.dataFetcher("relationships", new EntityRelationshipsResultResolver(graphClient)));
}

private void configureViewResolvers(final RuntimeWiring.Builder builder) {
builder
.type("DataHubView",
typeWiring -> typeWiring.dataFetcher("relationships", new EntityRelationshipsResultResolver(graphClient)))
.type("ListViewsResult", typeWiring -> typeWiring
.dataFetcher("views", new LoadableTypeBatchResolver<>(
dataHubViewType,
(env) -> ((ListViewsResult) env.getSource()).getViews().stream()
.map(DataHubView::getUrn)
.collect(Collectors.toList())))
);
}

private void configureDataProcessInstanceResolvers(final RuntimeWiring.Builder builder) {
builder.type("DataProcessInstance",
typeWiring -> typeWiring.dataFetcher("relationships", new EntityRelationshipsResultResolver(graphClient))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public static boolean canCreateGlobalAnnouncements(@Nonnull QueryContext context
return isAuthorized(context, Optional.empty(), PoliciesConfig.CREATE_GLOBAL_ANNOUNCEMENTS_PRIVILEGE);
}

public static boolean canManageGlobalViews(@Nonnull QueryContext context) {
return isAuthorized(context, Optional.empty(), PoliciesConfig.MANAGE_GLOBAL_VIEWS);
}

public static boolean isAuthorized(
@Nonnull QueryContext context,
@Nonnull Optional<ResourceSpec> resourceSpec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public CompletableFuture<AuthenticatedUser> get(DataFetchingEnvironment environm
platformPrivileges.setCreateDomains(AuthorizationUtils.canCreateDomains(context));
platformPrivileges.setCreateTags(AuthorizationUtils.canCreateTags(context));
platformPrivileges.setManageTags(AuthorizationUtils.canManageTags(context));
platformPrivileges.setManageGlobalViews(AuthorizationUtils.canManageGlobalViews(context));

// Construct and return authenticated user object.
final AuthenticatedUser authUser = new AuthenticatedUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.linkedin.datahub.graphql.exception.ValidationException;
import com.linkedin.datahub.graphql.generated.FacetFilterInput;

import com.linkedin.datahub.graphql.generated.OrFilter;
import com.linkedin.datahub.graphql.generated.AndFilterInput;
import com.linkedin.metadata.query.filter.Condition;
import com.linkedin.metadata.query.filter.Criterion;
import com.linkedin.metadata.query.filter.CriterionArray;
Expand Down Expand Up @@ -103,7 +103,7 @@ public static List<Criterion> criterionListFromAndFilter(List<FacetFilterInput>
// In the case that user sends filters to be or-d together, we need to build a series of conjunctive criterion
// arrays, rather than just one for the AND case.
public static ConjunctiveCriterionArray buildConjunctiveCriterionArrayWithOr(
@Nonnull List<OrFilter> orFilters
@Nonnull List<AndFilterInput> orFilters
) {
return new ConjunctiveCriterionArray(orFilters.stream().map(orFilter -> {
CriterionArray andCriterionForOr = new CriterionArray(criterionListFromAndFilter(orFilter.getAnd()));
Expand All @@ -115,7 +115,7 @@ public static ConjunctiveCriterionArray buildConjunctiveCriterionArrayWithOr(
}

@Nullable
public static Filter buildFilter(@Nullable List<FacetFilterInput> andFilters, @Nullable List<OrFilter> orFilters) {
public static Filter buildFilter(@Nullable List<FacetFilterInput> andFilters, @Nullable List<AndFilterInput> orFilters) {
if ((andFilters == null || andFilters.isEmpty()) && (orFilters == null || orFilters.isEmpty())) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import com.linkedin.datahub.graphql.generated.ResourcePrivileges;
import com.linkedin.datahub.graphql.generated.TelemetryConfig;
import com.linkedin.datahub.graphql.generated.TestsConfig;
import com.linkedin.datahub.graphql.generated.ViewsConfig;
import com.linkedin.datahub.graphql.generated.VisualConfig;
import com.linkedin.metadata.config.DataHubConfiguration;
import com.linkedin.metadata.config.IngestionConfiguration;
import com.linkedin.metadata.config.TestsConfiguration;
import com.linkedin.metadata.config.ViewsConfiguration;
import com.linkedin.metadata.telemetry.TelemetryConfiguration;
import com.linkedin.metadata.config.VisualConfiguration;
import com.linkedin.metadata.version.GitVersion;
Expand All @@ -43,6 +45,7 @@ public class AppConfigResolver implements DataFetcher<CompletableFuture<AppConfi
private final TelemetryConfiguration _telemetryConfiguration;
private final TestsConfiguration _testsConfiguration;
private final DataHubConfiguration _datahubConfiguration;
private final ViewsConfiguration _viewsConfiguration;

public AppConfigResolver(
final GitVersion gitVersion,
Expand All @@ -54,7 +57,8 @@ public AppConfigResolver(
final VisualConfiguration visualConfiguration,
final TelemetryConfiguration telemetryConfiguration,
final TestsConfiguration testsConfiguration,
final DataHubConfiguration datahubConfiguration) {
final DataHubConfiguration datahubConfiguration,
final ViewsConfiguration viewsConfiguration) {
_gitVersion = gitVersion;
_isAnalyticsEnabled = isAnalyticsEnabled;
_ingestionConfiguration = ingestionConfiguration;
Expand All @@ -65,6 +69,7 @@ public AppConfigResolver(
_telemetryConfiguration = telemetryConfiguration;
_testsConfiguration = testsConfiguration;
_datahubConfiguration = datahubConfiguration;
_viewsConfiguration = viewsConfiguration;
}

@Override
Expand Down Expand Up @@ -127,6 +132,10 @@ public CompletableFuture<AppConfig> get(final DataFetchingEnvironment environmen
testsConfig.setEnabled(_testsConfiguration.isEnabled());
appConfig.setTestsConfig(testsConfig);

final ViewsConfig viewsConfig = new ViewsConfig();
viewsConfig.setEnabled(_viewsConfiguration.isEnabled());
appConfig.setViewsConfig(viewsConfig);

return CompletableFuture.completedFuture(appConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.generated.UpdateUserSettingInput;
import com.linkedin.datahub.graphql.generated.UserSetting;
import com.linkedin.datahub.graphql.resolvers.settings.user.UpdateCorpUserViewsSettingsResolver;
import com.linkedin.identity.CorpUserAppearanceSettings;
import com.linkedin.identity.CorpUserSettings;
import com.linkedin.metadata.entity.EntityService;
Expand All @@ -20,6 +21,10 @@
import static com.linkedin.metadata.Constants.*;


/**
* Deprecated! Use {@link UpdateCorpUserViewsSettingsResolver}
* instead.
*/
@Slf4j
@RequiredArgsConstructor
public class UpdateUserSettingResolver implements DataFetcher<CompletableFuture<Boolean>> {
Expand Down Expand Up @@ -60,4 +65,4 @@ public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throw
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.generated.ContentParams;
import com.linkedin.datahub.graphql.generated.EntityProfileParams;
import com.linkedin.datahub.graphql.generated.Filter;
import com.linkedin.datahub.graphql.generated.FacetFilter;
import com.linkedin.datahub.graphql.generated.ListRecommendationsInput;
import com.linkedin.datahub.graphql.generated.ListRecommendationsResult;
import com.linkedin.datahub.graphql.generated.RecommendationContent;
Expand Down Expand Up @@ -148,7 +148,7 @@ private RecommendationParams mapRecommendationParams(
searchParams.setFilters(params.getSearchParams()
.getFilters()
.stream()
.map(criterion -> Filter.builder().setField(criterion.getField()).setValues(
.map(criterion -> FacetFilter.builder().setField(criterion.getField()).setValues(
ImmutableList.of(criterion.getValue())).build())
.collect(Collectors.toList()));
}
Expand Down
Loading

0 comments on commit e1b0539

Please sign in to comment.