Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
Open
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
Expand Up @@ -222,7 +222,7 @@ class SchemaTypeSpecBuilder(
fun responseMarshallerSpec(fieldSpecs: List<FieldSpec>): MethodSpec {
val code = fieldSpecs
.map { fieldSpec ->
if (fieldSpec.type.isOptional()) {
if (fieldSpec.type.isNullable()) {
CodeBlock.builder()
.addStatement("final \$T \$L = \$L", fieldSpec.type.unwrapOptionalType().withoutAnnotations(),
"\$${fieldSpec.name}", fieldSpec.type.unwrapOptionalValue(fieldSpec.name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,14 @@ public ResponseFieldMarshaller marshaller() {
return new ResponseFieldMarshaller() {
@Override
public void marshal(ResponseWriter writer) {
writer.writeFragment(humanDetails.marshaller());
writer.writeFragment(droidDetails.marshaller());
final HumanDetails $humanDetails = humanDetails;
if ($humanDetails != null) {
writer.writeFragment($humanDetails.marshaller());
}
final DroidDetails $droidDetails = droidDetails;
if ($droidDetails != null) {
writer.writeFragment($droidDetails.marshaller());
}
}
};
}
Expand Down Expand Up @@ -575,8 +581,14 @@ public ResponseFieldMarshaller marshaller() {
return new ResponseFieldMarshaller() {
@Override
public void marshal(ResponseWriter writer) {
writer.writeFragment(humanDetails.marshaller());
writer.writeFragment(droidDetails.marshaller());
final HumanDetails $humanDetails = humanDetails;
if ($humanDetails != null) {
writer.writeFragment($humanDetails.marshaller());
}
final DroidDetails $droidDetails = droidDetails;
if ($droidDetails != null) {
writer.writeFragment($droidDetails.marshaller());
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,14 @@ public ResponseFieldMarshaller marshaller() {
return new ResponseFieldMarshaller() {
@Override
public void marshal(ResponseWriter writer) {
writer.writeFragment(character.marshaller());
writer.writeFragment(starship.marshaller());
final Character $character = character;
if ($character != null) {
writer.writeFragment($character.marshaller());
}
final Starship $starship = starship;
if ($starship != null) {
writer.writeFragment($starship.marshaller());
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlin.reflect.KClass
*
* A common configuration is to have secondary SQL cache.
*/
class LruNormalizedCache internal constructor(evictionPolicy: EvictionPolicy) : NormalizedCache() {
open class LruNormalizedCache constructor(evictionPolicy: EvictionPolicy) : NormalizedCache() {

private val lruCache: Cache<String, Record> =
CacheBuilder.newBuilder().apply {
Expand Down Expand Up @@ -97,4 +97,6 @@ class LruNormalizedCache internal constructor(evictionPolicy: EvictionPolicy) :
put(this@LruNormalizedCache::class, lruCache.asMap())
putAll(nextCache?.dump().orEmpty())
}

fun getFromCacheIfPresent(key: String): Record? = lruCache.getIfPresent(key)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.apollographql.apollo.cache.normalized.NormalizedCache
import com.apollographql.apollo.cache.normalized.Record
import com.apollographql.apollo.cache.normalized.RecordFieldJsonAdapter
import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -248,6 +250,25 @@ class LruNormalizedCacheTest {
assertThat(record2).isNull()
}

@Test
fun test_getFromCacheIfPresent() {
val lruCache = createLruNormalizedCache()
val testRecord1 = createTestRecord("1")
val testRecordSet: MutableCollection<Record> = HashSet()
testRecordSet.add(testRecord1)
lruCache.merge(testRecordSet, CacheHeaders.NONE)
assertEquals(testRecord1, lruCache.getFromCacheIfPresent("key1"))

val testRecord2 = createTestRecord("2")
lruCache.merge(testRecord2, CacheHeaders.NONE)

assertEquals(testRecord2, lruCache.getFromCacheIfPresent("key2"))

val testRecord3 = createTestRecord("2")
lruCache.merge(testRecord3, builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "true").build())
assertNull(lruCache.getFromCacheIfPresent("key3"))
}

private fun createLruNormalizedCache() =
LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024.toLong()).build()).create(basicFieldAdapter)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public Builder useHttpGetMethodForQueries(boolean useHttpGetMethodForQueries) {

public Builder autoPersistQueries(boolean autoPersistQueries) {
this.autoPersistQueries = autoPersistQueries;
if (autoPersistQueries) {
sendQueryDocument = false;
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void run() {
}
};
private final List<OnSubscriptionManagerStateChangeListener> onStateChangeListeners = new CopyOnWriteArrayList<>();

private final boolean autoPersistSubscription;

public RealSubscriptionManager(@NotNull ScalarTypeAdapters scalarTypeAdapters,
Expand All @@ -89,6 +90,7 @@ public RealSubscriptionManager(@NotNull ScalarTypeAdapters scalarTypeAdapters,
this.transport = transportFactory.create(new SubscriptionTransportCallback(this, dispatcher));
this.dispatcher = dispatcher;
this.connectionHeartbeatTimeoutMs = connectionHeartbeatTimeoutMs;

this.responseNormalizer = responseNormalizer;
this.autoPersistSubscription = autoPersistSubscription;
}
Expand Down Expand Up @@ -309,7 +311,9 @@ void onOperationServerMessage(OperationServerMessage message) {
} else if (message instanceof OperationServerMessage.Complete) {
onCompleteServerMessage((OperationServerMessage.Complete) message);
} else if (message instanceof OperationServerMessage.ConnectionError) {
disconnect(true);
// Jordan - Ignore connection errors, as they don't always mean the socket should be disconnected
// See https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_error
// disconnect(true);
} else if (message instanceof OperationServerMessage.ConnectionKeepAlive) {
resetConnectionKeepAliveTimerTask();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ public Init(@NotNull Map<String, Object> connectionParams) {
public static final class Start extends OperationClientMessage {
private static final String TYPE = "start";
private static final String JSON_KEY_QUERY = "query";
private static final String JSON_KEY_ID = "id";
private static final String JSON_KEY_VARIABLES = "variables";
private static final String JSON_KEY_OPERATION_NAME = "operationName";
private static final String JSON_KEY_EXTENSIONS = "extensions";
private static final String JSON_KEY_EXTENSIONS_PERSISTED_QUERY = "persistedQuery";
private static final String JSON_KEY_EXTENSIONS_PERSISTED_QUERY_VERSION = "version";
private static final String JSON_KEY_EXTENSIONS_PERSISTED_QUERY_HASH = "sha256Hash";
private final ScalarTypeAdapters scalarTypeAdapters;
private boolean enableAutoPersistedQueries;

public final String subscriptionId;
public final Subscription<?, ?, ?> subscription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void proceedAsync(@NotNull ApolloInterceptor.InterceptorRequest request,
)
);
} else if (proceedAsyncInvocationCount == 2) {
assertThat(request.sendQueryDocument).isTrue();
assertThat(request.sendQueryDocument).isFalse();
assertThat(request.autoPersistQueries).isTrue();
callBack.onResponse(
new ApolloInterceptor.InterceptorResponse(
Expand Down Expand Up @@ -157,7 +157,7 @@ public void proceedAsync(@NotNull ApolloInterceptor.InterceptorRequest request,
)
);
} else if (proceedAsyncInvocationCount == 2) {
assertThat(request.sendQueryDocument).isTrue();
assertThat(request.sendQueryDocument).isFalse();
assertThat(request.autoPersistQueries).isTrue();
callBack.onResponse(
new ApolloInterceptor.InterceptorResponse(
Expand Down