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 Factory to create NormalizedCaches injected with Scalar adapters #405

Merged
merged 6 commits into from
Apr 11, 2017

Conversation

BenSchwab
Copy link
Contributor

closes #401

Using a factory pattern to manage the complexity of making sure that normalized cache implementations are injected with the same scalar adapter set as is set in the ApolloClientBuilder.

@BenSchwab BenSchwab force-pushed the bschwab--custom-scalar-sql branch from 959cb12 to ddf8946 Compare April 10, 2017 19:00
* An adapter used to serialize and deserialize Record fields. Record object types will be serialized to
* {@link CacheReference}.
*/
public final class RecordFieldAdapter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this class out from /sql package as it's seems more generic and not specific to sql

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class CacheStore {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to call it ApolloCacheStore?

EvictionPolicy evictionPolicy,
Optional<NormalizedCacheFactory> secondaryNormalizedCache) {
super(recordFieldAdapter);
if (secondaryNormalizedCache.isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I guess it would be better:

this.secondaryCache = secondaryNormalizedCache.transform(it -> it.createNormalizedCache(recordFieldAdapter)));

@@ -70,8 +86,8 @@ public LruNormalizedCache(EvictionPolicy evictionPolicy, NormalizedCache seconda
}

@Nonnull @Override public Set<String> merge(Record apolloRecord) {
if (secondaryCacheStore.isPresent()) {
secondaryCacheStore.get().merge(apolloRecord);
if (secondaryCache.isPresent()) {
Copy link
Contributor

@sav007 sav007 Apr 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we selected Java8 Optional implementation for internal use.
this can be replaced with Java8 optional:

secondaryCache.ifPresent(it -> it.merge(apolloRecord))

Copy link
Contributor

@sav007 sav007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool!

@BenSchwab BenSchwab merged commit b4d2649 into master Apr 11, 2017
@BenSchwab BenSchwab deleted the bschwab--custom-scalar-sql branch April 11, 2017 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FieldsAdapter (SQLStore) does not properly serialize custom scalar types
2 participants