コード例 #1
0
        private void CompleteFields()
        {
            var fields         = new Dictionary <string, ObjectFieldDescription>();
            var handledMembers = new HashSet <MemberInfo>();

            foreach (ObjectFieldDescriptor fieldDescriptor in Fields)
            {
                ObjectFieldDescription fieldDescription = fieldDescriptor
                                                          .CreateDescription();

                if (!fieldDescription.Ignored)
                {
                    fields[fieldDescription.Name] = fieldDescription;
                }

                if (fieldDescription.ClrMember != null)
                {
                    handledMembers.Add(fieldDescription.ClrMember);
                }
            }

            OnCompleteFields(fields, handledMembers);

            ObjectDescription.Fields.AddRange(fields.Values);
        }
コード例 #2
0
        protected internal static void AddResolverType(
            IDictionary <string, ObjectFieldDescription> fields,
            ISet <string> processed,
            Type sourceType,
            Type resolverType)
        {
            Dictionary <string, MemberInfo> members =
                ReflectionUtils.GetMembers(resolverType);

            foreach (KeyValuePair <string, MemberInfo> member in members)
            {
                if (IsResolverRelevant(sourceType, member.Value))
                {
                    ObjectFieldDescription description =
                        CreateFieldDescriptor(
                            sourceType, resolverType, member.Value)
                        .CreateDescription();

                    if (processed.Add(description.Name))
                    {
                        fields[description.Name] = description;
                    }
                }
            }
        }
コード例 #3
0
        internal ObjectField(ObjectFieldDescription fieldDescription)
            : base(fieldDescription)
        {
            _sourceType   = fieldDescription.SourceType;
            _resolverType = fieldDescription.ResolverType;
            _member       = fieldDescription.Member;

            Resolver             = fieldDescription.Resolver;
            InterfaceFields      = _interfaceFields.AsReadOnly();
            ExecutableDirectives = _executableDirectives.AsReadOnly();
        }
コード例 #4
0
        internal ObjectField(ObjectFieldDescription fieldDescription)
            : base(fieldDescription)
        {
            _sourceType           = fieldDescription.SourceType ?? typeof(object);
            _resolverType         = fieldDescription.ResolverType;
            _member               = fieldDescription.ClrMember;
            _middlewareComponents = fieldDescription.MiddlewareComponents;

            Resolver             = fieldDescription.Resolver;
            InterfaceFields      = _interfaceFields.AsReadOnly();
            ExecutableDirectives = _executableDirectives.AsReadOnly();
        }
コード例 #5
0
        protected virtual void CompleteFields()
        {
            var fields = new Dictionary <string, ObjectFieldDescription>();

            foreach (ObjectFieldDescriptor fieldDescriptor in Fields)
            {
                ObjectFieldDescription fieldDescription = fieldDescriptor
                                                          .CreateDescription();
                fields[fieldDescription.Name] = fieldDescription;
            }

            ObjectDescription.Fields.AddRange(fields.Values);
        }
コード例 #6
0
        public void SchemaTypesOverwriteDotNetTypes()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor("Type", "field");

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Type <NativeType <IReadOnlyDictionary <string, string> > >()
            .Type <ListType <StringType> >();

            // assert
            ObjectFieldDescription description = descriptor.CreateDescription();
            TypeReference          typeRef     = description.TypeReference;

            Assert.Equal(typeof(ListType <StringType>), typeRef.ClrType);
        }
コード例 #7
0
        public void ResolverTypeIsSet()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

            // act
            descriptor.ResolverType(typeof(string));

            // assert
            ObjectFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(typeof(ObjectField), description.SourceType);
            Assert.Equal(typeof(string), description.ResolverType);
        }
コード例 #8
0
        public void SourceTypeIsSet()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Name("args");

            // assert
            ObjectFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(typeof(ObjectField), description.SourceType);
        }
コード例 #9
0
        public void ResolverTypesDoNotOverwriteSchemaTypes()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Name("args")
            .Type <NonNullType <ListType <NonNullType <__InputValue> > > >()
            .Resolver(c => c.Parent <ObjectField>().Arguments);

            // assert
            ObjectFieldDescription description = descriptor.CreateDescription();
            TypeReference          typeRef     = description.TypeReference;

            Assert.Equal(typeof(NonNullType <ListType <NonNullType <__InputValue> > >), typeRef.ClrType);
        }
コード例 #10
0
        public void SetResolverAndInferTypeIsAlwaysRecognosedAsDotNetType()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Type <__Type>()
            .Resolver(ctx => ctx.Schema
                      .GetType <INamedType>(ctx.Argument <string>("type")));

            // assert
            ObjectFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(typeof(__Type), description.TypeReference.ClrType);
            Assert.NotNull(description.Resolver);
        }
コード例 #11
0
        public void SetResolverAndInferTypeFromResolver()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                "Field", typeof(ObjectField).GetProperty("Arguments"),
                typeof(IReadOnlyDictionary <string, InputField>));

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Resolver(() => "ThisIsAString");

            // assert
            ObjectFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(typeof(NativeType <string>), description.TypeReference.NativeType);
            Assert.NotNull(description.Resolver);

            Mock <IResolverContext> context = new Mock <IResolverContext>(MockBehavior.Strict);

            Assert.Equal("ThisIsAString", description.Resolver(context.Object, default));
        }
コード例 #12
0
 internal ObjectField(ObjectFieldDescription fieldDescription)
     : base(fieldDescription)
 {
     _member  = fieldDescription.Member;
     Resolver = fieldDescription.Resolver;
 }