-
Notifications
You must be signed in to change notification settings - Fork 7
Schema changes to get entities count for labels #122
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package org.hypertrace.graphql.label.request; | ||
|
||
import org.hypertrace.core.graphql.common.request.ContextualRequest; | ||
import org.hypertrace.graphql.label.schema.Label; | ||
import org.hypertrace.graphql.label.schema.mutation.UpdateLabel; | ||
|
||
public interface LabelUpdateRequest extends ContextualRequest { | ||
Label label(); | ||
UpdateLabel label(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.hypertrace.graphql.label.schema; | ||
|
||
import graphql.annotations.annotationTypes.GraphQLField; | ||
import graphql.annotations.annotationTypes.GraphQLName; | ||
import graphql.annotations.annotationTypes.GraphQLNonNull; | ||
import org.hypertrace.core.graphql.common.schema.results.arguments.page.LimitArgument; | ||
|
||
@GraphQLName(LabeledEntities.TYPE_NAME) | ||
public interface LabeledEntities { | ||
String TYPE_NAME = "LabeledEntities"; | ||
String LABELED_ENTITIES_QUERY_NAME = "labeledEntities"; | ||
String ENTITY_TYPE_ARGUMENT_NAME = "type"; | ||
|
||
@GraphQLField | ||
@GraphQLNonNull | ||
@GraphQLName(LABELED_ENTITIES_QUERY_NAME) | ||
LabeledEntityResultSet labeledEntities( | ||
@GraphQLNonNull @GraphQLName(ENTITY_TYPE_ARGUMENT_NAME) String entityType, | ||
@GraphQLName(LimitArgument.ARGUMENT_NAME) int limit); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hypertrace.graphql.label.schema; | ||
|
||
import graphql.annotations.annotationTypes.GraphQLName; | ||
import org.hypertrace.core.graphql.common.schema.attributes.AttributeQueryable; | ||
import org.hypertrace.core.graphql.common.schema.id.Identifiable; | ||
|
||
@GraphQLName(LabeledEntity.TYPE_NAME) | ||
public interface LabeledEntity extends AttributeQueryable, Identifiable { | ||
String TYPE_NAME = "LabeledEntity"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.hypertrace.graphql.label.schema; | ||
|
||
import graphql.annotations.annotationTypes.GraphQLField; | ||
import graphql.annotations.annotationTypes.GraphQLName; | ||
import graphql.annotations.annotationTypes.GraphQLNonNull; | ||
import java.util.List; | ||
import org.hypertrace.core.graphql.common.schema.results.ResultSet; | ||
|
||
@GraphQLName(LabeledEntityResultSet.TYPE_NAME) | ||
public interface LabeledEntityResultSet extends ResultSet<LabeledEntity> { | ||
String TYPE_NAME = "LabeledEntityResultSet"; | ||
|
||
@Override | ||
@GraphQLField | ||
@GraphQLNonNull | ||
@GraphQLName(RESULT_SET_RESULTS_NAME) | ||
List<LabeledEntity> results(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.hypertrace.graphql.label.schema.mutation; | ||
|
||
import graphql.annotations.annotationTypes.GraphQLName; | ||
import org.hypertrace.core.graphql.common.schema.id.Identifiable; | ||
import org.hypertrace.graphql.label.schema.LabelData; | ||
|
||
@GraphQLName(UpdateLabel.TYPE_NAME) | ||
public interface UpdateLabel extends Identifiable, LabelData { | ||
String TYPE_NAME = "UpdateLabel"; | ||
String ARGUMENT_NAME = "label"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
package org.hypertrace.graphql.label.dao; | ||
|
||
import io.reactivex.rxjava3.core.Single; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import lombok.Value; | ||
import lombok.experimental.Accessors; | ||
import org.hypertrace.graphql.label.schema.Label; | ||
import org.hypertrace.graphql.label.schema.LabelResultSet; | ||
import org.hypertrace.graphql.label.schema.LabeledEntity; | ||
import org.hypertrace.graphql.label.schema.LabeledEntityResultSet; | ||
import org.hypertrace.label.config.service.v1.CreateLabelResponse; | ||
import org.hypertrace.label.config.service.v1.GetLabelsResponse; | ||
import org.hypertrace.label.config.service.v1.UpdateLabelResponse; | ||
|
@@ -42,7 +47,8 @@ private Label convertLabel(org.hypertrace.label.config.service.v1.Label label) { | |
label.getId(), | ||
label.getData().getKey(), | ||
label.getData().hasColor() ? label.getData().getColor() : null, | ||
label.getData().hasDescription() ? label.getData().getDescription() : null); | ||
label.getData().hasDescription() ? label.getData().getDescription() : null, | ||
Collections.emptyMap()); | ||
} | ||
|
||
@Value | ||
|
@@ -60,5 +66,36 @@ private static class DefaultLabel implements Label { | |
String key; | ||
String color; | ||
String description; | ||
Map<String, List<LabeledEntity>> labeledEntitiesMap; | ||
|
||
@Override | ||
public LabeledEntityResultSet labeledEntities(String entityType, int limit) { | ||
List<LabeledEntity> labeledEntities = | ||
Optional.ofNullable(labeledEntitiesMap.get(entityType)).orElse(Collections.emptyList()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're doing the work on the request side, this should be unreachable - can assume the map contains any requested entity types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to return empty values till implementation is done |
||
List<LabeledEntity> labeledEntitiesWithLimit = | ||
labeledEntities.size() > limit ? labeledEntities.subList(0, limit) : labeledEntities; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. limits should be enforced on the request side There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An entity may hold multiple labels. I was planning to fetch entities along with labels, and reverse map from labels to entities here. Let me know if there is a better approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking we'd just create a query for entities filtered by label. Using the label results, you have a list of label IDs which can become an IN filter on a single entity query (per requested type). You're likely right about the limit being enforced on the response side though, now that I think about it. We can either
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going for second option as well |
||
return new DefaultLabeledEntityResultSet( | ||
labeledEntitiesWithLimit, labeledEntitiesWithLimit.size(), labeledEntities.size()); | ||
} | ||
} | ||
|
||
@Value | ||
@Accessors(fluent = true) | ||
private static class DefaultLabeledEntityResultSet implements LabeledEntityResultSet { | ||
List<LabeledEntity> results; | ||
long count; | ||
long total; | ||
} | ||
|
||
@Value | ||
@Accessors(fluent = true) | ||
private static class DefaultLabeledEntity implements LabeledEntity { | ||
String id; | ||
Map<String, Object> attributeValues; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah crap, I have an enormous change (oops) locally that changes how attributes work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me know what changes are coming, and I will update accordingly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The relevant part here is that
and most of the impls are now holding a
Unless I'm able to get stuff merged (and it won't be today), not much you can do to prepare for it, since don't have the new types. |
||
|
||
@Override | ||
public Object attribute(String key) { | ||
return this.attributeValues.get(key); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would make sense to hold a
Map<String, LabeledEntityResultSet>
I thinkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure