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); }
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; } } } }
internal ObjectField(ObjectFieldDescription fieldDescription) : base(fieldDescription) { _sourceType = fieldDescription.SourceType; _resolverType = fieldDescription.ResolverType; _member = fieldDescription.Member; Resolver = fieldDescription.Resolver; InterfaceFields = _interfaceFields.AsReadOnly(); ExecutableDirectives = _executableDirectives.AsReadOnly(); }
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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
internal ObjectField(ObjectFieldDescription fieldDescription) : base(fieldDescription) { _member = fieldDescription.Member; Resolver = fieldDescription.Resolver; }