private static Field ProcessFieldOrProperty(MemberInfo prop, ParameterExpression param, ISchemaProvider schema, bool createEnumTypes, bool createNewComplexTypes, Func <MemberInfo, string> fieldNamer) { if (ignoreProps.Contains(prop.Name) || GraphQLIgnoreAttribute.ShouldIgnoreMemberFromQuery(prop)) { return(null); } // Get Description from ComponentModel.DescriptionAttribute string description = ""; var d = (DescriptionAttribute)prop.GetCustomAttribute(typeof(DescriptionAttribute), false); if (d != null) { description = d.Description; } LambdaExpression le = Expression.Lambda(prop.MemberType == MemberTypes.Property ? Expression.Property(param, prop.Name) : Expression.Field(param, prop.Name), param); var attributes = prop.GetCustomAttributes(typeof(GraphQLAuthorizeAttribute), true).Cast <GraphQLAuthorizeAttribute>(); var requiredClaims = new RequiredClaims(attributes); // get the object type returned (ignoring list etc) so we know the context to find fields etc var returnType = le.ReturnType.IsEnumerableOrArray() ? le.ReturnType.GetEnumerableOrArrayType() : le.ReturnType.GetNonNullableType(); var t = CacheType(returnType, schema, createEnumTypes, createNewComplexTypes, fieldNamer); // see if there is a direct type mapping from the expression return to to something. // otherwise build the type info var returnTypeInfo = schema.GetCustomTypeMapping(le.ReturnType) ?? new GqlTypeInfo(() => schema.Type(returnType), le.Body.Type); var f = new Field(fieldNamer(prop), le, description, returnTypeInfo, requiredClaims); return(f); }
private static Field ProcessFieldOrProperty <TContextType>(MemberInfo prop, Type fieldOrPropType, ParameterExpression param, MappedSchemaProvider <TContextType> schema) { if (ignoreProps.Contains(prop.Name) || GraphQLIgnoreAttribute.ShouldIgnoreMemberFromQuery(prop)) { return(null); } // Get Description from ComponentModel.DescriptionAttribute string description = ""; var d = (DescriptionAttribute)prop.GetCustomAttribute(typeof(DescriptionAttribute), false); if (d != null) { description = d.Description; } LambdaExpression le = Expression.Lambda(prop.MemberType == MemberTypes.Property ? Expression.Property(param, prop.Name) : Expression.Field(param, prop.Name), param); var f = new Field(SchemaGenerator.ToCamelCaseStartsLower(prop.Name), le, description); var t = CacheType <TContextType>(fieldOrPropType, schema); if (t != null && t.IsEnum && !f.ReturnTypeClr.IsNullableType()) { f.ReturnTypeNotNullable = true; } return(f); }
private static Field ProcessFieldOrProperty(MemberInfo prop, Type fieldOrPropType, ParameterExpression param, ISchemaProvider schema, bool createEnumTypes, bool createNewComplexTypes) { if (ignoreProps.Contains(prop.Name) || GraphQLIgnoreAttribute.ShouldIgnoreMemberFromQuery(prop)) { return(null); } // Get Description from ComponentModel.DescriptionAttribute string description = ""; var d = (DescriptionAttribute)prop.GetCustomAttribute(typeof(DescriptionAttribute), false); if (d != null) { description = d.Description; } LambdaExpression le = Expression.Lambda(prop.MemberType == MemberTypes.Property ? Expression.Property(param, prop.Name) : Expression.Field(param, prop.Name), param); var attributes = prop.GetCustomAttributes(typeof(GraphQLAuthorizeAttribute), true).Cast <GraphQLAuthorizeAttribute>(); var requiredClaims = new RequiredClaims(attributes); var returnType = le.ReturnType.IsEnumerableOrArray() ? le.ReturnType.GetEnumerableOrArrayType() : le.ReturnType; var t = CacheType(returnType, schema, createEnumTypes, createNewComplexTypes); var f = new Field(SchemaGenerator.ToCamelCaseStartsLower(prop.Name), le, description, null, null, requiredClaims); if (t != null && t.IsEnum && !f.ReturnTypeClr.IsNullableType()) { f.ReturnTypeNotNullable = true; } return(f); }