public MutationType(ISchemaProvider schema, string methodName, GqlTypeInfo returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims, bool isAsync) { Description = description; ReturnType = returnType; this.mutationClassInstance = mutationClassInstance; this.method = method; Name = methodName; AuthorizeClaims = authorizeClaims; this.isAsync = isAsync; argInstanceType = method.GetParameters() .FirstOrDefault(p => p.GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null || p.ParameterType.GetTypeInfo().GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null)?.ParameterType; if (argInstanceType != null) { foreach (var item in argInstanceType.GetProperties()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), ArgType.FromProperty(schema, item)); } foreach (var item in argInstanceType.GetFields()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), ArgType.FromField(schema, item)); } } }
/// <summary> /// Build INPUT Type to be used by Mutations /// </summary> /// <param name="schema"></param> /// <remarks> /// Since Types and Inputs cannot have the same name, camelCase the name to prevent duplicates. /// </remarks> /// <returns></returns> private static List <TypeElement> BuildInputTypes(ISchemaProvider schema) { var types = new List <TypeElement>(); foreach (ISchemaType schemaType in schema.GetNonContextTypes().Where(s => s.IsInput)) { if (schemaType.Name.StartsWith("__")) { continue; } var inputValues = new List <InputValue>(); foreach (Field field in schemaType.GetFields()) { if (field.Name.StartsWith("__")) { continue; } // Skip any property with special attribute //== JT: When reading PropertyInfo, must use the default casing. Had to convert back to Pascal from Camel case var property = schemaType.ContextType.GetProperty(SchemaGenerator.ToPascalCaseStartsUpper(field.Name)); if (property != null && GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(property)) { continue; } // Skipping custom fields added to schema if (field.Resolve.NodeType == System.Linq.Expressions.ExpressionType.Call) { continue; } // Skipping ENUM type if (field.ReturnType.TypeDotnet.GetTypeInfo().IsEnum) { continue; } inputValues.Add(new InputValue { Name = field.Name, Description = field.Description, Type = BuildType(schema, field.ReturnType, field.ReturnType.TypeDotnet, true) }); } var typeElement = new TypeElement { Kind = "INPUT_OBJECT", Name = schemaType.Name, Description = schemaType.Description, InputFields = inputValues.ToArray() }; types.Add(typeElement); } return(types); }
/// <summary> /// Build INPUT Type to be used by Mutations /// </summary> /// <param name="schema"></param> /// <param name="combinedMapping"></param> /// <remarks> /// Since Types and Inputs cannot have the same name, camelCase the name to prevent duplicates. /// </remarks> /// <returns></returns> private static List <TypeElement> BuildInputTypes(ISchemaProvider schema, IReadOnlyDictionary <Type, string> combinedMapping) { var types = new List <TypeElement>(); foreach (ISchemaType schemaType in schema.GetNonContextTypes().Where(s => s.IsInput)) { if (schemaType.Name.StartsWith("__")) { continue; } var inputValues = new List <Models.InputValue>(); foreach (Field field in schemaType.GetFields()) { if (field.Name.StartsWith("__")) { continue; } // Skip any property with special attribute var property = schemaType.ContextType.GetProperty(field.Name); if (property != null && GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(property)) { continue; } // Skipping custom fields added to schema if (field.Resolve.NodeType == System.Linq.Expressions.ExpressionType.Call) { continue; } // Skipping ENUM type if (field.ReturnTypeClr.GetTypeInfo().IsEnum) { continue; } inputValues.Add(new Models.InputValue { Name = field.Name, Description = field.Description, Type = BuildType(schema, field.ReturnTypeClr, field.ReturnTypeClrSingle, combinedMapping, true) }); } var typeElement = new TypeElement { Kind = "INPUT_OBJECT", Name = schemaType.Name, Description = schemaType.Description, InputFields = inputValues.ToArray() }; types.Add(typeElement); } return(types); }
public MutationType(ISchemaProvider schema, string methodName, GqlTypeInfo returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims, bool isAsync, Func <MemberInfo, string> fieldNamer) { Description = description; ReturnType = returnType; this.mutationClassInstance = mutationClassInstance; this.method = method; Name = methodName; AuthorizeClaims = authorizeClaims; this.isAsync = isAsync; argInstanceType = method.GetParameters() .FirstOrDefault(p => p.GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null || p.ParameterType.GetTypeInfo().GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null)?.ParameterType; if (argInstanceType != null) { foreach (var item in argInstanceType.GetProperties()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(fieldNamer(item), ArgType.FromProperty(schema, item)); } foreach (var item in argInstanceType.GetFields()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(fieldNamer(item), ArgType.FromField(schema, item)); } } //== JT: Start Here else { /*== JT * When parameters are the standard System Types like; Int, String, etc or using the EntityGraphQL.Schema.RequiredField, * loop through the parameters and NOT the object's properties * NOTE: some parameters might be Services * EX: public ReturnModel RemoveById(DataContext context, RequiredField<int> id) */ // !! Forcing a single parameter ONLY. Anything more than that should require a POCO !! ParameterInfo item = method.GetParameters() .FirstOrDefault(p => p.ParameterType.Namespace.StartsWith("EntityGraphQL.Schema") || p.ParameterType.Namespace.StartsWith("System")); if (item.ParameterType.Name == "Nullable`1") { Type argType = item.ParameterType.GetGenericArguments()[0]; argInstanceType = argType; } else { argInstanceType = item.ParameterType; } //TODO: see if able to use the "fieldNamer()" function argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), ArgType.FromParameter(schema, item)); } //== }
public MutationType(string methodName, ISchemaType returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims) { this.Description = description; this.ReturnType = returnType; this.mutationClassInstance = mutationClassInstance; this.method = method; Name = methodName; AuthorizeClaims = authorizeClaims; var methodArg = method.GetParameters().ElementAt(1); this.argInstanceType = methodArg.ParameterType; foreach (var item in argInstanceType.GetProperties()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), new ArgType { Type = item.PropertyType, TypeNotNullable = GraphQLNotNullAttribute.IsMemberMarkedNotNull(item) || item.PropertyType.GetTypeInfo().IsEnum }); } foreach (var item in argInstanceType.GetFields()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), new ArgType { Type = item.FieldType, TypeNotNullable = GraphQLNotNullAttribute.IsMemberMarkedNotNull(item) || item.FieldType.GetTypeInfo().IsEnum }); } }