mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
32 changed files with 1708 additions and 2015 deletions
@ -0,0 +1,70 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using GraphQL.Types; |
|||
using Squidex.Domain.Apps.Core.Contents; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Infrastructure.Json.Objects; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
|||
{ |
|||
internal sealed class ComponentGraphType : ObjectGraphType<JsonObject> |
|||
{ |
|||
public ComponentGraphType(Builder builder, SchemaInfo schemaInfo) |
|||
{ |
|||
Name = schemaInfo.ComponentType; |
|||
|
|||
Description = $"The structure of the {schemaInfo.DisplayName} component schema."; |
|||
|
|||
AddField(ContentFields.SchemaId); |
|||
AddResolvedInterface(builder.SharedTypes.ComponentInterface); |
|||
|
|||
IsTypeOf = CheckType(schemaInfo.Schema.Id.ToString()); |
|||
} |
|||
|
|||
public void Initialize(Builder builder, SchemaInfo schemaInfo) |
|||
{ |
|||
foreach (var fieldInfo in schemaInfo.Fields) |
|||
{ |
|||
if (fieldInfo.Field.IsComponentLike()) |
|||
{ |
|||
AddField(new FieldType |
|||
{ |
|||
Name = fieldInfo.FieldNameDynamic, |
|||
Arguments = ContentActions.Json.Arguments, |
|||
ResolvedType = AllTypes.Json, |
|||
Resolver = FieldVisitor.JsonPath, |
|||
Description = fieldInfo.Field.RawProperties.Hints |
|||
}).WithSourceName(fieldInfo); |
|||
} |
|||
|
|||
var (resolvedType, resolver, args) = builder.GetGraphType(fieldInfo); |
|||
|
|||
if (resolvedType != null && resolver != null) |
|||
{ |
|||
AddField(new FieldType |
|||
{ |
|||
Name = fieldInfo.FieldName, |
|||
Arguments = args, |
|||
ResolvedType = resolvedType, |
|||
Resolver = resolver, |
|||
Description = fieldInfo.Field.RawProperties.Hints |
|||
}).WithSourceName(fieldInfo); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private static Func<object, bool> CheckType(string schemaId) |
|||
{ |
|||
return value => |
|||
{ |
|||
return Component.IsValid(value as IJsonValue, out var discrimiator) && discrimiator == schemaId.ToString(); |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL.Types; |
|||
using Squidex.Infrastructure.Json.Objects; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
|||
{ |
|||
internal sealed class ComponentInterfaceGraphType : InterfaceGraphType<JsonObject> |
|||
{ |
|||
public ComponentInterfaceGraphType() |
|||
{ |
|||
Name = "Component"; |
|||
|
|||
AddField(ContentFields.SchemaId); |
|||
|
|||
Description = "The structure of all content types."; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using GraphQL.Types; |
|||
using Squidex.Domain.Apps.Core.Contents; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Collections; |
|||
using Squidex.Infrastructure.Json.Objects; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
|||
{ |
|||
internal sealed class ComponentUnionGraphType : UnionGraphType |
|||
{ |
|||
private readonly Dictionary<string, IObjectGraphType> types = new Dictionary<string, IObjectGraphType>(); |
|||
|
|||
public bool HasType => types.Count > 0; |
|||
|
|||
public ComponentUnionGraphType(Builder builder, FieldInfo fieldInfo, ImmutableList<DomainId>? schemaIds) |
|||
{ |
|||
Name = fieldInfo.ReferenceType; |
|||
|
|||
if (schemaIds?.Any() == true) |
|||
{ |
|||
foreach (var schemaId in schemaIds) |
|||
{ |
|||
var contentType = builder.GetComponentType(schemaId); |
|||
|
|||
if (contentType != null) |
|||
{ |
|||
types[schemaId.ToString()] = contentType; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (HasType) |
|||
{ |
|||
foreach (var type in types) |
|||
{ |
|||
AddPossibleType(type.Value); |
|||
} |
|||
|
|||
ResolveType = value => |
|||
{ |
|||
if (value is JsonObject component && component.TryGetValue<JsonString>(Component.Discriminator, out var schemaId)) |
|||
{ |
|||
return types.GetOrDefault(schemaId.Value); |
|||
} |
|||
|
|||
return null; |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Domain.Apps.Entities.Apps; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|||
{ |
|||
public static class TestApp |
|||
{ |
|||
public static readonly NamedId<DomainId> DefaultId = NamedId.Of(DomainId.NewGuid(), "my-app"); |
|||
|
|||
public static readonly IAppEntity Default; |
|||
|
|||
static TestApp() |
|||
{ |
|||
Default = Mocks.App(DefaultId, Language.DE, Language.GermanGermany); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Domain.Apps.Core; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Domain.Apps.Entities.Schemas; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Collections; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|||
{ |
|||
public static class TestSchemas |
|||
{ |
|||
public static readonly NamedId<DomainId> DefaultId = NamedId.Of(DomainId.NewGuid(), "my-schema"); |
|||
public static readonly NamedId<DomainId> Ref1Id = NamedId.Of(DomainId.NewGuid(), "my-ref-schema1"); |
|||
public static readonly NamedId<DomainId> Ref2Id = NamedId.Of(DomainId.NewGuid(), "my-ref-schema2"); |
|||
|
|||
public static readonly ISchemaEntity Default; |
|||
public static readonly ISchemaEntity Ref1; |
|||
public static readonly ISchemaEntity Ref2; |
|||
|
|||
static TestSchemas() |
|||
{ |
|||
Ref1 = Mocks.Schema(TestApp.DefaultId, Ref1Id, |
|||
new Schema(Ref1Id.Name) |
|||
.Publish() |
|||
.AddString(1, "schemaRef1Field", Partitioning.Invariant)); |
|||
|
|||
Ref2 = Mocks.Schema(TestApp.DefaultId, Ref2Id, |
|||
new Schema(Ref2Id.Name) |
|||
.Publish() |
|||
.AddString(1, "schemaRef2Field", Partitioning.Invariant)); |
|||
|
|||
Default = Mocks.Schema(TestApp.DefaultId, DefaultId, |
|||
new Schema(DefaultId.Name) |
|||
.Publish() |
|||
.AddJson(1, "my-json", Partitioning.Invariant, |
|||
new JsonFieldProperties()) |
|||
.AddString(2, "my-string", Partitioning.Invariant, |
|||
new StringFieldProperties()) |
|||
.AddString(3, "my-localized-string", Partitioning.Language, |
|||
new StringFieldProperties()) |
|||
.AddNumber(4, "my-number", Partitioning.Invariant, |
|||
new NumberFieldProperties()) |
|||
.AddAssets(5, "my-assets", Partitioning.Invariant, |
|||
new AssetsFieldProperties()) |
|||
.AddBoolean(6, "my-boolean", Partitioning.Invariant, |
|||
new BooleanFieldProperties()) |
|||
.AddDateTime(7, "my-datetime", Partitioning.Invariant, |
|||
new DateTimeFieldProperties()) |
|||
.AddReferences(8, "my-references", Partitioning.Invariant, |
|||
new ReferencesFieldProperties { SchemaId = Ref1Id.Id }) |
|||
.AddReferences(9, "my-union", Partitioning.Invariant, |
|||
new ReferencesFieldProperties()) |
|||
.AddGeolocation(10, "my-geolocation", Partitioning.Invariant, |
|||
new GeolocationFieldProperties()) |
|||
.AddComponent(11, "my-component", Partitioning.Invariant, |
|||
new ComponentFieldProperties { SchemaId = Ref1Id.Id }) |
|||
.AddComponents(12, "my-components", Partitioning.Invariant, |
|||
new ComponentsFieldProperties { SchemaIds = ImmutableList.Create(Ref1.Id, Ref2.Id) }) |
|||
.AddTags(13, "my-tags", Partitioning.Invariant, |
|||
new TagsFieldProperties()) |
|||
.AddArray(100, "my-array", Partitioning.Invariant, f => f |
|||
.AddBoolean(121, "nested-boolean", |
|||
new BooleanFieldProperties()) |
|||
.AddNumber(122, "nested-number", |
|||
new NumberFieldProperties())) |
|||
.SetScripts(new SchemaScripts { Query = "<query-script>" })); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue