public static void SetFields <TSourceType>(ComplexGraphType <TSourceType> type, IEnumerable <PropertyInfo> properties, GraphObjectTypeReflectionOptions <TSourceType> options) { // Default the options if we get a null passed in. if (options == null) { options = new GraphObjectTypeReflectionOptions <TSourceType>(); } //type.Name = typeof(TSourceType).GraphQLName(); // Don't do this, it will then break with Input types. // Helper method that works out if bool isNullable(PropertyInfo propertyInfo) { if (!options.Nullable.HasValue) { return(IsNullableProperty(propertyInfo)); } if (options.NullableProperties?.Any(p => GetPropertyName(p) == propertyInfo.Name) == true) { return(true); } if (options.NonNullableProperties?.Any(p => GetPropertyName(p) == propertyInfo.Name) == true) { return(false); } return(options.Nullable.Value); } foreach (var propertyInfo in properties) { if (options.ExcludedProperties?.Any(p => GetPropertyName(p) == propertyInfo.Name) == true) { continue; } if (options.SkipExisting) { if (type.Fields.Any(p => p.Name == propertyInfo.Name)) { continue; } } type.Field( type: propertyInfo.PropertyType.GetGraphTypeFromType(isNullable(propertyInfo)), name: propertyInfo.Name, description: propertyInfo.Description(), deprecationReason: propertyInfo.ObsoleteMessage() ).DefaultValue = (propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), false).FirstOrDefault() as DefaultValueAttribute)?.Value; } }
/// <summary> /// Creates a GraphQL type from <typeparamref name="TSourceType"/> by specifying additional options. /// </summary> public ReflectedInputObjectGraphType(GraphObjectTypeReflectionOptions <TSourceType> options) { GraphObjectTypeReflectionHelper.SetFields(this, GetRegisteredProperties(), options); }