Skip to content

Adding color, description in labels graphql apis #116

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

Merged
merged 4 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hypertrace.graphql.label.dao;

import java.util.Optional;
import org.hypertrace.graphql.label.request.LabelCreateRequest;
import org.hypertrace.graphql.label.request.LabelUpdateRequest;
import org.hypertrace.label.config.service.v1.CreateLabelRequest;
Expand All @@ -9,14 +10,21 @@
public class LabelRequestConverter {
CreateLabelRequest convertCreationRequest(LabelCreateRequest creationRequest) {
return CreateLabelRequest.newBuilder()
.setData(LabelData.newBuilder().setKey(creationRequest.label().key()).build())
.setData(convertLabelData(creationRequest.label()))
.build();
}

UpdateLabelRequest convertUpdateRequest(LabelUpdateRequest updateRequest) {
return UpdateLabelRequest.newBuilder()
.setId(updateRequest.label().id())
.setData(LabelData.newBuilder().setKey(updateRequest.label().key()).build())
.setData(convertLabelData(updateRequest.label()))
.build();
}

private LabelData convertLabelData(org.hypertrace.graphql.label.schema.LabelData data) {
LabelData.Builder dataBuilder = LabelData.newBuilder().setKey(data.key());
Optional.ofNullable(data.color()).ifPresent(dataBuilder::setColor);
Optional.ofNullable(data.description()).ifPresent(dataBuilder::setDescription);
return dataBuilder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ Single<LabelResultSet> convert(GetLabelsResponse response) {
Single<List<Label>> convertToLabelList(GetLabelsResponse response) {
return Single.just(
response.getLabelsList().stream()
.map(label -> new DefaultLabel(label.getId(), label.getData().getKey()))
.map(this::convertLabel)
.collect(Collectors.toUnmodifiableList()));
}

Single<Label> convertLabel(CreateLabelResponse response) {
return Single.just(
new DefaultLabel(response.getLabel().getId(), response.getLabel().getData().getKey()));
return Single.just(convertLabel(response.getLabel()));
}

Single<Label> convertUpdateLabel(UpdateLabelResponse response) {
return Single.just(
new DefaultLabel(response.getLabel().getId(), response.getLabel().getData().getKey()));
return Single.just(convertLabel(response.getLabel()));
}

private Label convertLabel(org.hypertrace.label.config.service.v1.Label label) {
return new DefaultLabel(
label.getId(),
label.getData().getKey(),
label.getData().hasColor() ? label.getData().getColor() : null,
label.getData().hasDescription() ? label.getData().getDescription() : null);
}

@Value
Expand All @@ -52,5 +58,7 @@ private static class DefaultLabelResultSet implements LabelResultSet {
private static class DefaultLabel implements Label {
String id;
String key;
String color;
String description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ public List<Module> jacksonModules() {
private static class CreateLabelArgument implements CreateLabel {
@JsonProperty(KEY)
String key;

@JsonProperty(COLOR_KEY)
String color;

@JsonProperty(DESCRIPTION_KEY)
String description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ private static class LabelArgument implements Label {

@JsonProperty(KEY)
String key;

@JsonProperty(COLOR_KEY)
String color;

@JsonProperty(DESCRIPTION_KEY)
String description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public LabelCreateRequest buildCreateRequest(
@Override
public LabelUpdateRequest buildUpdateRequest(
GraphQlRequestContext requestContext, Map<String, Object> arguments) {
System.out.println(arguments);
return new LabelUpdateRequestImpl(
requestContext,
this.argumentDeserializer.deserializeObject(arguments, Label.class).orElseThrow());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
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.id.Identifiable;

@GraphQLName(Label.TYPE_NAME)
public interface Label extends Identifiable {
public interface Label extends Identifiable, LabelData {
String TYPE_NAME = "Label";
String ARGUMENT_NAME = "label";
String KEY = "key";

@GraphQLField
@GraphQLNonNull
@GraphQLName(KEY)
String key();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.hypertrace.graphql.label.schema;

import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLNonNull;
import javax.annotation.Nullable;

public interface LabelData {
String KEY = "key";
String COLOR_KEY = "color";
String DESCRIPTION_KEY = "description";

@GraphQLField
@GraphQLNonNull
@GraphQLName(KEY)
String key();

@GraphQLField
@Nullable
@GraphQLName(COLOR_KEY)
String color();

@GraphQLField
@Nullable
@GraphQLName(DESCRIPTION_KEY)
String description();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package org.hypertrace.graphql.label.schema.mutation;

import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLNonNull;
import org.hypertrace.graphql.label.schema.LabelData;

@GraphQLName(CreateLabel.TYPE_NAME)
public interface CreateLabel {
public interface CreateLabel extends LabelData {
String TYPE_NAME = "CreateLabel";
String ARGUMENT_NAME = "label";
String KEY = "key";

@GraphQLField
@GraphQLNonNull
@GraphQLName(KEY)
String key();
}