|
|
|
@ -8,43 +8,25 @@ |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using GraphQL; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Squidex.Domain.Apps.Entities.Apps; |
|
|
|
using Squidex.Domain.Apps.Entities.Assets; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Infrastructure.Log; |
|
|
|
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
{ |
|
|
|
public sealed class CachingGraphQLService : CachingProviderBase, IGraphQLService |
|
|
|
{ |
|
|
|
private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10); |
|
|
|
private readonly IContentQueryService contentQuery; |
|
|
|
private readonly IGraphQLUrlGenerator urlGenerator; |
|
|
|
private readonly ISemanticLog log; |
|
|
|
private readonly IAssetQueryService assetQuery; |
|
|
|
private readonly IAppProvider appProvider; |
|
|
|
|
|
|
|
public CachingGraphQLService( |
|
|
|
IMemoryCache cache, |
|
|
|
IAppProvider appProvider, |
|
|
|
IAssetQueryService assetQuery, |
|
|
|
IContentQueryService contentQuery, |
|
|
|
IGraphQLUrlGenerator urlGenerator, |
|
|
|
ISemanticLog log) |
|
|
|
private readonly IDependencyResolver resolver; |
|
|
|
|
|
|
|
public CachingGraphQLService(IMemoryCache cache, IDependencyResolver resolver) |
|
|
|
: base(cache) |
|
|
|
{ |
|
|
|
Guard.NotNull(appProvider, nameof(appProvider)); |
|
|
|
Guard.NotNull(assetQuery, nameof(assetQuery)); |
|
|
|
Guard.NotNull(contentQuery, nameof(contentQuery)); |
|
|
|
Guard.NotNull(urlGenerator, nameof(urlGenerator)); |
|
|
|
Guard.NotNull(log, nameof(log)); |
|
|
|
|
|
|
|
this.appProvider = appProvider; |
|
|
|
this.assetQuery = assetQuery; |
|
|
|
this.contentQuery = contentQuery; |
|
|
|
this.urlGenerator = urlGenerator; |
|
|
|
this.log = log; |
|
|
|
Guard.NotNull(resolver, nameof(resolver)); |
|
|
|
|
|
|
|
this.resolver = resolver; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<(bool HasError, object Response)> QueryAsync(QueryContext context, params GraphQLQuery[] queries) |
|
|
|
@ -54,7 +36,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
|
|
|
|
var model = await GetModelAsync(context.App); |
|
|
|
|
|
|
|
var ctx = new GraphQLExecutionContext(context, assetQuery, contentQuery, urlGenerator); |
|
|
|
var ctx = new GraphQLExecutionContext(context, resolver); |
|
|
|
|
|
|
|
var result = await Task.WhenAll(queries.Select(q => QueryInternalAsync(model, ctx, q))); |
|
|
|
|
|
|
|
@ -68,7 +50,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
|
|
|
|
var model = await GetModelAsync(context.App); |
|
|
|
|
|
|
|
var ctx = new GraphQLExecutionContext(context, assetQuery, contentQuery, urlGenerator); |
|
|
|
var ctx = new GraphQLExecutionContext(context, resolver); |
|
|
|
|
|
|
|
var result = await QueryInternalAsync(model, ctx, query); |
|
|
|
|
|
|
|
@ -82,7 +64,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
return (false, new { data = new object() }); |
|
|
|
} |
|
|
|
|
|
|
|
var result = await model.ExecuteAsync(ctx, query, log); |
|
|
|
var result = await model.ExecuteAsync(ctx, query); |
|
|
|
|
|
|
|
if (result.Errors?.Any() == true) |
|
|
|
{ |
|
|
|
@ -102,9 +84,13 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
{ |
|
|
|
entry.AbsoluteExpirationRelativeToNow = CacheDuration; |
|
|
|
|
|
|
|
var allSchemas = await appProvider.GetSchemasAsync(app.Id); |
|
|
|
var allSchemas = await resolver.Resolve<IAppProvider>().GetSchemasAsync(app.Id); |
|
|
|
|
|
|
|
return new GraphQLModel(app, allSchemas, contentQuery.DefaultPageSizeGraphQl, assetQuery.DefaultPageSizeGraphQl, urlGenerator); |
|
|
|
return new GraphQLModel(app, |
|
|
|
allSchemas, |
|
|
|
resolver.Resolve<IContentQueryService>().DefaultPageSizeGraphQl, |
|
|
|
resolver.Resolve<IAssetQueryService>().DefaultPageSizeGraphQl, |
|
|
|
resolver.Resolve<IGraphQLUrlGenerator>()); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|