static String idForSubscription(Subscription<?, ?, ?> subscription) { return subscription.operationId() + "$" + subscription.variables().valueMap().hashCode(); }
@Override public void writeToJson(@NotNull JsonWriter writer) throws IOException { checkNotNull(writer, "writer == null"); writer.name(JSON_KEY_ID).value(subscriptionId); writer.name(JSON_KEY_TYPE).value(TYPE); writer.name(JSON_KEY_PAYLOAD).beginObject(); writer.name(JSON_KEY_QUERY).value(subscription.queryDocument().replaceAll("\\n", "")); writer.name(JSON_KEY_VARIABLES).beginObject(); subscription.variables().marshaller().marshal(new InputFieldJsonWriter(writer, scalarTypeAdapters)); writer.endObject(); writer.name(JSON_KEY_OPERATION_NAME).value(subscription.name().name()); writer.endObject(); } }
public void onMessage(final String msg) { try { //TODO: Check why is this being converted to a Response Body ResponseBody messageBody = ResponseBody.create(MediaType.parse("text/plain"), msg); OperationResponseParser<D, T> parser = new OperationResponseParser(subscription, subscription.responseFieldMapper(), scalarTypeAdapters, normalizer); Response<T> parsedResponse = parser.parse(messageBody.source()); if (parsedResponse.hasErrors()) { Log.w(TAG, "Errors detected in parsed subscription message"); } //TODO: Check why the message is this is not done in an else clause propagateMessageToAllListeners(parsedResponse); } catch (Exception rethrown) { Log.e(TAG, "Failed to parse: " + msg, rethrown); notifyErrorToAllListeners(new ApolloParseException("Failed to parse http response", rethrown)); } }