예제 #1
0
        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 = binding.FieldMember.GetGraphQLName();
                }
            }
        }
예제 #2
0
 internal BindFieldResolver(
     ResolverCollectionBindingInfo bindingInfo,
     FieldResolverBindungInfo fieldBindingInfo)
 {
     _bindingInfo = bindingInfo
                    ?? throw new ArgumentNullException(nameof(bindingInfo));
     _fieldBindingInfo = fieldBindingInfo
                         ?? throw new ArgumentNullException(nameof(fieldBindingInfo));
 }
예제 #3
0
        internal BoundResolver(ResolverCollectionBindingInfo bindingInfo)
        {
            if (bindingInfo == null)
            {
                throw new ArgumentNullException(nameof(bindingInfo));
            }

            _bindingInfo = bindingInfo;
        }
예제 #4
0
        public IBindResolver <TResolver> BindResolver <TResolver>(
            BindingBehavior bindingBehavior)
            where TResolver : class
        {
            var bindingInfo =
                new ResolverCollectionBindingInfo
            {
                Behavior     = bindingBehavior,
                ResolverType = typeof(TResolver)
            };

            _resolverBindings.Add(bindingInfo);
            return(new BindResolver <TResolver>(bindingInfo));
        }
        private List <IFieldResolverDescriptor> CollectPossibleDescriptors(
            ITypeRegistry typeRegistry,
            ResolverCollectionBindingInfo resolverBinding)
        {
            var descriptors = new List <IFieldResolverDescriptor>();

            // if implicit resolver discovery is on get all possible
            // resolver members from the resolver type.
            if (resolverBinding.Behavior == BindingBehavior.Implicit)
            {
                descriptors.AddRange(FieldResolverDiscoverer.DiscoverResolvers(
                                         resolverBinding.ResolverType,
                                         resolverBinding.ObjectType,
                                         resolverBinding.ObjectTypeName,
                                         m => LookupFieldName(typeRegistry, m)));
            }

            if (resolverBinding.Fields.Count > 0)
            {
                ILookup <string, IFieldResolverDescriptor> descriptorLookup =
                    descriptors.ToLookup(t => t.Field.FieldName);

                IEnumerable <FieldMember> selectedResolvers =
                    resolverBinding.Fields.Select(
                        t => new FieldMember(
                            resolverBinding.ObjectTypeName,
                            t.FieldName, t.ResolverMember)).ToArray();

                foreach (IFieldResolverDescriptor explicitDescriptor in
                         FieldResolverDiscoverer.CreateResolverDescriptors(
                             resolverBinding.ResolverType,
                             resolverBinding.ObjectType,
                             selectedResolvers))
                {
                    // remove implicit declared descriptos for the
                    // explcitly declared ones.
                    RemoveDescriptors(descriptors,
                                      descriptorLookup[explicitDescriptor.Field.FieldName]);

                    // add the explicitly declared descriptor
                    descriptors.Add(explicitDescriptor);
                }
            }

            return(descriptors);
        }
예제 #6
0
 public BindResolver(ResolverCollectionBindingInfo bindingInfo)
 {
     _bindingInfo = bindingInfo
                    ?? throw new ArgumentNullException(nameof(bindingInfo));
 }