private static bool ShouldIncludeNode(Directives directives) { if (directives != null) { var directive = directives.Find(DirectiveGraphType.Skip.Name); if (directive != null) { var values = GetArgumentValues( DirectiveGraphType.Skip.Arguments, directive.Arguments, null); values.TryGetValue("if", out object ifObj); return(!(bool.TryParse(ifObj?.ToString() ?? string.Empty, out bool ifVal) && ifVal)); } directive = directives.Find(DirectiveGraphType.Include.Name); if (directive != null) { var values = GetArgumentValues( DirectiveGraphType.Include.Arguments, directive.Arguments, null); values.TryGetValue("if", out object ifObj); return(bool.TryParse(ifObj?.ToString() ?? string.Empty, out bool ifVal) && ifVal); } } return(true); }
private static bool?GetDirectiveValue(ValidationContext context, Directives directives, DirectiveGraphType directiveType, Variables variables) { var directive = directives.Find(directiveType.Name); if (directive == null) { return(null); } var argumentValues = ExecutionHelper.GetArgumentValues( context.Schema, directiveType.Arguments, directive.Arguments, variables); argumentValues.TryGetValue("if", out object ifObj); return(bool.TryParse(ifObj?.ToString() ?? string.Empty, out bool ifVal) && ifVal); }
public async Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { Object result = await next(context); if (result is null) { return(result); } Directives directives = context.FieldAst.Directives; if (directives.Find("lowerCase") != null) { return(result.ToString().ToLowerInvariant()); } if (directives.Find("upperCase") != null) { return(result.ToString().ToUpperInvariant()); } if (directives.Find("formatCpf") != null) { string entryText = Regex.Replace(result.ToString(), @"\D", ""); entryText = Regex.Replace(entryText, @"(\d{3})(\d{0,3})(\d{0,3})(\d{0,3})", @"$1.$2.$3-$4"); return(entryText); } if (directives.Find("formatPostalCode") != null) { string entryText = result.ToString(); return(Regex.Replace(entryText, @"(\d{5})(\d{3})", @"$1-$2")); } if (directives.Find("formatDateTime") != null) { Directive formatDateTime = directives.Find("formatDateTime"); string format = formatDateTime.Arguments.ValueFor("format").Value.ToString(); DateTime datetime = (DateTime)result; return(datetime.ToString(format)); } return(result); }
public bool ShouldIncludeNode(ExecutionContext context, Directives directives) { if (directives != null) { var directive = directives.Find(DirectiveGraphType.Skip.Name); if (directive != null) { var values = GetArgumentValues( context.Schema, DirectiveGraphType.Skip.Arguments, directive.Arguments, context.Variables); return !((bool) values["if"]); } directive = directives.Find(DirectiveGraphType.Include.Name); if (directive != null) { var values = GetArgumentValues( context.Schema, DirectiveGraphType.Include.Arguments, directive.Arguments, context.Variables); return (bool) values["if"]; } } return true; }
public bool ShouldIncludeNode(ExecutionContext context, Directives directives) { if (directives != null) { var directive = directives.Find(DirectiveGraphType.Skip.Name); if (directive != null) { var values = GetArgumentValues( context.Schema, DirectiveGraphType.Skip.Arguments, directive.Arguments, context.Variables); object ifObj; values.TryGetValue("if", out ifObj); bool ifVal; return !(bool.TryParse(ifObj?.ToString() ?? string.Empty, out ifVal) && ifVal); } directive = directives.Find(DirectiveGraphType.Include.Name); if (directive != null) { var values = GetArgumentValues( context.Schema, DirectiveGraphType.Include.Arguments, directive.Arguments, context.Variables); object ifObj; values.TryGetValue("if", out ifObj); bool ifVal; return bool.TryParse(ifObj?.ToString() ?? string.Empty, out ifVal) && ifVal; } } return true; }
public bool HasDirective(string name) => Directives.Find(d => d.Name.Name == name) != null;