#pragma warning disable CA1822 // Mark members as static #pragma warning disable VSTHRD200 // Use "Async" suffix for async methods public async Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) #pragma warning restore VSTHRD200 // Use "Async" suffix for async methods #pragma warning restore CA1822 // Mark members as static { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (next is null) { throw new ArgumentNullException(nameof(next)); } var metadata = new Dictionary <string, object> { { "typeName", context.ParentType.Name }, { "fieldName", context.FieldName }, { "path", context.Path }, { "arguments", context.Arguments }, }; var path = $"{context.ParentType.Name}.{context.FieldName}"; using (context.Metrics.Subject("field", path, metadata)) { return(await next(context).ConfigureAwait(false)); } }
/// <inheritdoc/> public async ValueTask <object?> ResolveAsync(IResolveFieldContext context, FieldMiddlewareDelegate next) { var name = context.FieldAst.Name.StringValue; //ISSUE:allocation var metadata = new Dictionary <string, object?> { { "typeName", context.ParentType.Name },
public Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { using (context.Metrics.Subject("class", "from class")) { return(next(context)); } }
public Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { using (MiniProfiler.Current.Step($"[GraphQL] Resolving {string.Join(".", context.Path)}", ProfileLevel.Info)) { return(next(context)); } }
public void ApplyTo(ISchema schema) { schema.AllTypes.Apply(item => { var complex = item as IComplexGraphType; complex?.Fields.Apply(field => { var resolver = new MiddlewareResolver(field.Resolver); FieldMiddlewareDelegate app = context => resolver.Resolve(context); app = Build(app); field.Resolver = new FuncFieldResolver <object>(context => { try { var result = app.Invoke(context); result.ConfigureAwait(false); return(result.Result); } catch (AggregateException ex) { throw new Exception(ex.InnerException.Message, ex.InnerException); } }); }); }); }
public Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { string typeName = context.ParentType.Name; string fieldName = context.FieldName; Dictionary <string, object> metadata = new Dictionary <string, object>() { { "typeName", typeName }, { "fieldName", fieldName } }; using (context.Metrics.Subject("field", context.FieldName, metadata)) { var result = next(context); if (result.Exception != null) { LogException(result.Exception, typeName, fieldName); } return(result); } }
public async Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { var result = await next(context); var directive = context.FieldAst.Directives.Find("lowercase"); // check if directive exists, check argument values, etc. return(directive != null?result?.ToString().ToLower() : result); }
public FieldMiddlewareDelegate Build(FieldMiddlewareDelegate start = null) { var app = start ?? (context => Task.FromResult(new NameFieldResolver().Resolve(context))); foreach (var component in _components.Reverse()) { app = component(app); } return(app); }
public FieldMiddlewareDelegate Build(FieldMiddlewareDelegate start = null) { var app = start ?? (context => Task.FromResult(new NameFieldResolver().Resolve(context))); foreach (var component in _components.Reverse()) { app = component(app); } return app; }
public Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "typeName", context.ParentType.Name }, { "fieldName", context.FieldName } }; using (context.Metrics.Subject("field", context.FieldName, metadata)) { return(next(context)); } }
/// <inheritdoc/> public async Task <object> Resolve(IResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary <string, object> { { "typeName", context.ParentType.Name }, { "fieldName", context.FieldName }, { "returnTypeName", SchemaPrinter.ResolveName(context.ReturnType) }, { "path", context.Path }, }; using (context.Metrics.Subject("field", context.FieldName, metadata)) return(await next(context).ConfigureAwait(false)); }
public async Task <object?> Resolve(IResolveFieldContext context, FieldMiddlewareDelegate next) { try { return(await next(context)); } catch (ValidationException validationException) { context.Errors.AddRange(validationException.Errors.Select(ToExecutionError)); return(ReturnTypeFinder.Find(context)); } }
public Task<object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary<string, object> { {"typeName", context.ParentType.Name}, {"fieldName", context.FieldName} }; using (context.Metrics.Subject("field", context.FieldName, metadata)) { return next(context); } }
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 async Task <object> Resolve( ResolveFieldContext context, FieldMiddlewareDelegate next) { try { return(await next(context)); } catch (BoxSessionInvalidatedException) { context.Errors.Add(new ExecutionError("Could not obtain a valid session with Box.")); throw; } }
public Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { if (context.ReturnType is StringGraphType) { return(FastDecorator(context, next, null)); } if (context.ReturnType is NonNullGraphType nonnull && nonnull.ResolvedType is StringGraphType) { return(FastDecorator(context, next, string.Empty)); } return(next(context)); }
public void ApplyTo(ISchema schema) { foreach (var complex in schema.AllTypes.OfType <IComplexGraphType>()) { foreach (var field in complex.Fields) { var resolver = new MiddlewareResolver(field.Resolver); FieldMiddlewareDelegate app = Build(resolver.Resolve); field.Resolver = new FuncFieldResolver <object>(app.Invoke); } } }
public void ApplyTo(ISchema schema) { schema.AllTypes.Apply(item => { var complex = item as IComplexGraphType; complex?.Fields.Apply(field => { var resolver = new MiddlewareResolver(field.Resolver); FieldMiddlewareDelegate app = Build(resolver.Resolve); field.Resolver = new FuncFieldResolver <object>(app.Invoke); }); }); }
public Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary <string, object> { { "typeName", context.ParentType.Name }, { "fieldName", context.FieldName }, { "path", context.Path } }; //Console.WriteLine("hello world"); using (context.Metrics.Subject("field", context.FieldName, metadata)) { return(next(context)); } }
public async Task <object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary <string, object> { { "typeName", context.ParentType.Name }, { "fieldName", context.FieldName }, { "path", context.Path }, { "arguments", context.Arguments }, }; var path = $"{context.ParentType.Name}.{context.FieldName}"; using (context.Metrics.Subject("field", path, metadata)) { return(await next(context).ConfigureAwait(false)); } }
public Task <object> Resolve( ResolveFieldContext context, FieldMiddlewareDelegate next) { if (context.FieldDefinition.RequiresAuthorization()) { var err = new ExecutionError($"not authorized to access {context.ParentType.Name} : {context.FieldName}"); context.Errors.Add(err); return(Task.FromResult <object>(null)); } else { return(next(context)); } }
public async Task <object> Resolve( ResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary <string, object> { { "typeName", context.ParentType.Name }, { "fieldName", context.FieldName }, { "path", context.Path }, { "arguments", context.Arguments }, }; var path = $"{context.ParentType.Name}.{context.FieldName}"; try { using (context.Metrics.Subject("field", path, metadata)) { return(await next(context).ConfigureAwait(false)); } //return await next(context); } catch (Exception e) { ErrorLog log = new ErrorLog() { time = DateTime.Now, action = path, log_level = "alert", api_message = new ErrorLog.ApiMessage() { request = JsonConvert.SerializeObject(context.Arguments) }, project_name = "log" }; log.error_message = e.ToString(); //Lay lai cai goc; try { await LogHelper.AddLogAsync(log); }catch (Exception ex) { } throw; } }
internal FieldMiddlewareDelegate Build(FieldMiddlewareDelegate start, ISchema schema) { var middlewareDelegate = start ?? (context => Task.FromResult(NameFieldResolver.Instance.Resolve(context))); if (_middlewares != null) { foreach (var middleware in _middlewares.Reverse()) { middlewareDelegate = middleware(schema, middlewareDelegate); } } else if (_singleMiddleware != null) { middlewareDelegate = _singleMiddleware(schema, middlewareDelegate); } return(middlewareDelegate); }
public void ApplyTo(ISchema schema) { // allocation free optimization if no middlewares are defined if (!Empty) { foreach (var complex in schema.AllTypes.OfType <IComplexGraphType>()) { foreach (var field in complex.Fields) { var resolver = new MiddlewareResolver(field.Resolver); FieldMiddlewareDelegate app = Build(resolver.Resolve); field.Resolver = new FuncFieldResolver <object>(app.Invoke); } } } }
public FieldMiddlewareDelegate Build(FieldMiddlewareDelegate start = null) { var app = start ?? (context => Task.FromResult(NameFieldResolver.Instance.Resolve(context))); if (_components != null) { foreach (var component in _components.Reverse()) { app = component(app); } } else if (_singleComponent != null) { app = _singleComponent(app); } return(app); }
public async Task <object> Resolve( ResolveFieldContext context, FieldMiddlewareDelegate next) { var _cachePolicy = (ICachePolicy)((IServiceProvider)context.UserContext["serviceProvider"]).GetService(typeof(ICachePolicy)); CacheControlPayload cacheControlPayload = null; // check if the field contains cache attribute object tempValue; if (context.FieldDefinition.Metadata.TryGetValue(CacheControlAttribute.MetadataKey, out tempValue)) { cacheControlPayload = tempValue as CacheControlPayload; } // check if the field type has cache attriubute else { IGraphType returnType; if (context.ReturnType is ListGraphType list) { returnType = list.ResolvedType; } else { returnType = context.ReturnType; } if (returnType.Metadata.TryGetValue(CacheControlAttribute.MetadataKey, out tempValue)) { cacheControlPayload = tempValue as CacheControlPayload; } } if (cacheControlPayload == null) { // if the cache is not assigned by the user use the default cacheControlPayload = new CacheControlPayload(-1, CacheControlScope.Public); } // add the cache payload to the cache policy _cachePolicy.AddCacheControl(cacheControlPayload); return(await next(context)); }
public FieldMiddlewareDelegate Build(FieldMiddlewareDelegate start = null) { return(overriddenBuilder.Build(start)); }
public async Task <object> FastDecorator(ResolveFieldContext context, FieldMiddlewareDelegate next, string emptyChar) { var result = await next(context) as string; return(string.IsNullOrEmpty(result) ? emptyChar : result); }
public Task<object> Resolve(ResolveFieldContext context, FieldMiddlewareDelegate next) { using (context.Metrics.Subject("class", "from class")) { return next(context); } }
/// <inheritdoc/> public async Task <object?> Resolve(IResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary <string, object?> { { "typeName", context.ParentType.Name },
public Task <object> Resolve(IResolveFieldContext context, FieldMiddlewareDelegate next) { Interlocked.Increment(ref _count); return(next(context)); }
/// <inheritdoc/> public ValueTask <object?> ResolveAsync(IResolveFieldContext context, FieldMiddlewareDelegate next) { return(context.Metrics.Enabled ? ResolveWhenMetricsEnabledAsync(context, next) : next(context)); }