private static string BuildMethodParameterDefinition(GraphQlType baseType, GraphQlArgument argument) { var isArgumentNotNull = argument.Type.Kind == GraphQlTypeKindNonNull; var isTypeNotNull = isArgumentNotNull; var unwrappedType = argument.Type.UnwrapIfNonNull(); var isCollection = unwrappedType.Kind == GraphQlTypeKindList; if (isCollection) { isTypeNotNull = unwrappedType.OfType.Kind == GraphQlTypeKindNonNull; unwrappedType = unwrappedType.OfType.UnwrapIfNonNull(); } var argumentNetType = unwrappedType.Kind == GraphQlTypeKindEnum ? $"{unwrappedType.Name}?" : ScalarToNetType(baseType, argument.Name, unwrappedType); if (isTypeNotNull) { argumentNetType = argumentNetType.TrimEnd('?'); } if (unwrappedType.Kind == GraphQlTypeKindInputObject) { argumentNetType = $"{unwrappedType.Name}{GraphQlGeneratorConfiguration.ClassPostfix}"; } if (isCollection) { argumentNetType = $"IEnumerable<{argumentNetType}>"; } var argumentDefinition = $"{argumentNetType} {NamingHelper.ToValidVariableName(argument.Name)}"; if (!isArgumentNotNull) { argumentDefinition = $"{argumentDefinition} = null"; } return(argumentDefinition); }
private static void AppendArgumentDictionary(StringBuilder builder, ICollection <GraphQlArgument> args) { if (args.Count == 0) { return; } builder.AppendLine(" var args = new Dictionary<string, object>();"); foreach (var arg in args) { if (arg.Type.Kind == GraphQlTypeKindNonNull) { builder.AppendLine($" args.Add(\"{arg.Name}\", {NamingHelper.ToValidVariableName(arg.Name)});"); } else { builder.AppendLine($" if ({NamingHelper.ToValidVariableName(arg.Name)} != null)"); builder.AppendLine($" args.Add(\"{arg.Name}\", {NamingHelper.ToValidVariableName(arg.Name)});"); builder.AppendLine(); } } }