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

feat: Expose possibleTypes on cache #906

Merged
merged 1 commit into from Jun 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/graphql/lib/src/cache/_normalizing_data_proxy.dart
Expand Up @@ -17,6 +17,9 @@ abstract class NormalizingDataProxy extends GraphQLDataProxy {
/// `typePolicies` to pass down to `normalize`
Map<String, TypePolicy> get typePolicies;

/// `possibleTypes` to pass down to [normalize]
Map<String, Set<String>> get possibleTypes;

/// Optional `dataIdFromObject` function to pass through to [normalize]
DataIdResolver? get dataIdFromObject;

Expand Down Expand Up @@ -92,6 +95,7 @@ abstract class NormalizingDataProxy extends GraphQLDataProxy {
document: request.operation.document,
operationName: request.operation.operationName,
variables: sanitizeVariables(request.variables)!,
possibleTypes: possibleTypes,
);

Map<String, dynamic>? readFragment(
Expand All @@ -112,6 +116,7 @@ abstract class NormalizingDataProxy extends GraphQLDataProxy {
idFields: fragmentRequest.idFields,
fragmentName: fragmentRequest.fragment.fragmentName,
variables: sanitizeVariables(fragmentRequest.variables)!,
possibleTypes: possibleTypes,
);

void writeQuery(
Expand All @@ -134,6 +139,7 @@ abstract class NormalizingDataProxy extends GraphQLDataProxy {
variables: sanitizeVariables(request.variables)!,
// data
data: data,
possibleTypes: possibleTypes,
);
if (broadcast ?? true) {
broadcastRequested = true;
Expand Down Expand Up @@ -171,6 +177,7 @@ abstract class NormalizingDataProxy extends GraphQLDataProxy {
variables: sanitizeVariables(request.variables)!,
// data
data: data,
possibleTypes: possibleTypes,
);
if (broadcast ?? true) {
broadcastRequested = true;
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql/lib/src/cache/_optimistic_transactions.dart
Expand Up @@ -44,6 +44,9 @@ class OptimisticProxy extends NormalizingDataProxy {
/// `typePolicies` to pass down to `normalize` (proxied from [cache])
get typePolicies => cache.typePolicies;

/// `possibleTypeOf` to pass down to `normalize` (proxied from [cache])
get possibleTypes => cache.possibleTypes;

/// Optional `dataIdFromObject` function to pass through to [normalize]
/// (proxied from [cache])
get dataIdFromObject => cache.dataIdFromObject;
Expand Down
4 changes: 4 additions & 0 deletions packages/graphql/lib/src/cache/cache.dart
Expand Up @@ -32,6 +32,7 @@ class GraphQLCache extends NormalizingDataProxy {
Store? store,
this.dataIdFromObject,
this.typePolicies = const {},
this.possibleTypes = const {},
this.partialDataPolicy = PartialDataCachePolicy.acceptForOptimisticData,
Object? Function(Object?) sanitizeVariables = sanitizeFilesForCache,
}) : sanitizeVariables = variableSanitizer(sanitizeVariables),
Expand Down Expand Up @@ -60,6 +61,9 @@ class GraphQLCache extends NormalizingDataProxy {
/// `typePolicies` to pass down to [normalize]
final Map<String, TypePolicy> typePolicies;

/// `possibleTypes` to pass down to [normalize]
final Map<String, Set<String>> possibleTypes;

/// Optional `dataIdFromObject` function to pass through to [normalize]
final DataIdResolver? dataIdFromObject;

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/pubspec.yaml
Expand Up @@ -13,7 +13,7 @@ dependencies:
gql_error_link: ^0.2.0
gql_dedupe_link: ^2.0.0
hive: ^2.0.0
normalize: ^0.5.1
normalize: ^0.5.3
http: ^0.13.0
collection: ^1.15.0
web_socket_channel: ^2.0.0
Expand Down