Browse Source

Test

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
f472fe0182
  1. 2
      src/Squidex.Domain.Apps.Core/Schemas/Field.cs
  2. 22
      src/Squidex.Domain.Apps.Core/Schemas/IGraphQLResolver.cs
  3. 1
      src/Squidex.Domain.Apps.Core/Squidex.Domain.Apps.Core.csproj
  4. 15
      src/Squidex.Domain.Apps.Read/GraphQl/IGraphQLResolver.cs
  5. 99
      src/Squidex.Domain.Apps.Read/GraphQl/SchemaGraphType.cs
  6. 1
      src/Squidex.Domain.Apps.Read/Squidex.Domain.Apps.Read.csproj

2
src/Squidex.Domain.Apps.Core/Schemas/Field.cs

@ -79,6 +79,8 @@ namespace Squidex.Domain.Apps.Core.Schemas
public abstract object ConvertValue(JToken value); public abstract object ConvertValue(JToken value);
public abstract IGraph
public Field Hide() public Field Hide()
{ {
return Clone<Field>(clone => clone.isHidden = true); return Clone<Field>(clone => clone.isHidden = true);

22
src/Squidex.Domain.Apps.Core/Schemas/IGraphQLResolver.cs

@ -0,0 +1,22 @@
// ==========================================================================
// IGraphQLResolver.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using GraphQL.Types;
namespace Squidex.Domain.Apps.Core.Schemas
{
public interface IGraphQLResolver
{
IGraphType GetSchemaListType(Schema schema);
IGraphType GetSchemaListType(Guid schemaId);
IGraphType GetAssetListType();
}
}

1
src/Squidex.Domain.Apps.Core/Squidex.Domain.Apps.Core.csproj

@ -10,6 +10,7 @@
<ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" /> <ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphQL" Version="0.16.1" />
<PackageReference Include="Microsoft.OData.Core" Version="7.2.0" /> <PackageReference Include="Microsoft.OData.Core" Version="7.2.0" />
<PackageReference Include="NJsonSchema" Version="9.2.5" /> <PackageReference Include="NJsonSchema" Version="9.2.5" />
<PackageReference Include="NodaTime" Version="2.0.3" /> <PackageReference Include="NodaTime" Version="2.0.3" />

15
src/Squidex.Domain.Apps.Read/GraphQl/IGraphQLResolver.cs

@ -0,0 +1,15 @@
using System;
using GraphQL.Types;
using Schema = Squidex.Domain.Apps.Core.Schemas.Schema;
namespace Squidex.Domain.Apps.Read.GraphQl
{
public interface IGraphQLResolver
{
IGraphType GetSchemaListType(Schema schema);
IGraphType GetSchemaListType(Guid schemaId);
IGraphType GetAssetListType();
}
}

99
src/Squidex.Domain.Apps.Read/GraphQl/SchemaGraphType.cs

@ -0,0 +1,99 @@
// ==========================================================================
// SchemaGraphType.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using GraphQL.Resolvers;
using GraphQL.Types;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Read.Contents;
using Squidex.Infrastructure;
using Schema = Squidex.Domain.Apps.Core.Schemas.Schema;
namespace Squidex.Domain.Apps.Read.GraphQl
{
public interface IGraphQLContext : IGraphQLResolver
{
IFieldPartitioning ResolvePartition(Partitioning key);
}
public sealed class ContentGraphType : ObjectGraphType<IContentEntity>
{
private static readonly IFieldResolver DataResolver =
new FuncFieldResolver<IContentEntity, NamedContentData>(c => c.Source.Data);
public ContentGraphType(Schema schema, IGraphQLContext context)
{
var schemaName = schema.Properties.Label.WithFallback(schema.Name);
Field("id", x => x.Id)
.Description($"The id of the {schemaName} content.");
Field("version", x => x.Version)
.Description($"The version of the {schemaName} content.");
Field("created", x => x.Created)
.Description($"The date and time when the {schemaName} content has been created.");
Field("createdBy", x => x.CreatedBy.ToString())
.Description($"The user that has created the {schemaName} content.");
Field("lastModified", x => x.LastModified.ToString())
.Description($"The date and time when the {schemaName} content has been modified last.");
Field("lastModified", x => x.LastModified.ToString())
.Description($"The user that has updated the {schemaName} content last.");
AddField(new FieldType
{
Name = "data",
Resolver = DataResolver,
ResolvedType = new SchemaDataGraphType(schema, context),
Description = $"The version of the {schemaName} content."
});
}
}
public sealed class SchemaDataGraphType : ObjectGraphType<NamedContentData>
{
private static readonly IFieldResolver FieldResolver =
new FuncFieldResolver<NamedContentData, ContentFieldData>(c => c.Source.GetOrDefault(c.FieldName));
public SchemaDataGraphType(Schema schema, IGraphQLContext context)
{
foreach (var field in schema.Fields)
{
var fieldName = field.Name;
AddField(new FieldType
{
Name = fieldName,
Resolver = FieldResolver,
ResolvedType = new SchemaFieldGraphType(field, context),
});
}
}
}
public sealed class SchemaFieldGraphType : ObjectGraphType<ContentFieldData>
{
public SchemaFieldGraphType(Field field, IGraphQLContext context)
{
var partition = context.ResolvePartition(field.Paritioning);
foreach (var partitionItem in partition)
{
AddField(new FieldType
{
Name = partitionItem.Key,
Resolver = new FuncFieldResolver<object>()
}
}
}
}
}

1
src/Squidex.Domain.Apps.Read/Squidex.Domain.Apps.Read.csproj

@ -13,6 +13,7 @@
<ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" /> <ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphQL" Version="0.16.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" />
<PackageReference Include="NodaTime" Version="2.0.3" /> <PackageReference Include="NodaTime" Version="2.0.3" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.7.0" /> <PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.7.0" />

Loading…
Cancel
Save