Browse Source

Minor fixes

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
9ac555a559
  1. 14
      Squidex.sln
  2. 16
      src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository.cs
  3. 16
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/CachingGraphQLInvoker.cs
  4. 8
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/GraphQLModel.cs
  5. 2
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/IGraphQLInvoker.cs
  6. 18
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/QueryContext.cs
  7. 37
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/GeolocationScalarType.cs
  8. 37
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/JsonScalarType.cs
  9. 6
      src/Squidex.Domain.Apps.Read/Contents/Repositories/IContentRepository.cs
  10. 2
      src/Squidex.Domain.Apps.Read/Squidex.Domain.Apps.Read.csproj
  11. 4
      src/Squidex/app/features/api/api-area.component.html
  12. 8
      src/Squidex/app/features/dashboard/pages/dashboard-page.component.html

14
Squidex.sln

@ -56,6 +56,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Domain.Users.MongoD
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Domain.Users.Tests", "tests\Squidex.Domain.Users.Tests\Squidex.Domain.Users.Tests.csproj", "{42184546-E3CB-4D4F-9495-43979B9C63B9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Domain.Users.Tests", "tests\Squidex.Domain.Users.Tests\Squidex.Domain.Users.Tests.csproj", "{42184546-E3CB-4D4F-9495-43979B9C63B9}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL", "C:\Users\mail2\Downloads\graphql-dotnet\src\GraphQL\GraphQL.csproj", "{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -266,6 +268,18 @@ Global
{42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x64.Build.0 = Release|Any CPU {42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x64.Build.0 = Release|Any CPU
{42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.ActiveCfg = Release|Any CPU {42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.ActiveCfg = Release|Any CPU
{42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.Build.0 = Release|Any CPU {42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.Build.0 = Release|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Debug|x64.ActiveCfg = Debug|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Debug|x64.Build.0 = Debug|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Debug|x86.ActiveCfg = Debug|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Debug|x86.Build.0 = Debug|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Release|Any CPU.Build.0 = Release|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Release|x64.ActiveCfg = Release|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Release|x64.Build.0 = Release|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Release|x86.ActiveCfg = Release|Any CPU
{A28051B9-C4A7-4B3D-9426-CD3A1342F4FA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

16
src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository.cs

@ -75,16 +75,16 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents
this.modelBuilder = modelBuilder; this.modelBuilder = modelBuilder;
} }
public async Task<IReadOnlyList<IContentEntity>> QueryAsync(IAppEntity appEntity, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery) public async Task<IReadOnlyList<IContentEntity>> QueryAsync(IAppEntity app, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery)
{ {
var contentEntities = (List<IContentEntity>)null; var contentEntities = (List<IContentEntity>)null;
await ForSchemaAsync(appEntity.Id, schemaId, async (collection, schemaEntity) => await ForSchemaAsync(app.Id, schemaId, async (collection, schemaEntity) =>
{ {
IFindFluent<MongoContentEntity, MongoContentEntity> cursor; IFindFluent<MongoContentEntity, MongoContentEntity> cursor;
try try
{ {
var model = modelBuilder.BuildEdmModel(schemaEntity, appEntity); var model = modelBuilder.BuildEdmModel(schemaEntity, app);
var parser = model.ParseQuery(odataQuery); var parser = model.ParseQuery(odataQuery);
@ -121,16 +121,16 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents
return contentEntities; return contentEntities;
} }
public async Task<long> CountAsync(IAppEntity appEntity, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery) public async Task<long> CountAsync(IAppEntity app, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery)
{ {
var contentsCount = 0L; var contentsCount = 0L;
await ForSchemaAsync(appEntity.Id, schemaId, async (collection, schemaEntity) => await ForSchemaAsync(app.Id, schemaId, async (collection, schemaEntity) =>
{ {
IFindFluent<MongoContentEntity, MongoContentEntity> cursor; IFindFluent<MongoContentEntity, MongoContentEntity> cursor;
try try
{ {
var model = modelBuilder.BuildEdmModel(schemaEntity, appEntity); var model = modelBuilder.BuildEdmModel(schemaEntity, app);
var parser = model.ParseQuery(odataQuery); var parser = model.ParseQuery(odataQuery);
@ -169,11 +169,11 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents
return contentIds.Except(contentEntities.Select(x => Guid.Parse(x["_id"].AsString))).ToList(); return contentIds.Except(contentEntities.Select(x => Guid.Parse(x["_id"].AsString))).ToList();
} }
public async Task<IContentEntity> FindContentAsync(IAppEntity appEntity, Guid schemaId, Guid id) public async Task<IContentEntity> FindContentAsync(IAppEntity app, Guid schemaId, Guid id)
{ {
var contentEntity = (MongoContentEntity)null; var contentEntity = (MongoContentEntity)null;
await ForSchemaAsync(appEntity.Id, schemaId, async (collection, schemaEntity) => await ForSchemaAsync(app.Id, schemaId, async (collection, schemaEntity) =>
{ {
contentEntity = contentEntity =
await collection.Find(x => x.Id == id) await collection.Find(x => x.Id == id)

16
src/Squidex.Domain.Apps.Read/Contents/GraphQL/CachingGraphQLInvoker.cs

@ -67,28 +67,28 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
return TaskHelper.Done; return TaskHelper.Done;
} }
public async Task<object> QueryAsync(IAppEntity appEntity, GraphQLQuery query) public async Task<object> QueryAsync(IAppEntity app, GraphQLQuery query)
{ {
Guard.NotNull(appEntity, nameof(appEntity)); Guard.NotNull(app, nameof(app));
Guard.NotNull(query, nameof(query)); Guard.NotNull(query, nameof(query));
var modelContext = await GetModelAsync(appEntity); var modelContext = await GetModelAsync(app);
var queryContext = new QueryContext(appEntity, contentRepository, assetRepository); var queryContext = new QueryContext(app, contentRepository, assetRepository);
return await modelContext.ExecuteAsync(queryContext, query); return await modelContext.ExecuteAsync(queryContext, query);
} }
private async Task<GraphQLModel> GetModelAsync(IAppEntity appEntity) private async Task<GraphQLModel> GetModelAsync(IAppEntity app)
{ {
var cacheKey = CreateCacheKey(appEntity.Id); var cacheKey = CreateCacheKey(app.Id);
var modelContext = Cache.Get<GraphQLModel>(cacheKey); var modelContext = Cache.Get<GraphQLModel>(cacheKey);
if (modelContext == null) if (modelContext == null)
{ {
var schemas = await schemaRepository.QueryAllAsync(appEntity.Id); var schemas = await schemaRepository.QueryAllAsync(app.Id);
modelContext = new GraphQLModel(appEntity, schemas.Where(x => x.IsPublished)); modelContext = new GraphQLModel(app, schemas.Where(x => x.IsPublished));
Cache.Set(cacheKey, modelContext); Cache.Set(cacheKey, modelContext);
} }

8
src/Squidex.Domain.Apps.Read/Contents/GraphQL/GraphQLModel.cs

@ -36,9 +36,9 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
private readonly IGraphType assetType = new AssetGraphType(); private readonly IGraphType assetType = new AssetGraphType();
private readonly GraphQLSchema graphQLSchema; private readonly GraphQLSchema graphQLSchema;
public GraphQLModel(IAppEntity appEntity, IEnumerable<ISchemaEntity> schemas) public GraphQLModel(IAppEntity app, IEnumerable<ISchemaEntity> schemas)
{ {
partitionResolver = appEntity.PartitionResolver; partitionResolver = app.PartitionResolver;
var defaultResolver = var defaultResolver =
new FuncFieldResolver<ContentFieldData, object>(c => c.Source.GetOrDefault(c.FieldName)); new FuncFieldResolver<ContentFieldData, object>(c => c.Source.GetOrDefault(c.FieldName));
@ -58,10 +58,10 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
(new DateGraphType(), defaultResolver); (new DateGraphType(), defaultResolver);
var jsonInfos = var jsonInfos =
(new ObjectGraphType(), defaultResolver); (new JsonScalarType(), defaultResolver);
var geolocationInfos = var geolocationInfos =
(new ObjectGraphType(), defaultResolver); (new GeolocationScalarType(), defaultResolver);
fieldInfos = new Dictionary<Type, Func<Field, (IGraphType ResolveType, IFieldResolver Resolver)>> fieldInfos = new Dictionary<Type, Func<Field, (IGraphType ResolveType, IFieldResolver Resolver)>>
{ {

2
src/Squidex.Domain.Apps.Read/Contents/GraphQL/IGraphQLInvoker.cs

@ -13,6 +13,6 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
{ {
public interface IGraphQLInvoker public interface IGraphQLInvoker
{ {
Task<object> QueryAsync(IAppEntity appEntity, GraphQLQuery query); Task<object> QueryAsync(IAppEntity app, GraphQLQuery query);
} }
} }

18
src/Squidex.Domain.Apps.Read/Contents/GraphQL/QueryContext.cs

@ -28,18 +28,18 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
private readonly ConcurrentDictionary<Guid, IAssetEntity> cachedAssets = new ConcurrentDictionary<Guid, IAssetEntity>(); private readonly ConcurrentDictionary<Guid, IAssetEntity> cachedAssets = new ConcurrentDictionary<Guid, IAssetEntity>();
private readonly IContentRepository contentRepository; private readonly IContentRepository contentRepository;
private readonly IAssetRepository assetRepository; private readonly IAssetRepository assetRepository;
private readonly IAppEntity appEntity; private readonly IAppEntity app;
public QueryContext(IAppEntity appEntity, IContentRepository contentRepository, IAssetRepository assetRepository) public QueryContext(IAppEntity app, IContentRepository contentRepository, IAssetRepository assetRepository)
{ {
Guard.NotNull(contentRepository, nameof(contentRepository)); Guard.NotNull(contentRepository, nameof(contentRepository));
Guard.NotNull(assetRepository, nameof(assetRepository)); Guard.NotNull(assetRepository, nameof(assetRepository));
Guard.NotNull(appEntity, nameof(appEntity)); Guard.NotNull(app, nameof(app));
this.contentRepository = contentRepository; this.contentRepository = contentRepository;
this.assetRepository = assetRepository; this.assetRepository = assetRepository;
this.appEntity = appEntity; this.app = app;
} }
public async Task<IAssetEntity> FindAssetAsync(Guid id) public async Task<IAssetEntity> FindAssetAsync(Guid id)
@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
if (content == null) if (content == null)
{ {
content = await contentRepository.FindContentAsync(appEntity, schemaId, id); content = await contentRepository.FindContentAsync(app, schemaId, id);
if (content != null) if (content != null)
{ {
@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
public async Task<IReadOnlyList<IAssetEntity>> QueryAssetsAsync(string query, int skip = 0, int take = 10) public async Task<IReadOnlyList<IAssetEntity>> QueryAssetsAsync(string query, int skip = 0, int take = 10)
{ {
var assets = await assetRepository.QueryAsync(appEntity.Id, null, null, query, take, skip); var assets = await assetRepository.QueryAsync(app.Id, null, null, query, take, skip);
foreach (var asset in assets) foreach (var asset in assets)
{ {
@ -90,7 +90,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
public async Task<IReadOnlyList<IContentEntity>> QueryContentsAsync(Guid schemaId, string query) public async Task<IReadOnlyList<IContentEntity>> QueryContentsAsync(Guid schemaId, string query)
{ {
var contents = await contentRepository.QueryAsync(appEntity, schemaId, false, null, query); var contents = await contentRepository.QueryAsync(app, schemaId, false, null, query);
foreach (var content in contents) foreach (var content in contents)
{ {
@ -117,7 +117,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
{ {
Task.Run(async () => Task.Run(async () =>
{ {
var assets = await assetRepository.QueryAsync(appEntity.Id, null, notLoadedAssets, string.Empty, int.MaxValue).ConfigureAwait(false); var assets = await assetRepository.QueryAsync(app.Id, null, notLoadedAssets, string.Empty, int.MaxValue).ConfigureAwait(false);
foreach (var asset in assets) foreach (var asset in assets)
{ {
@ -146,7 +146,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
{ {
Task.Run(async () => Task.Run(async () =>
{ {
var contents = await contentRepository.QueryAsync(appEntity, schemaId, false, notLoadedContents, string.Empty).ConfigureAwait(false); var contents = await contentRepository.QueryAsync(app, schemaId, false, notLoadedContents, string.Empty).ConfigureAwait(false);
foreach (var content in contents) foreach (var content in contents)
{ {

37
src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/GeolocationScalarType.cs

@ -0,0 +1,37 @@
// ==========================================================================
// GeolocationScalarType.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using GraphQL.Language.AST;
using GraphQL.Types;
using Newtonsoft.Json.Linq;
namespace Squidex.Domain.Apps.Read.Contents.GraphQL.Types
{
public sealed class GeolocationScalarType : ScalarGraphType
{
public GeolocationScalarType()
{
Name = "Json";
}
public override object Serialize(object value)
{
return value;
}
public override object ParseValue(object value)
{
return value != null ? value is JObject ? value : JObject.FromObject(value) : null;
}
public override object ParseLiteral(IValue value)
{
return null;
}
}
}

37
src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/JsonScalarType.cs

@ -0,0 +1,37 @@
// ==========================================================================
// JsonScalarType.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using GraphQL.Language.AST;
using GraphQL.Types;
using Newtonsoft.Json.Linq;
namespace Squidex.Domain.Apps.Read.Contents.GraphQL.Types
{
public sealed class JsonScalarType : ScalarGraphType
{
public JsonScalarType()
{
Name = "Json";
}
public override object Serialize(object value)
{
return value;
}
public override object ParseValue(object value)
{
return value != null ? value is JObject ? value : JObject.FromObject(value) : null;
}
public override object ParseLiteral(IValue value)
{
return null;
}
}
}

6
src/Squidex.Domain.Apps.Read/Contents/Repositories/IContentRepository.cs

@ -15,12 +15,12 @@ namespace Squidex.Domain.Apps.Read.Contents.Repositories
{ {
public interface IContentRepository public interface IContentRepository
{ {
Task<IReadOnlyList<IContentEntity>> QueryAsync(IAppEntity appEntity, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery); Task<IReadOnlyList<IContentEntity>> QueryAsync(IAppEntity app, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery);
Task<IReadOnlyList<Guid>> QueryNotFoundAsync(Guid appId, Guid schemaId, IList<Guid> contentIds); Task<IReadOnlyList<Guid>> QueryNotFoundAsync(Guid appId, Guid schemaId, IList<Guid> contentIds);
Task<long> CountAsync(IAppEntity appEntity, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery); Task<long> CountAsync(IAppEntity app, Guid schemaId, bool nonPublished, HashSet<Guid> ids, string odataQuery);
Task<IContentEntity> FindContentAsync(IAppEntity appEntity, Guid schemaId, Guid id); Task<IContentEntity> FindContentAsync(IAppEntity app, Guid schemaId, Guid id);
} }
} }

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

@ -11,9 +11,9 @@
<ProjectReference Include="..\Squidex.Domain.Apps.Core\Squidex.Domain.Apps.Core.csproj" /> <ProjectReference Include="..\Squidex.Domain.Apps.Core\Squidex.Domain.Apps.Core.csproj" />
<ProjectReference Include="..\Squidex.Domain.Apps.Events\Squidex.Domain.Apps.Events.csproj" /> <ProjectReference Include="..\Squidex.Domain.Apps.Events\Squidex.Domain.Apps.Events.csproj" />
<ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" /> <ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" />
<ProjectReference Include="C:\Users\mail2\Downloads\graphql-dotnet\src\GraphQL\GraphQL.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" />

4
src/Squidex/app/features/api/api-area.component.html

@ -21,8 +21,8 @@
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link"> <a class="nav-link" href="/api/content/{{appName() | async}}/docs" target="_blank">
REST Swagger
</a> </a>
</li> </li>
</ul> </ul>

8
src/Squidex/app/features/dashboard/pages/dashboard-page.component.html

@ -26,7 +26,7 @@
</div> </div>
</a> </a>
<a class="card card-href" href="/api/content/{{appName() | async}}/docs" target="_blank"> <a class="card card-href" href="/api/docs" target="_blank">
<div class="card-block"> <div class="card-block">
<div class="card-image"> <div class="card-image">
<img src="/images/dashboard-api.png" /> <img src="/images/dashboard-api.png" />
@ -35,11 +35,7 @@
<h4 class="card-title">API Documentation</h4> <h4 class="card-title">API Documentation</h4>
<div class="card-text"> <div class="card-text">
Swagger compatible documentation for your schemas. Swagger compatible documentation for app management.
</div>
<div class="card-more">
Read More: <a href="/api/docs" target="_blank">Management API</a>
</div> </div>
</div> </div>
</a> </a>

Loading…
Cancel
Save