Skip to content

Commit a024396

Browse files
Adding color, description in labels graphql apis (#116)
1 parent 1ec3bd0 commit a024396

File tree

8 files changed

+65
-26
lines changed

8 files changed

+65
-26
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.hypertrace.graphql.label.dao;
22

3+
import java.util.Optional;
34
import org.hypertrace.graphql.label.request.LabelCreateRequest;
45
import org.hypertrace.graphql.label.request.LabelUpdateRequest;
56
import org.hypertrace.label.config.service.v1.CreateLabelRequest;
@@ -9,14 +10,21 @@
910
public class LabelRequestConverter {
1011
CreateLabelRequest convertCreationRequest(LabelCreateRequest creationRequest) {
1112
return CreateLabelRequest.newBuilder()
12-
.setData(LabelData.newBuilder().setKey(creationRequest.label().key()).build())
13+
.setData(convertLabelData(creationRequest.label()))
1314
.build();
1415
}
1516

1617
UpdateLabelRequest convertUpdateRequest(LabelUpdateRequest updateRequest) {
1718
return UpdateLabelRequest.newBuilder()
1819
.setId(updateRequest.label().id())
19-
.setData(LabelData.newBuilder().setKey(updateRequest.label().key()).build())
20+
.setData(convertLabelData(updateRequest.label()))
2021
.build();
2122
}
23+
24+
private LabelData convertLabelData(org.hypertrace.graphql.label.schema.LabelData data) {
25+
LabelData.Builder dataBuilder = LabelData.newBuilder().setKey(data.key());
26+
Optional.ofNullable(data.color()).ifPresent(dataBuilder::setColor);
27+
Optional.ofNullable(data.description()).ifPresent(dataBuilder::setDescription);
28+
return dataBuilder.build();
29+
}
2230
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/dao/LabelResponseConverter.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,24 @@ Single<LabelResultSet> convert(GetLabelsResponse response) {
2525
Single<List<Label>> convertToLabelList(GetLabelsResponse response) {
2626
return Single.just(
2727
response.getLabelsList().stream()
28-
.map(label -> new DefaultLabel(label.getId(), label.getData().getKey()))
28+
.map(this::convertLabel)
2929
.collect(Collectors.toUnmodifiableList()));
3030
}
3131

3232
Single<Label> convertLabel(CreateLabelResponse response) {
33-
return Single.just(
34-
new DefaultLabel(response.getLabel().getId(), response.getLabel().getData().getKey()));
33+
return Single.just(convertLabel(response.getLabel()));
3534
}
3635

3736
Single<Label> convertUpdateLabel(UpdateLabelResponse response) {
38-
return Single.just(
39-
new DefaultLabel(response.getLabel().getId(), response.getLabel().getData().getKey()));
37+
return Single.just(convertLabel(response.getLabel()));
38+
}
39+
40+
private Label convertLabel(org.hypertrace.label.config.service.v1.Label label) {
41+
return new DefaultLabel(
42+
label.getId(),
43+
label.getData().getKey(),
44+
label.getData().hasColor() ? label.getData().getColor() : null,
45+
label.getData().hasDescription() ? label.getData().getDescription() : null);
4046
}
4147

4248
@Value
@@ -52,5 +58,7 @@ private static class DefaultLabelResultSet implements LabelResultSet {
5258
private static class DefaultLabel implements Label {
5359
String id;
5460
String key;
61+
String color;
62+
String description;
5563
}
5664
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/deserialization/CreateLabelDeserializationConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ public List<Module> jacksonModules() {
3333
private static class CreateLabelArgument implements CreateLabel {
3434
@JsonProperty(KEY)
3535
String key;
36+
37+
@JsonProperty(COLOR_KEY)
38+
String color;
39+
40+
@JsonProperty(DESCRIPTION_KEY)
41+
String description;
3642
}
3743
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/deserialization/LabelDeserializationConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ private static class LabelArgument implements Label {
3636

3737
@JsonProperty(KEY)
3838
String key;
39+
40+
@JsonProperty(COLOR_KEY)
41+
String color;
42+
43+
@JsonProperty(DESCRIPTION_KEY)
44+
String description;
3945
}
4046
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/request/LabelRequestBuilderImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public LabelCreateRequest buildCreateRequest(
2828
@Override
2929
public LabelUpdateRequest buildUpdateRequest(
3030
GraphQlRequestContext requestContext, Map<String, Object> arguments) {
31-
System.out.println(arguments);
3231
return new LabelUpdateRequestImpl(
3332
requestContext,
3433
this.argumentDeserializer.deserializeObject(arguments, Label.class).orElseThrow());
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
package org.hypertrace.graphql.label.schema;
22

3-
import graphql.annotations.annotationTypes.GraphQLField;
43
import graphql.annotations.annotationTypes.GraphQLName;
5-
import graphql.annotations.annotationTypes.GraphQLNonNull;
64
import org.hypertrace.core.graphql.common.schema.id.Identifiable;
75

86
@GraphQLName(Label.TYPE_NAME)
9-
public interface Label extends Identifiable {
7+
public interface Label extends Identifiable, LabelData {
108
String TYPE_NAME = "Label";
119
String ARGUMENT_NAME = "label";
12-
String KEY = "key";
13-
14-
@GraphQLField
15-
@GraphQLNonNull
16-
@GraphQLName(KEY)
17-
String key();
1810
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.hypertrace.graphql.label.schema;
2+
3+
import graphql.annotations.annotationTypes.GraphQLField;
4+
import graphql.annotations.annotationTypes.GraphQLName;
5+
import graphql.annotations.annotationTypes.GraphQLNonNull;
6+
import javax.annotation.Nullable;
7+
8+
public interface LabelData {
9+
String KEY = "key";
10+
String COLOR_KEY = "color";
11+
String DESCRIPTION_KEY = "description";
12+
13+
@GraphQLField
14+
@GraphQLNonNull
15+
@GraphQLName(KEY)
16+
String key();
17+
18+
@GraphQLField
19+
@Nullable
20+
@GraphQLName(COLOR_KEY)
21+
String color();
22+
23+
@GraphQLField
24+
@Nullable
25+
@GraphQLName(DESCRIPTION_KEY)
26+
String description();
27+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
package org.hypertrace.graphql.label.schema.mutation;
22

3-
import graphql.annotations.annotationTypes.GraphQLField;
43
import graphql.annotations.annotationTypes.GraphQLName;
5-
import graphql.annotations.annotationTypes.GraphQLNonNull;
4+
import org.hypertrace.graphql.label.schema.LabelData;
65

76
@GraphQLName(CreateLabel.TYPE_NAME)
8-
public interface CreateLabel {
7+
public interface CreateLabel extends LabelData {
98
String TYPE_NAME = "CreateLabel";
109
String ARGUMENT_NAME = "label";
11-
String KEY = "key";
12-
13-
@GraphQLField
14-
@GraphQLNonNull
15-
@GraphQLName(KEY)
16-
String key();
1710
}

0 commit comments

Comments
 (0)