From a56fdd06e751f7ba81eaa5c5435255e0012b9771 Mon Sep 17 00:00:00 2001 From: Diana Suvorova Date: Fri, 10 Apr 2020 13:11:36 -0700 Subject: [PATCH] returning bytes as a utf8-encoded string --- .../api/graphql/rejoiner/RejoinerIntegrationTest.java | 2 +- .../com/google/api/graphql/rejoiner/ProtoScalars.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rejoiner-guice/src/test/java/com/google/api/graphql/rejoiner/RejoinerIntegrationTest.java b/rejoiner-guice/src/test/java/com/google/api/graphql/rejoiner/RejoinerIntegrationTest.java index 42b93e4..dde7f5a 100644 --- a/rejoiner-guice/src/test/java/com/google/api/graphql/rejoiner/RejoinerIntegrationTest.java +++ b/rejoiner-guice/src/test/java/com/google/api/graphql/rejoiner/RejoinerIntegrationTest.java @@ -276,7 +276,7 @@ public void executionQueryWithAllFields() { .put("intField", (long) 1) .put("RenamedField", "name") .put("testInnerProto", ImmutableMap.of("foo", "foooo")) - .put("bytesField", ByteString.copyFromUtf8("b-y-t-e-s")) + .put("bytesField", "b-y-t-e-s") .build()))); } diff --git a/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoScalars.java b/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoScalars.java index 9a11e2e..ed03ebe 100644 --- a/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoScalars.java +++ b/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoScalars.java @@ -81,12 +81,12 @@ private ProtoScalars() {} public static final GraphQLScalarType BYTES = GraphQLScalarType.newScalar() .coercing( - new Coercing() { + new Coercing() { @Override - public ByteString serialize(Object dataFetcherResult) + public String serialize(Object dataFetcherResult) throws CoercingSerializeException { if (dataFetcherResult instanceof ByteString) { - return (ByteString) dataFetcherResult; + return ((ByteString) dataFetcherResult).toStringUtf8(); } else { throw new CoercingSerializeException( "Invalid value '" + dataFetcherResult + "' for Bytes"); @@ -119,7 +119,7 @@ public ByteString parseLiteral(Object input) throws CoercingParseLiteralExceptio }) .name("Bytes") .description( - "Scalar for proto type bytes." + "Scalar for proto type byte as a utf8-encoded string" + " May contain any arbitrary sequence of bytes no longer than 2^32.") .build(); }