Skip to content
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

Add Operation.Data.toJsonString() convenience function for the jvm #4124

Merged
merged 4 commits into from
May 19, 2022
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
1 change: 1 addition & 0 deletions apollo-api/api/apollo-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ public abstract interface class com/apollographql/apollo3/api/Upload {
public final class com/apollographql/apollo3/api/_DataKt {
public static final fun toJson (Lcom/apollographql/apollo3/api/Operation$Data;Lcom/apollographql/apollo3/api/json/JsonWriter;Lcom/apollographql/apollo3/api/CustomScalarAdapters;)V
public static synthetic fun toJson$default (Lcom/apollographql/apollo3/api/Operation$Data;Lcom/apollographql/apollo3/api/json/JsonWriter;Lcom/apollographql/apollo3/api/CustomScalarAdapters;ILjava/lang/Object;)V
public static synthetic fun toJsonString$default (Lcom/apollographql/apollo3/api/Operation$Data;Lcom/apollographql/apollo3/api/CustomScalarAdapters;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
}

public final class com/apollographql/apollo3/api/http/ByteStringHttpBody : com/apollographql/apollo3/api/http/HttpBody {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.apollographql.apollo3.api

import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.api.json.buildJsonString

private fun Operation.Data.adapter(): Adapter<Operation.Data> {
val name = this::class.java.name
Expand All @@ -25,3 +27,9 @@ fun Operation.Data.toJson(jsonWriter: JsonWriter, customScalarAdapters: CustomSc
adapter().toJson(jsonWriter, customScalarAdapters, this)
}

@ApolloExperimental
fun Operation.Data.toJsonString(customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, indent: String? = null): String {
return buildJsonString(indent) {
toJson(this, customScalarAdapters)
}
}