Browse Source

More improvements.

pull/631/head
Sebastian 5 years ago
parent
commit
05ea940816
  1. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLService.cs
  2. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLModel.cs
  3. 6
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AppQueriesGraphType.cs
  4. 22
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Builder.cs
  5. 20
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs
  6. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentInterfaceGraphType.cs
  7. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/FieldInputVisitor.cs
  8. 9
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/FieldVisitor.cs
  9. 0
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/SchemaInfos.cs
  10. 13
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/SharedTypes.cs
  11. 2
      backend/src/Squidex/Config/Domain/QueryServices.cs
  12. 2
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLService.cs

@ -91,7 +91,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
return new GraphQLModel(app, return new GraphQLModel(app,
allSchemas, allSchemas,
resolver.GetRequiredService<GraphQLTypeFactory>(), resolver.GetRequiredService<SharedTypes>(),
resolver.GetRequiredService<ISemanticLog>()); resolver.GetRequiredService<ISemanticLog>());
}); });
} }

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLModel.cs

@ -24,7 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
private readonly GraphQLSchema schema; private readonly GraphQLSchema schema;
private readonly ISemanticLog log; private readonly ISemanticLog log;
public GraphQLModel(IAppEntity app, IEnumerable<ISchemaEntity> schemas, GraphQLTypeFactory typeFactory, ISemanticLog log) public GraphQLModel(IAppEntity app, IEnumerable<ISchemaEntity> schemas, SharedTypes typeFactory, ISemanticLog log)
{ {
this.log = log; this.log = log;

6
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AppQueriesGraphType.cs

@ -15,9 +15,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{ {
public AppQueriesGraphType(Builder builder, IEnumerable<SchemaInfo> schemaInfos) public AppQueriesGraphType(Builder builder, IEnumerable<SchemaInfo> schemaInfos)
{ {
AddField(builder.TypeFactory.FindAsset); AddField(builder.SharedTypes.FindAsset);
AddField(builder.TypeFactory.QueryAssets); AddField(builder.SharedTypes.QueryAssets);
AddField(builder.TypeFactory.QueryAssetsWithTotal); AddField(builder.SharedTypes.QueryAssetsWithTotal);
foreach (var schemaInfo in schemaInfos) foreach (var schemaInfo in schemaInfos)
{ {

22
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Builder.cs

@ -28,14 +28,14 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{ {
private readonly Dictionary<SchemaInfo, ContentGraphType> contentTypes = new Dictionary<SchemaInfo, ContentGraphType>(ReferenceEqualityComparer.Instance); private readonly Dictionary<SchemaInfo, ContentGraphType> contentTypes = new Dictionary<SchemaInfo, ContentGraphType>(ReferenceEqualityComparer.Instance);
private readonly Dictionary<SchemaInfo, ContentResultGraphType> contentResultTypes = new Dictionary<SchemaInfo, ContentResultGraphType>(ReferenceEqualityComparer.Instance); private readonly Dictionary<SchemaInfo, ContentResultGraphType> contentResultTypes = new Dictionary<SchemaInfo, ContentResultGraphType>(ReferenceEqualityComparer.Instance);
private readonly GraphQLTypeFactory typeFactory; private readonly SharedTypes sharedTypes;
private readonly GraphQLFieldVisitor fieldVisitor; private readonly FieldVisitor fieldVisitor;
private readonly GraphQLFieldInputVisitor fieldInputVisitor; private readonly FieldInputVisitor fieldInputVisitor;
private readonly PartitionResolver partitionResolver; private readonly PartitionResolver partitionResolver;
public GraphQLTypeFactory TypeFactory public SharedTypes SharedTypes
{ {
get { return typeFactory; } get { return sharedTypes; }
} }
static Builder() static Builder()
@ -48,14 +48,14 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
ValueConverter.Register<string, Status>(x => new Status(x)); ValueConverter.Register<string, Status>(x => new Status(x));
} }
public Builder(IAppEntity app, GraphQLTypeFactory typeFactory) public Builder(IAppEntity app, SharedTypes sharedTypes)
{ {
this.typeFactory = typeFactory; this.sharedTypes = sharedTypes;
partitionResolver = app.PartitionResolver(); partitionResolver = app.PartitionResolver();
fieldVisitor = new GraphQLFieldVisitor(this); fieldVisitor = new FieldVisitor(this);
fieldInputVisitor = new GraphQLFieldInputVisitor(this); fieldInputVisitor = new FieldInputVisitor(this);
} }
public GraphQLSchema BuildSchema(IEnumerable<ISchemaEntity> schemas) public GraphQLSchema BuildSchema(IEnumerable<ISchemaEntity> schemas)
@ -68,7 +68,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
foreach (var schemaInfo in schemaInfos) foreach (var schemaInfo in schemaInfos)
{ {
var contentType = new ContentGraphType(schemaInfo); var contentType = new ContentGraphType(this, schemaInfo);
contentTypes[schemaInfo] = contentType; contentTypes[schemaInfo] = contentType;
contentResultTypes[schemaInfo] = new ContentResultGraphType(contentType, schemaInfo); contentResultTypes[schemaInfo] = new ContentResultGraphType(contentType, schemaInfo);
@ -82,7 +82,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
newSchema.RegisterValueConverter(JsonConverter.Instance); newSchema.RegisterValueConverter(JsonConverter.Instance);
newSchema.RegisterValueConverter(InstantConverter.Instance); newSchema.RegisterValueConverter(InstantConverter.Instance);
newSchema.RegisterType(ContentInterfaceGraphType.Instance); newSchema.RegisterType(sharedTypes.ContentInterface);
if (schemas.Any()) if (schemas.Any())
{ {

20
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs

@ -17,7 +17,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
{ {
private readonly DomainId schemaId; private readonly DomainId schemaId;
public ContentGraphType(SchemaInfo schemaInfo) public ContentGraphType(Builder builder, SchemaInfo schemaInfo)
{ {
schemaId = schemaInfo.Schema.Id; schemaId = schemaInfo.Schema.Id;
@ -32,7 +32,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
AddField(ContentFields.Status); AddField(ContentFields.Status);
AddField(ContentFields.StatusColor); AddField(ContentFields.StatusColor);
AddResolvedInterface(ContentInterfaceGraphType.Instance); AddResolvedInterface(builder.SharedTypes.ContentInterface);
Description = $"The structure of a {schemaInfo.DisplayName} content type."; Description = $"The structure of a {schemaInfo.DisplayName} content type.";
@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
return value is IContentEntity content && content.SchemaId?.Id == schemaId; return value is IContentEntity content && content.SchemaId?.Id == schemaId;
} }
public void Initialize(Builder builder, SchemaInfo schemaInfo, IEnumerable<SchemaInfo> all) public void Initialize(Builder builder, SchemaInfo schemaInfo, IEnumerable<SchemaInfo> allSchemas)
{ {
AddField(new FieldType AddField(new FieldType
{ {
@ -80,7 +80,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
}); });
} }
foreach (var other in all.Where(x => References(x, schemaInfo))) foreach (var other in allSchemas.Where(IsReferencingThis))
{ {
AddReferencingQueries(builder, other); AddReferencingQueries(builder, other);
} }
@ -111,14 +111,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
}).WithSchemaId(referencingSchemaInfo); }).WithSchemaId(referencingSchemaInfo);
} }
private static bool References(SchemaInfo other, SchemaInfo schema) private bool IsReferencingThis(SchemaInfo other)
{ {
var id = schema.Schema.Id; return other.Schema.SchemaDef.Fields.Any(IsReferencingThis);
return other.Schema.SchemaDef.Fields.Any(x => References(x, id));
} }
private static bool References(IField field, DomainId id) private bool IsReferencingThis(IField field)
{ {
switch (field) switch (field)
{ {
@ -126,9 +124,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
return return
reference.Properties.SchemaIds == null || reference.Properties.SchemaIds == null ||
reference.Properties.SchemaIds.Count == 0 || reference.Properties.SchemaIds.Count == 0 ||
reference.Properties.SchemaIds.Contains(id); reference.Properties.SchemaIds.Contains(schemaId);
case IArrayField arrayField: case IArrayField arrayField:
return arrayField.Fields.Any(x => References(x, id)); return arrayField.Fields.Any(IsReferencingThis);
} }
return false; return false;

4
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentInterfaceGraphType.cs

@ -11,9 +11,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
{ {
internal sealed class ContentInterfaceGraphType : InterfaceGraphType<IEnrichedContentEntity> internal sealed class ContentInterfaceGraphType : InterfaceGraphType<IEnrichedContentEntity>
{ {
public static readonly IInterfaceGraphType Instance = new ContentInterfaceGraphType(); public ContentInterfaceGraphType()
private ContentInterfaceGraphType()
{ {
Name = "Content"; Name = "Content";

4
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/GraphQLFieldInputVisitor.cs → backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/FieldInputVisitor.cs

@ -11,11 +11,11 @@ using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{ {
internal sealed class GraphQLFieldInputVisitor : IFieldVisitor<IGraphType?, FieldInfo> internal sealed class FieldInputVisitor : IFieldVisitor<IGraphType?, FieldInfo>
{ {
private readonly Builder builder; private readonly Builder builder;
public GraphQLFieldInputVisitor(Builder builder) public FieldInputVisitor(Builder builder)
{ {
this.builder = builder; this.builder = builder;
} }

9
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/GraphQLFieldVisitor.cs → backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/FieldVisitor.cs

@ -11,14 +11,13 @@ using GraphQL;
using GraphQL.Resolvers; using GraphQL.Resolvers;
using GraphQL.Types; using GraphQL.Types;
using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents;
using Squidex.Infrastructure.Json.Objects; using Squidex.Infrastructure.Json.Objects;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
{ {
public delegate object ValueResolver(IJsonValue value, IResolveFieldContext fieldContext, GraphQLExecutionContext context); public delegate object ValueResolver(IJsonValue value, IResolveFieldContext fieldContext, GraphQLExecutionContext context);
internal sealed class GraphQLFieldVisitor : IFieldVisitor<(IGraphType?, IFieldResolver?, QueryArguments?), FieldInfo> internal sealed class FieldVisitor : IFieldVisitor<(IGraphType?, IFieldResolver?, QueryArguments?), FieldInfo>
{ {
private static readonly IFieldResolver Noop = CreateValueResolver((value, fieldContext, contex) => value); private static readonly IFieldResolver Noop = CreateValueResolver((value, fieldContext, contex) => value);
private static readonly IFieldResolver Json = CreateValueResolver(ContentActions.Json.Resolver); private static readonly IFieldResolver Json = CreateValueResolver(ContentActions.Json.Resolver);
@ -35,7 +34,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
private readonly Builder builder; private readonly Builder builder;
public GraphQLFieldVisitor(Builder builder) public FieldVisitor(Builder builder)
{ {
this.builder = builder; this.builder = builder;
} }
@ -52,7 +51,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<AssetsFieldProperties> field, FieldInfo args) public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<AssetsFieldProperties> field, FieldInfo args)
{ {
return (builder.TypeFactory.AssetsList, Assets, null); return (builder.SharedTypes.AssetsList, Assets, null);
} }
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<BooleanFieldProperties> field, FieldInfo args) public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<BooleanFieldProperties> field, FieldInfo args)

0
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/SchemaInfos.cs → backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/SchemaInfos.cs

13
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/GraphQLTypeFactory.cs → backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/SharedTypes.cs

@ -9,14 +9,16 @@ using System;
using GraphQL.Types; using GraphQL.Types;
using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Assets; using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Assets;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{ {
public class GraphQLTypeFactory public sealed class SharedTypes
{ {
private readonly Lazy<IGraphType> asset; private readonly Lazy<IGraphType> asset;
private readonly Lazy<IGraphType> assetsList; private readonly Lazy<IGraphType> assetsList;
private readonly Lazy<IGraphType> assetsResult; private readonly Lazy<IGraphType> assetsResult;
private readonly Lazy<IInterfaceGraphType> contentInterface;
private readonly Lazy<FieldType> findAsset; private readonly Lazy<FieldType> findAsset;
private readonly Lazy<FieldType> queryAssets; private readonly Lazy<FieldType> queryAssets;
private readonly Lazy<FieldType> queryAssetsWithTotal; private readonly Lazy<FieldType> queryAssetsWithTotal;
@ -27,13 +29,15 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
public IGraphType AssetsResult => assetsResult.Value; public IGraphType AssetsResult => assetsResult.Value;
public IInterfaceGraphType ContentInterface => contentInterface.Value;
public FieldType FindAsset => findAsset.Value; public FieldType FindAsset => findAsset.Value;
public FieldType QueryAssets => queryAssets.Value; public FieldType QueryAssets => queryAssets.Value;
public FieldType QueryAssetsWithTotal => queryAssetsWithTotal.Value; public FieldType QueryAssetsWithTotal => queryAssetsWithTotal.Value;
public GraphQLTypeFactory(IUrlGenerator urlGenerator) public SharedTypes(IUrlGenerator urlGenerator)
{ {
asset = new Lazy<IGraphType>(() => asset = new Lazy<IGraphType>(() =>
{ {
@ -50,6 +54,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
return new AssetsResultGraphType(AssetsList); return new AssetsResultGraphType(AssetsList);
}); });
contentInterface = new Lazy<IInterfaceGraphType>(() =>
{
return new ContentInterfaceGraphType();
});
findAsset = new Lazy<FieldType>(() => findAsset = new Lazy<FieldType>(() =>
{ {
return new FieldType return new FieldType

2
backend/src/Squidex/Config/Domain/QueryServices.cs

@ -30,7 +30,7 @@ namespace Squidex.Config.Domain
services.AddSingletonAs<DataLoaderDocumentListener>() services.AddSingletonAs<DataLoaderDocumentListener>()
.AsSelf(); .AsSelf();
services.AddSingletonAs<GraphQLTypeFactory>() services.AddSingletonAs<SharedTypes>()
.AsSelf(); .AsSelf();
services.AddSingletonAs<CachingGraphQLService>() services.AddSingletonAs<CachingGraphQLService>()

2
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs

@ -170,7 +170,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
[typeof(IUrlGenerator)] = urlGenerator, [typeof(IUrlGenerator)] = urlGenerator,
[typeof(ISemanticLog)] = A.Fake<ISemanticLog>(), [typeof(ISemanticLog)] = A.Fake<ISemanticLog>(),
[typeof(DataLoaderDocumentListener)] = new DataLoaderDocumentListener(dataLoaderContext), [typeof(DataLoaderDocumentListener)] = new DataLoaderDocumentListener(dataLoaderContext),
[typeof(GraphQLTypeFactory)] = new GraphQLTypeFactory(urlGenerator) [typeof(SharedTypes)] = new SharedTypes(urlGenerator)
}; };
} }

Loading…
Cancel
Save