//todo: use ResolversBuilder.AddLinkedTypes() /// <summary> /// Create resolvers for ObjectTypes and ObjectType extensions in <see cref="TypeSystemDocument"/> which /// resolve the values using the given <paramref name="link"/> /// </summary> /// <param name="remoteTypes"></param> /// <param name="link"></param> /// <param name="createResolver"></param> /// <param name="createSubscriber"></param> /// <returns></returns> public static ResolversMap CreateLinkResolvers( TypeSystemDocument remoteTypes, ExecutionResultLink link, Func <ExecutionResultLink, Resolver> createResolver = null, Func <ExecutionResultLink, Subscriber> createSubscriber = null) { if (createResolver == null) { createResolver = DefaultCreateRemoteResolver; } if (createSubscriber == null) { createSubscriber = DefaultCreateRemoteSubscriber; } var objectDefinitionsAndExtensions = GetObjectDefinitions(remoteTypes); var rootTypes = objectDefinitionsAndExtensions.Where(type => RootTypes.Contains(type.Name.Value)) .OfType <ObjectDefinition>(); ResolversMap resolvers = new ResolversMap(); foreach (var rootType in rootTypes) { foreach (var field in rootType.Fields) { if (rootType.Name != "Subscription") { resolvers.Add(rootType.Name.Value, field.Name.Value, createResolver(link)); } else { resolvers.Add(rootType.Name.Value, field.Name.Value, createSubscriber(link)); } } } var resolver = DefaultDictionaryResolver(); foreach (var objectType in objectDefinitionsAndExtensions.Where(type => !RootTypes.Contains(type.Name.Value)) .OfType <ObjectDefinition>()) { foreach (var field in objectType.Fields) { resolvers.Add(objectType.Name.Value, field.Name.Value, resolver); } } return(resolvers); }
public ResolversMap Clone() { var result = new ResolversMap(); foreach (var objectMap in this) { result.Add(objectMap.Key, objectMap.Value.Clone()); } return(result); }