private static void CompleteFieldResolverBindungs( ObjectTypeBinding typeBinding, IEnumerable <FieldResolverBindungInfo> fieldResolverBindings) { foreach (FieldResolverBindungInfo binding in fieldResolverBindings) { if (binding.FieldMember == null && binding.FieldName == null) { binding.FieldMember = binding.ResolverMember; } if (binding.FieldMember == null && typeBinding != null && typeBinding.Fields.TryGetValue( binding.FieldName, out FieldBinding fieldBinding)) { binding.FieldMember = fieldBinding.Member; } if (binding.FieldName == null && typeBinding != null) { fieldBinding = typeBinding.Fields.Values .FirstOrDefault(t => t.Member == binding.FieldMember); binding.FieldName = fieldBinding.Name; } // todo : error handling if (binding.FieldName == null) { binding.FieldName = binding.FieldMember.GetGraphQLName(); } } }
private void CompleteCollectionBindings(ITypeRegistry typeRegistry) { foreach (ResolverCollectionBindingInfo binding in _resolverBindings .OfType <ResolverCollectionBindingInfo>()) { if (binding.ObjectType == null && binding.ObjectTypeName.IsEmpty) { binding.ObjectType = binding.ResolverType; } ObjectTypeBinding typeBinding = null; if (binding.ObjectType == null && typeRegistry .TryGetTypeBinding(binding.ObjectTypeName, out typeBinding)) { binding.ObjectType = typeBinding.Type; } if (binding.ObjectTypeName.IsEmpty && typeRegistry .TryGetTypeBinding(binding.ObjectType, out typeBinding)) { binding.ObjectTypeName = typeBinding.Name; } if (binding.ObjectTypeName.IsEmpty) { binding.ObjectTypeName = binding.ObjectType.GetGraphQLName(); } // TODO : error handling if object type cannot be resolverd CompleteFieldResolverBindungs( typeBinding, binding.Fields); } }
CreateObjectTypeBindings(ITypeRegistry typeRegistry) { var typeBindings = new Dictionary <ObjectType, ObjectTypeBinding>(); foreach (TypeBindingInfo typeBindingInfo in _typeBindings) { if (typeBindingInfo.Name == null) { typeBindingInfo.Name = typeBindingInfo.Type.GetGraphQLName(); } IEnumerable <FieldBinding> fieldBindings = null; if (typeRegistry.TryGetType( typeBindingInfo.Name, out ObjectType ot)) { fieldBindings = CreateFieldBindings(typeBindingInfo, ot.Fields); typeBindings[ot] = new ObjectTypeBinding(ot.Name, typeBindingInfo.Type, ot, fieldBindings); } } return(typeBindings); }
private void CompleteFieldResolverBindungs( ResolverCollectionBindingInfo resolverCollectionBinding, ObjectTypeBinding typeBinding, IEnumerable <FieldResolverBindungInfo> fieldResolverBindings) { foreach (FieldResolverBindungInfo binding in fieldResolverBindings) { if (binding.FieldMember == null && binding.FieldName == null) { binding.FieldMember = binding.ResolverMember; } if (binding.FieldMember == null && typeBinding != null && typeBinding.Fields.TryGetValue( binding.FieldName, out FieldBinding fieldBinding)) { binding.FieldMember = fieldBinding.Member; } if (binding.FieldName == null && typeBinding != null) { fieldBinding = typeBinding.Fields.Values .FirstOrDefault(t => t.Member == binding.FieldMember); binding.FieldName = fieldBinding?.Name; } // todo : error handling if (binding.FieldName == null) { binding.FieldName = GetNameFromMember(binding.FieldMember); } } }
private Dictionary <ObjectType, ObjectTypeBinding> CreateObjectTypeBindings( ITypeRegistry typeRegistry) { Dictionary <ObjectType, ObjectTypeBinding> typeBindings = new Dictionary <ObjectType, ObjectTypeBinding>(); foreach (TypeBindingInfo typeBindingInfo in _typeBindings) { if (typeBindingInfo.Name == null) { typeBindingInfo.Name = GetNameFromType(typeBindingInfo.Type); } IEnumerable <FieldBinding> fieldBindings = null; if (typeRegistry.TryGetType <ObjectType>( typeBindingInfo.Name, out ObjectType ot)) { fieldBindings = CreateFieldBindings(typeBindingInfo, ot.Fields); typeBindings[ot] = new ObjectTypeBinding(ot.Name, typeBindingInfo.Type, ot, fieldBindings); } } return(typeBindings); }