From a3f8930568367f94538c044ea8a0098e81505ce7 Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Sun, 30 May 2021 16:49:21 +0100 Subject: [PATCH 1/3] feat: Add support for better fragment type resolution --- .../lib/src/config/normalization_config.dart | 3 + normalize/lib/src/denormalize_fragment.dart | 4 +- normalize/lib/src/denormalize_node.dart | 1 + normalize/lib/src/denormalize_operation.dart | 4 +- normalize/lib/src/normalize_fragment.dart | 2 + normalize/lib/src/normalize_node.dart | 1 + normalize/lib/src/normalize_operation.dart | 2 + normalize/lib/src/policies/field_policy.dart | 3 +- normalize/lib/src/utils/expand_fragments.dart | 40 ++++--- .../lib/src/utils/operation_field_names.dart | 2 + normalize/test/possible_type_of.dart | 101 ++++++++++++++++++ 11 files changed, 143 insertions(+), 20 deletions(-) create mode 100644 normalize/test/possible_type_of.dart diff --git a/normalize/lib/src/config/normalization_config.dart b/normalize/lib/src/config/normalization_config.dart index 3aedca70..30b142cb 100644 --- a/normalize/lib/src/config/normalization_config.dart +++ b/normalize/lib/src/config/normalization_config.dart @@ -26,6 +26,8 @@ class NormalizationConfig { /// Whether to accept or return partial data. final bool allowPartialData; + final Map> possibleTypeOf; + NormalizationConfig({ required this.read, required this.variables, @@ -35,5 +37,6 @@ class NormalizationConfig { required this.dataIdFromObject, required this.addTypename, required this.allowPartialData, + required this.possibleTypeOf, }); } diff --git a/normalize/lib/src/denormalize_fragment.dart b/normalize/lib/src/denormalize_fragment.dart index b172eef1..8d9306e6 100644 --- a/normalize/lib/src/denormalize_fragment.dart +++ b/normalize/lib/src/denormalize_fragment.dart @@ -2,11 +2,9 @@ import 'package:gql/ast.dart'; import 'package:normalize/normalize.dart'; import 'package:normalize/src/config/normalization_config.dart'; -import 'package:normalize/src/policies/type_policy.dart'; import 'package:normalize/src/utils/get_fragment_map.dart'; import 'package:normalize/src/utils/resolve_data_id.dart'; import 'package:normalize/src/utils/add_typename_visitor.dart'; -import 'package:normalize/src/utils/exceptions.dart'; import 'package:normalize/src/denormalize_node.dart'; /// Denormalizes data for a given fragment. @@ -36,6 +34,7 @@ Map? denormalizeFragment({ bool returnPartialData = false, bool handleException = true, String referenceKey = '\$ref', + Map> possibleTypeOf = const {}, }) { if (addTypename) { document = transform( @@ -86,6 +85,7 @@ Map? denormalizeFragment({ dataIdFromObject: dataIdFromObject, addTypename: addTypename, allowPartialData: returnPartialData, + possibleTypeOf: possibleTypeOf, ); try { diff --git a/normalize/lib/src/denormalize_node.dart b/normalize/lib/src/denormalize_node.dart index a61d85df..161d2f8a 100644 --- a/normalize/lib/src/denormalize_node.dart +++ b/normalize/lib/src/denormalize_node.dart @@ -45,6 +45,7 @@ Object? denormalizeNode({ typename: typename, selectionSet: selectionSet, fragmentMap: config.fragmentMap, + possibleTypeOf: config.possibleTypeOf, ); final result = subNodes.fold>( diff --git a/normalize/lib/src/denormalize_operation.dart b/normalize/lib/src/denormalize_operation.dart index 5bb7a3a4..cc682e9c 100644 --- a/normalize/lib/src/denormalize_operation.dart +++ b/normalize/lib/src/denormalize_operation.dart @@ -1,10 +1,8 @@ import 'package:gql/ast.dart'; import 'package:normalize/normalize.dart'; -import 'package:normalize/src/policies/type_policy.dart'; import 'package:normalize/src/utils/resolve_root_typename.dart'; import 'package:normalize/src/utils/add_typename_visitor.dart'; -import 'package:normalize/src/utils/exceptions.dart'; import 'package:normalize/src/utils/get_operation_definition.dart'; import 'package:normalize/src/denormalize_node.dart'; import 'package:normalize/src/config/normalization_config.dart'; @@ -31,6 +29,7 @@ Map? denormalizeOperation({ bool returnPartialData = false, bool handleException = true, String referenceKey = '\$ref', + Map> possibleTypeOf = const {}, }) { if (addTypename) { document = transform( @@ -55,6 +54,7 @@ Map? denormalizeOperation({ dataIdFromObject: dataIdFromObject, addTypename: addTypename, allowPartialData: returnPartialData, + possibleTypeOf: possibleTypeOf, ); try { diff --git a/normalize/lib/src/normalize_fragment.dart b/normalize/lib/src/normalize_fragment.dart index c84bd387..03410293 100644 --- a/normalize/lib/src/normalize_fragment.dart +++ b/normalize/lib/src/normalize_fragment.dart @@ -39,6 +39,7 @@ void normalizeFragment({ bool addTypename = false, String referenceKey = '\$ref', bool acceptPartialData = true, + Map> possibleTypeOf = const {}, }) { // Always add typenames to ensure data is stored with typename document = transform( @@ -75,6 +76,7 @@ void normalizeFragment({ addTypename: addTypename, dataIdFromObject: dataIdFromObject, allowPartialData: acceptPartialData, + possibleTypeOf: possibleTypeOf, ); final dataId = resolveDataId( diff --git a/normalize/lib/src/normalize_node.dart b/normalize/lib/src/normalize_node.dart index e368177f..0db6ca06 100644 --- a/normalize/lib/src/normalize_node.dart +++ b/normalize/lib/src/normalize_node.dart @@ -52,6 +52,7 @@ Object? normalizeNode({ typename: typename, selectionSet: selectionSet, fragmentMap: config.fragmentMap, + possibleTypeOf: config.possibleTypeOf, ); final dataToMerge = { diff --git a/normalize/lib/src/normalize_operation.dart b/normalize/lib/src/normalize_operation.dart index 3cae735a..f40023bf 100644 --- a/normalize/lib/src/normalize_operation.dart +++ b/normalize/lib/src/normalize_operation.dart @@ -35,6 +35,7 @@ void normalizeOperation({ bool addTypename = false, bool acceptPartialData = true, String referenceKey = '\$ref', + Map> possibleTypeOf = const {}, }) { if (addTypename) { document = transform( @@ -59,6 +60,7 @@ void normalizeOperation({ addTypename: addTypename, dataIdFromObject: dataIdFromObject, allowPartialData: acceptPartialData, + possibleTypeOf: possibleTypeOf, ); write( diff --git a/normalize/lib/src/policies/field_policy.dart b/normalize/lib/src/policies/field_policy.dart index 493f72a7..63d923f3 100644 --- a/normalize/lib/src/policies/field_policy.dart +++ b/normalize/lib/src/policies/field_policy.dart @@ -20,7 +20,7 @@ class FieldFunctionOptions { FieldFunctionOptions({ required this.field, required NormalizationConfig config, - }) : _config = config, + }) : _config = config, variables = config.variables, args = argsWithValues(config.variables, field.arguments); @@ -50,6 +50,7 @@ class FieldFunctionOptions { dataIdFromObject: _config.dataIdFromObject, addTypename: _config.addTypename, allowPartialData: true, + possibleTypeOf: _config.possibleTypeOf, ), ) as T?; } diff --git a/normalize/lib/src/utils/expand_fragments.dart b/normalize/lib/src/utils/expand_fragments.dart index 300566af..c2f7c5e5 100644 --- a/normalize/lib/src/utils/expand_fragments.dart +++ b/normalize/lib/src/utils/expand_fragments.dart @@ -6,39 +6,49 @@ List expandFragments({ required String? typename, required SelectionSetNode selectionSet, required Map fragmentMap, + required Map> possibleTypeOf, }) { final fieldNodes = []; for (var selectionNode in selectionSet.selections) { if (selectionNode is FieldNode) { fieldNodes.add(selectionNode); - } else if (selectionNode is InlineFragmentNode) { - // Only include this fragment if the type name matches - if (selectionNode.typeCondition?.on.name.value == typename) { - fieldNodes.addAll( - expandFragments( - typename: typename, - selectionSet: selectionNode.selectionSet, - fragmentMap: fragmentMap, - ), - ); - } + continue; + } + if (typename == null) { + continue; + } + String fragmentOnName; + SelectionSetNode fragmentSelectionSet; + if (selectionNode is InlineFragmentNode) { + fragmentOnName = selectionNode.typeCondition?.on.name.value ?? typename; + fragmentSelectionSet = selectionNode.selectionSet; } else if (selectionNode is FragmentSpreadNode) { final fragment = fragmentMap[selectionNode.name.value]; - if (fragment == null) { throw Exception('Missing fragment ${selectionNode.name.value}'); } + fragmentOnName = fragment.typeCondition.on.name.value; + fragmentSelectionSet = fragment.selectionSet; + } else { + throw (FormatException('Unknown selection node type')); + } + // We'll add the fields if + // - We know the current type (typename != null) + // and + // - If the fragment and current type are the same (fragmentOnName == typename) + // - Or the current type is a type of the fragment target + if (fragmentOnName == typename || + possibleTypeOf[typename]?.contains(fragmentOnName) == true) { fieldNodes.addAll( expandFragments( typename: typename, - selectionSet: fragment.selectionSet, + selectionSet: fragmentSelectionSet, fragmentMap: fragmentMap, + possibleTypeOf: possibleTypeOf, ), ); - } else { - throw (FormatException('Unknown selection node type')); } } return List.from(_mergeSelections(fieldNodes)); diff --git a/normalize/lib/src/utils/operation_field_names.dart b/normalize/lib/src/utils/operation_field_names.dart index a763aa73..7e121d4a 100644 --- a/normalize/lib/src/utils/operation_field_names.dart +++ b/normalize/lib/src/utils/operation_field_names.dart @@ -13,6 +13,7 @@ List operationFieldNames( String operationName, Map vars, Map typePolicies, + Map> possibleTypeOf, ) { final operationDefinition = getOperationDefinition( document, @@ -27,6 +28,7 @@ List operationFieldNames( typename: rootTypename, selectionSet: operationDefinition.selectionSet, fragmentMap: fragmentMap, + possibleTypeOf: possibleTypeOf, ); final typePolicy = typePolicies[rootTypename]; return fields.map((fieldNode) { diff --git a/normalize/test/possible_type_of.dart b/normalize/test/possible_type_of.dart new file mode 100644 index 00000000..ab21b53e --- /dev/null +++ b/normalize/test/possible_type_of.dart @@ -0,0 +1,101 @@ +import 'package:test/test.dart'; +import 'package:gql/language.dart'; + +import 'package:normalize/normalize.dart'; + +void main() { + group('Normalizing and denormalizing with possible type of', () { + test('Mutiple fragments', () { + final possibleTypeOf = { + 'Author': {'User'}, + 'Audience': {'User'}, + }; + final document = parseString(''' + fragment FAudience on Audience { + __typename + id + numHands + isClapping + } + fragment FUser on User { + id + __typename + name + } + query { + users { + ... on Author { + __typename + id + isGoodAuthor + } + ...FAudience + ...FUser + } + } + '''); + final data = { + 'users': [ + { + '__typename': 'Author', + 'id': '1', + 'name': 'Knud', + 'isGoodAuthor': true, + }, + { + '__typename': 'Audience', + 'id': 'a', + 'name': 'Lars', + 'numHands': 2, + 'isClapping': false + }, + ], + }; + + final normalizedMap = { + 'Author:1': { + '__typename': 'Author', + 'id': '1', + 'name': 'Knud', + 'isGoodAuthor': true + }, + 'Audience:a': { + '__typename': 'Audience', + 'id': 'a', + 'numHands': 2, + 'isClapping': false, + 'name': 'Lars' + }, + 'Query': { + 'users': [ + {r'$ref': 'Author:1'}, + {r'$ref': 'Audience:a'} + ] + }, + }; + final normalizedResult = {}; + normalizeOperation( + read: (dataId) => normalizedResult[dataId], + write: (dataId, value) => normalizedResult[dataId] = value, + document: document, + data: data, + acceptPartialData: false, + possibleTypeOf: possibleTypeOf, + ); + expect( + normalizedResult, + equals(normalizedMap), + ); + + expect( + denormalizeOperation( + document: document, + handleException: false, + read: (dataId) => normalizedMap[dataId], + possibleTypeOf: possibleTypeOf, + ), + equals(data), + ); + }); + }); +} From adcb7073854759c815684b19c36f02767840d42c Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Tue, 1 Jun 2021 18:18:00 +0100 Subject: [PATCH 2/3] fix: Supply empty possibleTypeOf map `operationFieldNames` --- ferry_cache/lib/src/utils/operation_root_data.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/ferry_cache/lib/src/utils/operation_root_data.dart b/ferry_cache/lib/src/utils/operation_root_data.dart index 54b4313e..51dfe9fc 100644 --- a/ferry_cache/lib/src/utils/operation_root_data.dart +++ b/ferry_cache/lib/src/utils/operation_root_data.dart @@ -15,6 +15,7 @@ Map operationRootData( request.operation.operationName!, (request.vars as dynamic).toJson(), typePolicies, + {}, ); return { for (var fieldName in fieldNames) From 88977f8e4cea205c31044246a5989dc7b3c82cca Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Tue, 1 Jun 2021 19:23:52 +0100 Subject: [PATCH 3/3] ref: Use possibleTypes instead of possibleTypeOf --- ferry_cache/lib/src/cache.dart | 3 +++ ferry_cache/lib/src/operation_data_change_stream.dart | 2 ++ ferry_cache/lib/src/utils/operation_root_data.dart | 3 ++- ferry_cache/test/data_change_streams_test.dart | 9 +++++++++ normalize/lib/src/config/normalization_config.dart | 5 +++-- normalize/lib/src/denormalize_fragment.dart | 4 ++-- normalize/lib/src/denormalize_node.dart | 2 +- normalize/lib/src/denormalize_operation.dart | 4 ++-- normalize/lib/src/normalize_fragment.dart | 4 ++-- normalize/lib/src/normalize_node.dart | 2 +- normalize/lib/src/normalize_operation.dart | 4 ++-- normalize/lib/src/policies/field_policy.dart | 2 +- normalize/lib/src/utils/expand_fragments.dart | 6 +++--- normalize/lib/src/utils/operation_field_names.dart | 4 ++-- normalize/test/possible_type_of.dart | 9 ++++----- 15 files changed, 39 insertions(+), 24 deletions(-) diff --git a/ferry_cache/lib/src/cache.dart b/ferry_cache/lib/src/cache.dart index 576f38a9..911f40b3 100644 --- a/ferry_cache/lib/src/cache.dart +++ b/ferry_cache/lib/src/cache.dart @@ -11,6 +11,7 @@ import './fragment_data_change_stream.dart'; class Cache { final Map typePolicies; + final Map> possibleTypes; final bool addTypename; final Store store; final utils.DataIdResolver? dataIdFromObject; @@ -27,6 +28,7 @@ class Cache { Store? store, this.dataIdFromObject, this.typePolicies = const {}, + this.possibleTypes = const {}, this.addTypename = true, Map?>> seedOptimisticPatches = const {}, @@ -65,6 +67,7 @@ class Cache { typePolicies, addTypename, dataIdFromObject, + possibleTypes, ).doOnDone(() => closed = true); return NeverStream() diff --git a/ferry_cache/lib/src/operation_data_change_stream.dart b/ferry_cache/lib/src/operation_data_change_stream.dart index b0decb4b..4f684136 100644 --- a/ferry_cache/lib/src/operation_data_change_stream.dart +++ b/ferry_cache/lib/src/operation_data_change_stream.dart @@ -20,6 +20,7 @@ Stream> operationDataChangeStream( Map typePolicies, bool addTypename, DataIdResolver? dataIdFromObject, + Map> possibleTypes, ) { final operationDefinition = getOperationDefinition( request.operation.document, @@ -67,6 +68,7 @@ Stream> operationDataChangeStream( data, request, typePolicies, + possibleTypes, ), ); } diff --git a/ferry_cache/lib/src/utils/operation_root_data.dart b/ferry_cache/lib/src/utils/operation_root_data.dart index 51dfe9fc..561f67eb 100644 --- a/ferry_cache/lib/src/utils/operation_root_data.dart +++ b/ferry_cache/lib/src/utils/operation_root_data.dart @@ -9,13 +9,14 @@ Map operationRootData( Map? data, OperationRequest request, Map typePolicies, + Map> possibleTypes, ) { final fieldNames = operationFieldNames( request.operation.document, request.operation.operationName!, (request.vars as dynamic).toJson(), typePolicies, - {}, + possibleTypes, ); return { for (var fieldName in fieldNames) diff --git a/ferry_cache/test/data_change_streams_test.dart b/ferry_cache/test/data_change_streams_test.dart index 520601b2..870eec09 100644 --- a/ferry_cache/test/data_change_streams_test.dart +++ b/ferry_cache/test/data_change_streams_test.dart @@ -66,6 +66,7 @@ void main() { {}, true, null, + {}, ); expect( @@ -89,6 +90,7 @@ void main() { {}, true, null, + {}, ); expect(stream, emitsInOrder([emitsDone])); @@ -113,6 +115,7 @@ void main() { {}, true, null, + {}, ); expect(stream, emitsInOrder([emitsDone])); @@ -134,6 +137,7 @@ void main() { {}, true, null, + {}, ); expect(stream, emitsInOrder([emitsDone])); @@ -158,6 +162,7 @@ void main() { {}, true, null, + {}, ); expect( @@ -190,6 +195,7 @@ void main() { {}, true, null, + {}, ); expect( @@ -225,6 +231,7 @@ void main() { {}, true, null, + {}, ); expect(stream, emitsInOrder([emitsDone])); @@ -255,6 +262,7 @@ void main() { {}, true, null, + {}, ); expect( @@ -291,6 +299,7 @@ void main() { {}, true, null, + {}, ); expect( diff --git a/normalize/lib/src/config/normalization_config.dart b/normalize/lib/src/config/normalization_config.dart index 30b142cb..821d457a 100644 --- a/normalize/lib/src/config/normalization_config.dart +++ b/normalize/lib/src/config/normalization_config.dart @@ -26,7 +26,8 @@ class NormalizationConfig { /// Whether to accept or return partial data. final bool allowPartialData; - final Map> possibleTypeOf; + /// A map from an interface/union to possible types. + final Map> possibleTypes; NormalizationConfig({ required this.read, @@ -37,6 +38,6 @@ class NormalizationConfig { required this.dataIdFromObject, required this.addTypename, required this.allowPartialData, - required this.possibleTypeOf, + required this.possibleTypes, }); } diff --git a/normalize/lib/src/denormalize_fragment.dart b/normalize/lib/src/denormalize_fragment.dart index 8d9306e6..5960fe8f 100644 --- a/normalize/lib/src/denormalize_fragment.dart +++ b/normalize/lib/src/denormalize_fragment.dart @@ -34,7 +34,7 @@ Map? denormalizeFragment({ bool returnPartialData = false, bool handleException = true, String referenceKey = '\$ref', - Map> possibleTypeOf = const {}, + Map> possibleTypes = const {}, }) { if (addTypename) { document = transform( @@ -85,7 +85,7 @@ Map? denormalizeFragment({ dataIdFromObject: dataIdFromObject, addTypename: addTypename, allowPartialData: returnPartialData, - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ); try { diff --git a/normalize/lib/src/denormalize_node.dart b/normalize/lib/src/denormalize_node.dart index 161d2f8a..cb6a7c82 100644 --- a/normalize/lib/src/denormalize_node.dart +++ b/normalize/lib/src/denormalize_node.dart @@ -45,7 +45,7 @@ Object? denormalizeNode({ typename: typename, selectionSet: selectionSet, fragmentMap: config.fragmentMap, - possibleTypeOf: config.possibleTypeOf, + possibleTypes: config.possibleTypes, ); final result = subNodes.fold>( diff --git a/normalize/lib/src/denormalize_operation.dart b/normalize/lib/src/denormalize_operation.dart index cc682e9c..adae3ad4 100644 --- a/normalize/lib/src/denormalize_operation.dart +++ b/normalize/lib/src/denormalize_operation.dart @@ -29,7 +29,7 @@ Map? denormalizeOperation({ bool returnPartialData = false, bool handleException = true, String referenceKey = '\$ref', - Map> possibleTypeOf = const {}, + Map> possibleTypes = const {}, }) { if (addTypename) { document = transform( @@ -54,7 +54,7 @@ Map? denormalizeOperation({ dataIdFromObject: dataIdFromObject, addTypename: addTypename, allowPartialData: returnPartialData, - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ); try { diff --git a/normalize/lib/src/normalize_fragment.dart b/normalize/lib/src/normalize_fragment.dart index 03410293..cc318f7c 100644 --- a/normalize/lib/src/normalize_fragment.dart +++ b/normalize/lib/src/normalize_fragment.dart @@ -39,7 +39,7 @@ void normalizeFragment({ bool addTypename = false, String referenceKey = '\$ref', bool acceptPartialData = true, - Map> possibleTypeOf = const {}, + Map> possibleTypes = const {}, }) { // Always add typenames to ensure data is stored with typename document = transform( @@ -76,7 +76,7 @@ void normalizeFragment({ addTypename: addTypename, dataIdFromObject: dataIdFromObject, allowPartialData: acceptPartialData, - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ); final dataId = resolveDataId( diff --git a/normalize/lib/src/normalize_node.dart b/normalize/lib/src/normalize_node.dart index 0db6ca06..fc166fb0 100644 --- a/normalize/lib/src/normalize_node.dart +++ b/normalize/lib/src/normalize_node.dart @@ -52,7 +52,7 @@ Object? normalizeNode({ typename: typename, selectionSet: selectionSet, fragmentMap: config.fragmentMap, - possibleTypeOf: config.possibleTypeOf, + possibleTypes: config.possibleTypes, ); final dataToMerge = { diff --git a/normalize/lib/src/normalize_operation.dart b/normalize/lib/src/normalize_operation.dart index f40023bf..7f87b57d 100644 --- a/normalize/lib/src/normalize_operation.dart +++ b/normalize/lib/src/normalize_operation.dart @@ -35,7 +35,7 @@ void normalizeOperation({ bool addTypename = false, bool acceptPartialData = true, String referenceKey = '\$ref', - Map> possibleTypeOf = const {}, + Map> possibleTypes = const {}, }) { if (addTypename) { document = transform( @@ -60,7 +60,7 @@ void normalizeOperation({ addTypename: addTypename, dataIdFromObject: dataIdFromObject, allowPartialData: acceptPartialData, - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ); write( diff --git a/normalize/lib/src/policies/field_policy.dart b/normalize/lib/src/policies/field_policy.dart index 63d923f3..5d8ff5f2 100644 --- a/normalize/lib/src/policies/field_policy.dart +++ b/normalize/lib/src/policies/field_policy.dart @@ -50,7 +50,7 @@ class FieldFunctionOptions { dataIdFromObject: _config.dataIdFromObject, addTypename: _config.addTypename, allowPartialData: true, - possibleTypeOf: _config.possibleTypeOf, + possibleTypes: _config.possibleTypes, ), ) as T?; } diff --git a/normalize/lib/src/utils/expand_fragments.dart b/normalize/lib/src/utils/expand_fragments.dart index c2f7c5e5..820ac493 100644 --- a/normalize/lib/src/utils/expand_fragments.dart +++ b/normalize/lib/src/utils/expand_fragments.dart @@ -6,7 +6,7 @@ List expandFragments({ required String? typename, required SelectionSetNode selectionSet, required Map fragmentMap, - required Map> possibleTypeOf, + required Map> possibleTypes, }) { final fieldNodes = []; @@ -40,13 +40,13 @@ List expandFragments({ // - If the fragment and current type are the same (fragmentOnName == typename) // - Or the current type is a type of the fragment target if (fragmentOnName == typename || - possibleTypeOf[typename]?.contains(fragmentOnName) == true) { + possibleTypes[fragmentOnName]?.contains(typename) == true) { fieldNodes.addAll( expandFragments( typename: typename, selectionSet: fragmentSelectionSet, fragmentMap: fragmentMap, - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ), ); } diff --git a/normalize/lib/src/utils/operation_field_names.dart b/normalize/lib/src/utils/operation_field_names.dart index 7e121d4a..6036eab9 100644 --- a/normalize/lib/src/utils/operation_field_names.dart +++ b/normalize/lib/src/utils/operation_field_names.dart @@ -13,7 +13,7 @@ List operationFieldNames( String operationName, Map vars, Map typePolicies, - Map> possibleTypeOf, + Map> possibleTypes, ) { final operationDefinition = getOperationDefinition( document, @@ -28,7 +28,7 @@ List operationFieldNames( typename: rootTypename, selectionSet: operationDefinition.selectionSet, fragmentMap: fragmentMap, - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ); final typePolicy = typePolicies[rootTypename]; return fields.map((fieldNode) { diff --git a/normalize/test/possible_type_of.dart b/normalize/test/possible_type_of.dart index ab21b53e..1c75e949 100644 --- a/normalize/test/possible_type_of.dart +++ b/normalize/test/possible_type_of.dart @@ -6,9 +6,8 @@ import 'package:normalize/normalize.dart'; void main() { group('Normalizing and denormalizing with possible type of', () { test('Mutiple fragments', () { - final possibleTypeOf = { - 'Author': {'User'}, - 'Audience': {'User'}, + final possibleTypes = { + 'User': {'Author', 'Audience'}, }; final document = parseString(''' fragment FAudience on Audience { @@ -80,7 +79,7 @@ void main() { document: document, data: data, acceptPartialData: false, - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ); expect( normalizedResult, @@ -92,7 +91,7 @@ void main() { document: document, handleException: false, read: (dataId) => normalizedMap[dataId], - possibleTypeOf: possibleTypeOf, + possibleTypes: possibleTypes, ), equals(data), );