Skip to content

Commit 044d36a

Browse files
Added build method for explore-request-builder (#138)
Explore API is now being used as part of other APIs too (like events) which do not inherently support many of the functionalities that explore does.. One requirement is to build the request using pre-defined scope and manipulating the arguments instead of using the user-entered arguments as is. Hnece, added an overloaded build method which takes all the arguments as parameters.
1 parent 275b8cc commit 044d36a

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/DefaultExploreRequestBuilder.java

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ public Single<ExploreRequest> build(
8080
.map(this.scopeStringTranslator::fromExternal)
8181
.orElseThrow();
8282

83-
return this.build(requestContext, explorerScope, arguments, selectionSet);
84-
}
85-
86-
private Single<ExploreRequest> build(
87-
GraphQlRequestContext requestContext,
88-
String explorerScope,
89-
Map<String, Object> arguments,
90-
DataFetchingFieldSelectionSet selectionSet) {
91-
9283
int limit =
9384
this.argumentDeserializer
9485
.deserializePrimitive(arguments, LimitArgument.class)
@@ -120,9 +111,6 @@ private Single<ExploreRequest> build(
120111
Optional<String> spaceId =
121112
this.argumentDeserializer.deserializePrimitive(arguments, SpaceArgument.class);
122113

123-
Set<AttributeExpression> groupByExpressions =
124-
groupBy.map(this::resolveGroupByExpressions).orElseGet(Collections::emptySet);
125-
126114
Optional<IntervalArgument> intervalArgument =
127115
this.argumentDeserializer.deserializeObject(arguments, IntervalArgument.class);
128116

@@ -134,6 +122,39 @@ private Single<ExploreRequest> build(
134122
this.selectionRequestBuilder.getAggregationSelections(
135123
requestContext, explorerScope, selectionSet);
136124

125+
return build(
126+
requestContext,
127+
explorerScope,
128+
timeRange,
129+
spaceId,
130+
limit,
131+
offset,
132+
requestedFilters,
133+
requestedOrders,
134+
groupBy,
135+
intervalArgument,
136+
attributeSelections,
137+
aggregationSelections);
138+
}
139+
140+
@Override
141+
public Single<ExploreRequest> build(
142+
GraphQlRequestContext requestContext,
143+
String explorerScope,
144+
TimeRangeArgument timeRange,
145+
Optional<String> spaceId,
146+
int limit,
147+
int offset,
148+
List<FilterArgument> requestedFilters,
149+
List<AggregatableOrderArgument> requestedOrders,
150+
Optional<GroupByArgument> groupBy,
151+
Optional<IntervalArgument> intervalArgument,
152+
Single<Set<AttributeRequest>> attributeSelections,
153+
Single<Set<MetricAggregationRequest>> aggregationSelections) {
154+
155+
Set<AttributeExpression> groupByExpressions =
156+
groupBy.map(this::resolveGroupByExpressions).orElseGet(Collections::emptySet);
157+
137158
Single<List<ExploreOrderArgument>> orderArguments =
138159
this.exploreOrderArgumentBuilder.buildList(requestContext, explorerScope, requestedOrders);
139160

@@ -151,8 +172,8 @@ private Single<ExploreRequest> build(
151172
requestContext,
152173
explorerScope,
153174
timeRange,
154-
limit,
155-
offset,
175+
limit > 0 ? limit : DEFAULT_LIMIT,
176+
offset >= 0 ? offset : DEFAULT_OFFSET,
156177
attributes,
157178
aggregations,
158179
orders,

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequestBuilder.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,36 @@
22

33
import graphql.schema.DataFetchingFieldSelectionSet;
44
import io.reactivex.rxjava3.core.Single;
5+
import java.util.List;
56
import java.util.Map;
7+
import java.util.Optional;
8+
import java.util.Set;
9+
import org.hypertrace.core.graphql.common.request.AttributeRequest;
10+
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
11+
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
612
import org.hypertrace.core.graphql.context.GraphQlRequestContext;
13+
import org.hypertrace.graphql.explorer.schema.argument.GroupByArgument;
14+
import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument;
15+
import org.hypertrace.graphql.metric.request.MetricAggregationRequest;
16+
import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument;
717

818
public interface ExploreRequestBuilder {
919
Single<ExploreRequest> build(
1020
GraphQlRequestContext context,
1121
Map<String, Object> arguments,
1222
DataFetchingFieldSelectionSet selectionSet);
23+
24+
Single<ExploreRequest> build(
25+
GraphQlRequestContext requestContext,
26+
String explorerScope,
27+
TimeRangeArgument timeRange,
28+
Optional<String> spaceId,
29+
int limit,
30+
int offset,
31+
List<FilterArgument> requestedFilters,
32+
List<AggregatableOrderArgument> requestedOrders,
33+
Optional<GroupByArgument> groupBy,
34+
Optional<IntervalArgument> intervalArgument,
35+
Single<Set<AttributeRequest>> attributeSelections,
36+
Single<Set<MetricAggregationRequest>> aggregationSelections);
1337
}

0 commit comments

Comments
 (0)