mirror of https://github.com/Squidex/squidex.git
21 changed files with 568 additions and 92 deletions
@ -0,0 +1,84 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL.Types; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
|||
{ |
|||
public sealed class ContentInterfaceGraphType : InterfaceGraphType |
|||
{ |
|||
public ContentInterfaceGraphType() |
|||
{ |
|||
Name = $"ContentInfaceDto"; |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "id", |
|||
ResolvedType = AllTypes.NonNullGuid, |
|||
Description = $"The id of the content." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "version", |
|||
ResolvedType = AllTypes.NonNullInt, |
|||
Description = $"The version of the content." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "created", |
|||
ResolvedType = AllTypes.NonNullDate, |
|||
Description = $"The date and time when the content has been created." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "createdBy", |
|||
ResolvedType = AllTypes.NonNullString, |
|||
Description = $"The user that has created the content." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "lastModified", |
|||
ResolvedType = AllTypes.NonNullDate, |
|||
Description = $"The date and time when the content has been modified last." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "lastModifiedBy", |
|||
ResolvedType = AllTypes.NonNullString, |
|||
Description = $"The user that has updated the content last." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "status", |
|||
ResolvedType = AllTypes.NonNullString, |
|||
Description = $"The the status of the content." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "statusColor", |
|||
ResolvedType = AllTypes.NonNullString, |
|||
Description = $"The color status of the content." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "url", |
|||
ResolvedType = AllTypes.NonNullString, |
|||
Description = $"The url to the the content." |
|||
}); |
|||
|
|||
Description = $"The structure of all content types."; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using GraphQL.Types; |
|||
using Squidex.Domain.Apps.Entities.Schemas; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
|||
{ |
|||
public sealed class ReferenceGraphType : UnionGraphType |
|||
{ |
|||
private readonly Dictionary<Guid, IObjectGraphType> types = new Dictionary<Guid, IObjectGraphType>(); |
|||
|
|||
public ReferenceGraphType(string fieldName, IDictionary<ISchemaEntity, ContentGraphType> schemaTypes, IEnumerable<Guid> schemaIds, Func<Guid, IObjectGraphType> schemaResolver) |
|||
{ |
|||
Name = $"{fieldName}ReferenceUnionDto"; |
|||
|
|||
if (schemaIds?.Any() == true) |
|||
{ |
|||
foreach (var schemaId in schemaIds) |
|||
{ |
|||
var schemaType = schemaResolver(schemaId); |
|||
|
|||
if (schemaType != null) |
|||
{ |
|||
types[schemaId] = schemaType; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
foreach (var schemaType in schemaTypes) |
|||
{ |
|||
types[schemaType.Key.Id] = schemaType.Value; |
|||
} |
|||
} |
|||
|
|||
foreach (var type in types) |
|||
{ |
|||
AddPossibleType(type.Value); |
|||
} |
|||
|
|||
ResolveType = value => |
|||
{ |
|||
if (value is IContentEntity content) |
|||
{ |
|||
return types.GetOrDefault(content.Id); |
|||
} |
|||
|
|||
return null; |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue