Browse Source

Some restructuring

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
29734a3954
  1. 2
      src/Squidex.Domain.Apps.Core/Schemas/Field.cs
  2. 1
      src/Squidex.Domain.Apps.Core/Squidex.Domain.Apps.Core.csproj
  3. 37
      src/Squidex.Domain.Apps.Read/GraphQl/ContentDataGraphType.cs
  4. 36
      src/Squidex.Domain.Apps.Read/GraphQl/ContentFieldGraphType.cs
  5. 45
      src/Squidex.Domain.Apps.Read/GraphQl/ContentGraphType.cs
  6. 94
      src/Squidex.Domain.Apps.Read/GraphQl/GraphQLContext.cs
  7. 17
      src/Squidex.Domain.Apps.Read/GraphQl/IGraphQLContext.cs
  8. 15
      src/Squidex.Domain.Apps.Read/GraphQl/IGraphQLResolver.cs

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

@ -79,8 +79,6 @@ 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);

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

@ -10,7 +10,6 @@
<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" />

37
src/Squidex.Domain.Apps.Read/GraphQl/ContentDataGraphType.cs

@ -0,0 +1,37 @@
// ==========================================================================
// SchemaGraphType.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using GraphQL.Resolvers;
using GraphQL.Types;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Infrastructure;
using Schema = Squidex.Domain.Apps.Core.Schemas.Schema;
namespace Squidex.Domain.Apps.Read.GraphQl
{
public sealed class ContentDataGraphType : ObjectGraphType<NamedContentData>
{
private static readonly IFieldResolver FieldResolver =
new FuncFieldResolver<NamedContentData, ContentFieldData>(c => c.Source.GetOrDefault(c.FieldName));
public ContentDataGraphType(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),
});
}
}
}
}

36
src/Squidex.Domain.Apps.Read/GraphQl/ContentFieldGraphType.cs

@ -0,0 +1,36 @@
// ==========================================================================
// SchemaGraphType.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using GraphQL.Types;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Core.Schemas;
namespace Squidex.Domain.Apps.Read.GraphQl
{
public sealed class ContentFieldGraphType : ObjectGraphType<ContentFieldData>
{
public ContentFieldGraphType(Field field, IGraphQLContext context)
{
var partition = context.ResolvePartition(field.Paritioning);
foreach (var partitionItem in partition)
{
var fieldInfo = context.GetGraphType(field);
AddField(new FieldType
{
Name = partitionItem.Key,
Resolver = fieldInfo.Resolver,
ResolvedType = fieldInfo.ResolveType,
Description = field.RawProperties.Hints
});
}
}
}
}

45
src/Squidex.Domain.Apps.Read/GraphQl/SchemaGraphType.cs → src/Squidex.Domain.Apps.Read/GraphQl/ContentGraphType.cs

@ -8,20 +8,13 @@
using GraphQL.Resolvers; using GraphQL.Resolvers;
using GraphQL.Types; using GraphQL.Types;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Read.Contents; using Squidex.Domain.Apps.Read.Contents;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Schema = Squidex.Domain.Apps.Core.Schemas.Schema; using Schema = Squidex.Domain.Apps.Core.Schemas.Schema;
namespace Squidex.Domain.Apps.Read.GraphQl namespace Squidex.Domain.Apps.Read.GraphQl
{ {
public interface IGraphQLContext : IGraphQLResolver
{
IFieldPartitioning ResolvePartition(Partitioning key);
}
public sealed class ContentGraphType : ObjectGraphType<IContentEntity> public sealed class ContentGraphType : ObjectGraphType<IContentEntity>
{ {
private static readonly IFieldResolver DataResolver = private static readonly IFieldResolver DataResolver =
@ -58,42 +51,4 @@ namespace Squidex.Domain.Apps.Read.GraphQl
}); });
} }
} }
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>()
}
}
}
}
} }

94
src/Squidex.Domain.Apps.Read/GraphQl/GraphQLContext.cs

@ -0,0 +1,94 @@
// ==========================================================================
// GraphQLContext.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
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 sealed class GraphQLContext : IGraphQLContext
{
private readonly PartitionResolver partitionResolver;
private readonly Dictionary<Type, (IGraphType ResolveType, IFieldResolver Resolver)> fieldInfos;
public GraphQLContext(PartitionResolver partitionResolver)
{
Guard.NotNull(partitionResolver, nameof(partitionResolver));
this.partitionResolver = partitionResolver;
var defaultResolver =
new FuncFieldResolver<ContentFieldData, object>(c => c.Source.GetOrDefault(c.FieldName));
fieldInfos = new Dictionary<Type, (IGraphType ResolveType, IFieldResolver Resolver)>
{
{
typeof(StringField),
(new StringGraphType(), defaultResolver)
},
{
typeof(BooleanField),
(new BooleanGraphType(), defaultResolver)
},
{
typeof(NumberField),
(new FloatGraphType(), defaultResolver)
},
{
typeof(DateTimeField),
(new FloatGraphType(), defaultResolver)
},
{
typeof(JsonField),
(new ObjectGraphType(), defaultResolver)
},
{
typeof(GeolocationField),
(new ObjectGraphType(), defaultResolver)
},
{
typeof(AssetsField),
(new ListGraphType<StringGraphType>(), defaultResolver)
},
{
typeof(ReferencesField),
(new ListGraphType<StringGraphType>(), defaultResolver)
}
};
}
public IGraphType GetSchemaListType(Schema schema)
{
throw new NotImplementedException();
}
public IGraphType GetSchemaListType(Guid schemaId)
{
throw new NotImplementedException();
}
public IFieldPartitioning ResolvePartition(Partitioning key)
{
return partitionResolver(key);
}
public (IGraphType ResolveType, IFieldResolver Resolver) GetGraphType(Field field)
{
return fieldInfos[field.GetType()];
}
}
}

17
src/Squidex.Domain.Apps.Core/Schemas/IGraphQLResolver.cs → src/Squidex.Domain.Apps.Read/GraphQl/IGraphQLContext.cs

@ -1,22 +1,25 @@
// ========================================================================== // ==========================================================================
// IGraphQLResolver.cs // SchemaGraphType.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System; using GraphQL.Resolvers;
using GraphQL.Types; using GraphQL.Types;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Schema = Squidex.Domain.Apps.Core.Schemas.Schema;
namespace Squidex.Domain.Apps.Core.Schemas namespace Squidex.Domain.Apps.Read.GraphQl
{ {
public interface IGraphQLResolver public interface IGraphQLContext
{ {
IGraphType GetSchemaListType(Schema schema); IGraphType GetSchemaListType(Schema schema);
IGraphType GetSchemaListType(Guid schemaId); IFieldPartitioning ResolvePartition(Partitioning key);
IGraphType GetAssetListType(); (IGraphType ResolveType, IFieldResolver Resolver) GetGraphType(Field field);
} }
} }

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

@ -1,15 +0,0 @@
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();
}
}
Loading…
Cancel
Save