private static IList <LambdaExpression> BuildFieldResolver_BuildMethodArguments(MethodInfo methodInfo, Type?sourceType, FieldType?fieldType) { List <LambdaExpression> expressions = new(); foreach (var parameterInfo in methodInfo.GetParameters()) { var typeInformation = new TypeInformation(parameterInfo); typeInformation.ApplyAttributes(); // typically this is unnecessary, since this is primarily used to control the graph type of generated query arguments var argumentInfo = new ArgumentInformation(parameterInfo, sourceType, fieldType, typeInformation); argumentInfo.ApplyAttributes(); // necessary to allow [FromSource], [FromServices] and similar attributes to work var(queryArgument, expression) = argumentInfo.ConstructQueryArgument(); if (queryArgument != null) { // even though the query argument is not used, it is necessary to apply attributes to the generated argument in case the name is overridden, // as the generated query argument's name is used within the expression for the call to GetArgument var attributes = parameterInfo.GetCustomAttributes <GraphQLAttribute>(); foreach (var attr in attributes) { attr.Modify(queryArgument); } } expression ??= GetParameterExpression( parameterInfo.ParameterType, queryArgument ?? throw new InvalidOperationException("Invalid response from ConstructQueryArgument: queryArgument and expression cannot both be null")); expressions.Add(expression); } return(expressions); }
/// <summary> /// Analyzes a method parameter and returns an instance of <see cref="ArgumentInformation"/> /// containing information necessary to build a <see cref="QueryArgument"/> and <see cref="IFieldResolver"/>. /// Also applies any <see cref="GraphQLAttribute"/> attributes defined on the <see cref="ParameterInfo"/> /// to the returned <see cref="ArgumentInformation"/> instance. /// </summary> protected virtual ArgumentInformation GetArgumentInformation <TParameterType>(FieldType fieldType, ParameterInfo parameterInfo) { var typeInformation = GetTypeInformation(parameterInfo); var argumentInfo = new ArgumentInformation(parameterInfo, typeof(TSourceType), fieldType, typeInformation); argumentInfo.ApplyAttributes(); return(argumentInfo); }