mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using GraphQL;
|
|
using GraphQL.Instrumentation;
|
|
using GraphQL.Types;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Log;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
|
|
{
|
|
public static class Middlewares
|
|
{
|
|
public static Func<ISchema, FieldMiddlewareDelegate, FieldMiddlewareDelegate> Logging(ISemanticLog log)
|
|
{
|
|
Guard.NotNull(log, nameof(log));
|
|
|
|
return (_, next) =>
|
|
{
|
|
return async context =>
|
|
{
|
|
try
|
|
{
|
|
return await next(context);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.LogWarning(ex, w => w
|
|
.WriteProperty("action", "resolveField")
|
|
.WriteProperty("status", "failed")
|
|
.WriteProperty("field", context.FieldName));
|
|
|
|
throw;
|
|
}
|
|
};
|
|
};
|
|
}
|
|
|
|
public static Func<ISchema, FieldMiddlewareDelegate, FieldMiddlewareDelegate> Errors()
|
|
{
|
|
return (_, next) =>
|
|
{
|
|
return async context =>
|
|
{
|
|
try
|
|
{
|
|
return await next(context);
|
|
}
|
|
catch (DomainException ex)
|
|
{
|
|
throw new ExecutionError(ex.Message);
|
|
}
|
|
};
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|