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

move json helpers out of internal #3715

Merged
merged 1 commit into from
Dec 15, 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
19 changes: 11 additions & 8 deletions apollo-api/api/apollo-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,17 @@ public final class com/apollographql/apollo3/api/json/-JsonReaders {
public static final fun jsonReader (Lokio/BufferedSource;)Lcom/apollographql/apollo3/api/json/JsonReader;
}

public final class com/apollographql/apollo3/api/json/-JsonWriters {
public static final fun buildJsonByteString (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lokio/ByteString;
public static synthetic fun buildJsonByteString$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lokio/ByteString;
public static final fun buildJsonMap (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun buildJsonString (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/String;
public static synthetic fun buildJsonString$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
public static final fun writeAny (Lcom/apollographql/apollo3/api/json/JsonWriter;Ljava/lang/Object;)V
public static final fun writeArray (Lcom/apollographql/apollo3/api/json/JsonWriter;Lkotlin/jvm/functions/Function1;)V
public static final fun writeObject (Lcom/apollographql/apollo3/api/json/JsonWriter;Lkotlin/jvm/functions/Function1;)V
}

public final class com/apollographql/apollo3/api/json/BufferedSinkJsonWriter : com/apollographql/apollo3/api/json/JsonWriter {
public static final field Companion Lcom/apollographql/apollo3/api/json/BufferedSinkJsonWriter$Companion;
public fun <init> (Lokio/BufferedSink;)V
Expand Down Expand Up @@ -979,14 +990,6 @@ public final class com/apollographql/apollo3/api/json/MapJsonWriter$State$Map :
public final fun setName (Ljava/lang/String;)V
}

public final class com/apollographql/apollo3/api/json/internal/-JsonWriters {
public static final fun buildJsonByteString (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lokio/ByteString;
public static synthetic fun buildJsonByteString$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lokio/ByteString;
public static final fun buildJsonMap (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun buildJsonString (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/String;
public static synthetic fun buildJsonString$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
}

public final class com/apollographql/apollo3/api/test/TestResolverKt {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.api.json.MapJsonReader.Companion.buffer
import com.apollographql.apollo3.api.json.MapJsonWriter
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.internal.writeAny
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.api.json.writeAny
import com.apollographql.apollo3.api.json.readAny
import kotlin.jvm.JvmField
import kotlin.jvm.JvmName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package com.apollographql.apollo3.api

import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.json.BufferedSinkJsonWriter
import com.apollographql.apollo3.api.json.internal.writeAny
import com.apollographql.apollo3.api.json.writeAny
import okio.Buffer
import kotlin.jvm.JvmField
import kotlin.jvm.JvmName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.internal.ResponseParser
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.api.json.internal.writeObject
import com.apollographql.apollo3.api.json.writeObject
import okio.use
import kotlin.jvm.JvmName
import kotlin.jvm.JvmOverloads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import com.apollographql.apollo3.api.Upload
import com.apollographql.apollo3.api.http.internal.urlEncode
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.api.json.internal.FileUploadAwareJsonWriter
import com.apollographql.apollo3.api.json.internal.buildJsonByteString
import com.apollographql.apollo3.api.json.internal.buildJsonMap
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.internal.writeAny
import com.apollographql.apollo3.api.json.internal.writeObject
import com.apollographql.apollo3.api.json.buildJsonByteString
import com.apollographql.apollo3.api.json.buildJsonMap
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.api.json.writeAny
import com.apollographql.apollo3.api.json.writeObject
import com.benasher44.uuid.uuid4
import okio.BufferedSink
import okio.ByteString
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
@file:JvmName("-JsonWriters")

package com.apollographql.apollo3.api.json.internal
package com.apollographql.apollo3.api.json

import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.json.BufferedSinkJsonWriter
import com.apollographql.apollo3.api.json.JsonNumber
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.api.json.MapJsonWriter
import okio.Buffer
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.jvm.JvmName

@ApolloInternal
fun JsonWriter.writeAny(value: Any?) {
when (value) {
null -> nullValue()
Expand Down Expand Up @@ -48,7 +42,6 @@ fun JsonWriter.writeAny(value: Any?) {
}

@OptIn(ExperimentalContracts::class)
@ApolloInternal
inline fun JsonWriter.writeObject(crossinline block: JsonWriter.() -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
Expand All @@ -60,7 +53,6 @@ inline fun JsonWriter.writeObject(crossinline block: JsonWriter.() -> Unit) {
}

@OptIn(ExperimentalContracts::class)
@ApolloInternal
inline fun JsonWriter.writeArray(crossinline block: JsonWriter.() -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
Expand Down
2 changes: 1 addition & 1 deletion apollo-api/src/commonTest/kotlin/test/JsonTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.apollographql.apollo3.api.AnyAdapter
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.LongAdapter
import com.apollographql.apollo3.api.json.MapJsonWriter
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.buildJsonString
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.api.http.valueOf
import com.apollographql.apollo3.api.json.BufferedSinkJsonWriter
import com.apollographql.apollo3.api.json.BufferedSourceJsonReader
import com.apollographql.apollo3.api.json.internal.buildJsonByteString
import com.apollographql.apollo3.api.json.internal.writeArray
import com.apollographql.apollo3.api.json.buildJsonByteString
import com.apollographql.apollo3.api.json.writeArray
import com.apollographql.apollo3.exception.ApolloException
import com.apollographql.apollo3.exception.ApolloHttpException
import com.apollographql.apollo3.internal.BackgroundDispatcher
Expand Down Expand Up @@ -197,9 +197,9 @@ class BatchingHttpInterceptor @JvmOverloads constructor(
throw ApolloException("batched query response contains a null item")
}
@OptIn(ApolloInternal::class)
buildJsonByteString {
AnyAdapter.toJson(this, CustomScalarAdapters.Empty, it)
}
(buildJsonByteString {
AnyAdapter.toJson(this, CustomScalarAdapters.Empty, it)
})
}
} catch (e: ApolloException) {
exception = e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.apollographql.apollo3.api.NullableAnyAdapter
import com.apollographql.apollo3.api.Operation
import com.apollographql.apollo3.api.http.DefaultHttpRequestComposer
import com.apollographql.apollo3.api.http.DefaultHttpRequestComposer.Companion.appendQueryParameters
import com.apollographql.apollo3.api.json.internal.buildJsonByteString
import com.apollographql.apollo3.api.json.internal.writeAny
import com.apollographql.apollo3.api.json.buildJsonByteString
import com.apollographql.apollo3.api.json.writeAny
import com.apollographql.apollo3.api.toJsonString
import com.apollographql.apollo3.exception.ApolloNetworkException
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import com.apollographql.apollo3.api.ApolloRequest
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.Operation
import com.apollographql.apollo3.api.json.BufferedSourceJsonReader
import com.apollographql.apollo3.api.json.internal.buildJsonByteString
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.internal.writeAny
import com.apollographql.apollo3.api.json.buildJsonByteString
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.api.json.writeAny
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import okio.Buffer

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.Operation
import com.apollographql.apollo3.api.composeJsonResponse
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.enqueue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.apollographql.apollo3.api.http.ByteStringHttpBody
import com.apollographql.apollo3.api.http.HttpMethod
import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.HttpRequestComposer
import com.apollographql.apollo3.api.json.internal.buildJsonByteString
import com.apollographql.apollo3.api.json.internal.writeObject
import com.apollographql.apollo3.api.json.buildJsonByteString
import com.apollographql.apollo3.api.json.writeObject
import com.apollographql.apollo3.api.json.jsonReader
import com.apollographql.apollo3.api.json.readAny
import com.apollographql.apollo3.integration.normalizer.HeroNameQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.api.composeJsonResponse
import com.apollographql.apollo3.api.http.valueOf
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.integration.normalizer.HeroNameQuery
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package test

import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.integration.normalizer.HeroNameQuery
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package test

import codegen.models.AllPlanetsQuery
import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.AnyAdapter
import com.apollographql.apollo3.api.composeJsonResponse
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.api.json.jsonReader
import com.apollographql.apollo3.api.json.readAny
import com.apollographql.apollo3.api.parseJsonResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package test
import codegen.models.AllPlanetsQuery
import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.composeJsonResponse
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.api.json.jsonReader
import com.apollographql.apollo3.api.json.readAny
import com.apollographql.apollo3.api.parseJsonResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import codegen.models.AllPlanetsQuery.Data.AllPlanets.Planet.Companion.planetFra
import codegen.models.AllPlanetsQuery.Data.AllPlanets.Planet.FilmConnection.Film.Companion.filmFragment
import codegen.models.fragment.PlanetFragment
import com.apollographql.apollo3.api.composeJsonResponse
import com.apollographql.apollo3.api.json.internal.buildJsonString
import com.apollographql.apollo3.api.json.buildJsonString
import com.apollographql.apollo3.api.parseJsonResponse
import com.apollographql.apollo3.mpp.Platform
import com.apollographql.apollo3.mpp.platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package test
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.ApolloRequest
import com.apollographql.apollo3.api.ExecutionContext
import com.apollographql.apollo3.api.Operation
import com.apollographql.apollo3.api.http.ByteStringHttpBody
import com.apollographql.apollo3.api.http.HttpMethod
import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.HttpRequestComposer
import com.apollographql.apollo3.api.json.internal.buildJsonByteString
import com.apollographql.apollo3.api.json.internal.writeObject
import com.apollographql.apollo3.api.json.buildJsonByteString
import com.apollographql.apollo3.api.json.writeObject
import com.apollographql.apollo3.api.json.jsonReader
import com.apollographql.apollo3.api.json.readAny
import com.apollographql.apollo3.mockserver.MockResponse
Expand Down