mirror of https://github.com/Squidex/squidex.git
8 changed files with 177 additions and 70 deletions
@ -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), |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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 |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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()]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
} |
} |
||||
} |
} |
||||
@ -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…
Reference in new issue