mirror of https://github.com/Squidex/squidex.git
28 changed files with 691 additions and 755 deletions
@ -1,40 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using GraphQL.Types; |
|
||||
using Squidex.Domain.Apps.Core.Contents; |
|
||||
using Squidex.Domain.Apps.Entities.Schemas; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
|
||||
{ |
|
||||
public sealed class ContentDataFlatGraphType : ObjectGraphType<FlatContentData> |
|
||||
{ |
|
||||
public ContentDataFlatGraphType(ISchemaEntity schema, string schemaName, string schemaType, IGraphModel model) |
|
||||
{ |
|
||||
Name = $"{schemaType}DataFlatDto"; |
|
||||
|
|
||||
foreach (var (field, fieldName, _) in schema.SchemaDef.Fields.SafeFields()) |
|
||||
{ |
|
||||
var (resolvedType, valueResolver, args) = model.GetGraphType(schema, field, fieldName); |
|
||||
|
|
||||
if (valueResolver != null) |
|
||||
{ |
|
||||
AddField(new FieldType |
|
||||
{ |
|
||||
Name = fieldName, |
|
||||
Arguments = args, |
|
||||
ResolvedType = resolvedType, |
|
||||
Resolver = ContentResolvers.FlatPartition(valueResolver, field.Name), |
|
||||
Description = field.RawProperties.Hints |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
Description = $"The structure of the flat {schemaName} data type."; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,39 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Types; |
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
||||
|
{ |
||||
|
public sealed class DataFlatGraphType : ObjectGraphType<FlatContentData> |
||||
|
{ |
||||
|
public DataFlatGraphType(GraphQLModel model, SchemaInfo schemaInfo) |
||||
|
{ |
||||
|
Name = schemaInfo.DataFlatType; |
||||
|
|
||||
|
foreach (var fieldInfo in schemaInfo.Fields) |
||||
|
{ |
||||
|
var (resolvedType, resolver, args) = model.GetGraphType(fieldInfo); |
||||
|
|
||||
|
if (resolver != null) |
||||
|
{ |
||||
|
AddField(new FieldType |
||||
|
{ |
||||
|
Name = fieldInfo.FieldName, |
||||
|
Arguments = args, |
||||
|
ResolvedType = resolvedType, |
||||
|
Resolver = resolver, |
||||
|
Description = fieldInfo.Field.RawProperties.Hints |
||||
|
}).WithSourceName(fieldInfo); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Description = $"The structure of the flat {schemaInfo.DisplayName} data type."; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Types; |
||||
|
using Squidex.Infrastructure.Json.Objects; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
||||
|
{ |
||||
|
public sealed class NestedGraphType : ObjectGraphType<JsonObject> |
||||
|
{ |
||||
|
public NestedGraphType(GraphQLModel model, FieldInfo fieldInfo) |
||||
|
{ |
||||
|
Name = fieldInfo.NestedType; |
||||
|
|
||||
|
foreach (var nestedFieldInfo in fieldInfo.Fields) |
||||
|
{ |
||||
|
var (resolvedType, resolver, args) = model.GetGraphType(nestedFieldInfo); |
||||
|
|
||||
|
if (resolvedType != null && resolver != null) |
||||
|
{ |
||||
|
AddField(new FieldType |
||||
|
{ |
||||
|
Name = nestedFieldInfo.FieldName, |
||||
|
Arguments = args, |
||||
|
ResolvedType = resolvedType, |
||||
|
Resolver = resolver, |
||||
|
Description = $"The {fieldInfo.DisplayName}/{nestedFieldInfo.DisplayName} nested field." |
||||
|
}).WithSourceName(nestedFieldInfo); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Description = $"The structure of the {fieldInfo.DisplayName} nested schema."; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Types; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
||||
|
{ |
||||
|
internal sealed class NestedInputGraphType : InputObjectGraphType |
||||
|
{ |
||||
|
public NestedInputGraphType(GraphQLModel model, FieldInfo fieldInfo) |
||||
|
{ |
||||
|
Name = fieldInfo.NestedInputType; |
||||
|
|
||||
|
foreach (var nestedFieldInfo in fieldInfo.Fields) |
||||
|
{ |
||||
|
var resolvedType = model.GetInputGraphType(nestedFieldInfo); |
||||
|
|
||||
|
if (resolvedType != null) |
||||
|
{ |
||||
|
AddField(new FieldType |
||||
|
{ |
||||
|
Name = nestedFieldInfo.FieldName, |
||||
|
ResolvedType = resolvedType, |
||||
|
Resolver = null, |
||||
|
Description = $"The {fieldInfo.DisplayName}/{nestedFieldInfo.DisplayName} nested field." |
||||
|
}).WithSourceName(nestedFieldInfo); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Description = $"The structure of the {fieldInfo.DisplayName} nested schema."; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,139 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using GraphQL; |
||||
|
using GraphQL.Resolvers; |
||||
|
using GraphQL.Types; |
||||
|
using Squidex.Domain.Apps.Core.Schemas; |
||||
|
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents; |
||||
|
using Squidex.Infrastructure.Json.Objects; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
||||
|
{ |
||||
|
public delegate object ValueResolver(IJsonValue value, IResolveFieldContext fieldContext, GraphQLExecutionContext context); |
||||
|
|
||||
|
internal sealed class GraphQLFieldVisitor : IFieldVisitor<(IGraphType?, IFieldResolver?, QueryArguments?), FieldInfo> |
||||
|
{ |
||||
|
private static readonly IFieldResolver Noop = CreateValueResolver((value, fieldContext, contex) => value); |
||||
|
private static readonly IFieldResolver Json = CreateValueResolver(ContentActions.Json.Resolver); |
||||
|
|
||||
|
private static readonly IFieldResolver Assets = CreateValueResolver((value, _, context) => |
||||
|
{ |
||||
|
return context.GetReferencedAssetsAsync(value); |
||||
|
}); |
||||
|
|
||||
|
private static readonly IFieldResolver References = CreateValueResolver((value, _, context) => |
||||
|
{ |
||||
|
return context.GetReferencedContentsAsync(value); |
||||
|
}); |
||||
|
|
||||
|
private readonly GraphQLModel model; |
||||
|
|
||||
|
public GraphQLFieldVisitor(GraphQLModel model) |
||||
|
{ |
||||
|
this.model = model; |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IArrayField field, FieldInfo args) |
||||
|
{ |
||||
|
var schemaFieldType = |
||||
|
new ListGraphType( |
||||
|
new NonNullGraphType( |
||||
|
new NestedGraphType(model, args))); |
||||
|
|
||||
|
return (schemaFieldType, Noop, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<AssetsFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (model.TypeFactory.AssetsList, Assets, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<BooleanFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (AllTypes.Boolean, Noop, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<DateTimeFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (AllTypes.Date, Noop, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<JsonFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (AllTypes.Json, Json, ContentActions.Json.Arguments); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<GeolocationFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (AllTypes.Json, Noop, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<NumberFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (AllTypes.Float, Noop, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<ReferencesFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return ResolveReferences(field, args); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<StringFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (AllTypes.String, Noop, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<TagsFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (AllTypes.Tags, Noop, null); |
||||
|
} |
||||
|
|
||||
|
public (IGraphType?, IFieldResolver?, QueryArguments?) Visit(IField<UIFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
return (null, null, null); |
||||
|
} |
||||
|
|
||||
|
private (IGraphType?, IFieldResolver?, QueryArguments?) ResolveReferences(IField<ReferencesFieldProperties> field, FieldInfo args) |
||||
|
{ |
||||
|
IGraphType? contentType = model.GetContentType(field.Properties.SingleId()); |
||||
|
|
||||
|
if (contentType == null) |
||||
|
{ |
||||
|
var union = new ContentUnionGraphType(model, args, field.Properties); |
||||
|
|
||||
|
if (!union.PossibleTypes.Any()) |
||||
|
{ |
||||
|
return (null, null, null); |
||||
|
} |
||||
|
|
||||
|
contentType = union; |
||||
|
} |
||||
|
|
||||
|
var schemaFieldType = new ListGraphType(new NonNullGraphType(contentType)); |
||||
|
|
||||
|
return (schemaFieldType, References, null); |
||||
|
} |
||||
|
|
||||
|
private static IFieldResolver CreateValueResolver(ValueResolver valueResolver) |
||||
|
{ |
||||
|
return Resolvers.Sync<IReadOnlyDictionary<string, IJsonValue>, object?>((source, fieldContext, context) => |
||||
|
{ |
||||
|
var key = fieldContext.FieldDefinition.SourceName(); |
||||
|
|
||||
|
if (source.TryGetValue(key, out var value)) |
||||
|
{ |
||||
|
return valueResolver(value, fieldContext, context); |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,150 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using GraphQL; |
|
||||
using GraphQL.Types; |
|
||||
using Squidex.Domain.Apps.Core.Schemas; |
|
||||
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents; |
|
||||
using Squidex.Domain.Apps.Entities.Schemas; |
|
||||
using Squidex.Infrastructure; |
|
||||
using Squidex.Infrastructure.Json.Objects; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
|
||||
{ |
|
||||
public delegate object ValueResolver(IJsonValue value, IResolveFieldContext fieldContext, GraphQLExecutionContext context); |
|
||||
|
|
||||
internal sealed class GraphQLTypeVisitor : IFieldVisitor<(IGraphType?, ValueResolver?, QueryArguments?), GraphQLTypeVisitor.Args> |
|
||||
{ |
|
||||
private static readonly ValueResolver NoopResolver = (value, fieldContext, contex) => value; |
|
||||
|
|
||||
private readonly Dictionary<DomainId, ContentGraphType> schemaTypes; |
|
||||
private readonly IGraphModel model; |
|
||||
|
|
||||
public readonly struct Args |
|
||||
{ |
|
||||
public readonly ISchemaEntity Schema; |
|
||||
|
|
||||
public readonly string SchemaField; |
|
||||
|
|
||||
public Args(ISchemaEntity schema, string fieldName) |
|
||||
{ |
|
||||
Schema = schema; |
|
||||
SchemaField = fieldName; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public GraphQLTypeVisitor(Dictionary<DomainId, ContentGraphType> schemaTypes, IGraphModel model) |
|
||||
{ |
|
||||
this.model = model; |
|
||||
|
|
||||
this.schemaTypes = schemaTypes; |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IArrayField field, Args args) |
|
||||
{ |
|
||||
var schemaFieldType = |
|
||||
new ListGraphType( |
|
||||
new NonNullGraphType( |
|
||||
new NestedGraphType(model, args.Schema, field, args.SchemaField))); |
|
||||
|
|
||||
return (schemaFieldType, NoopResolver, null); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<AssetsFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveAssets(); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<BooleanFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveDefault(AllTypes.NoopBoolean); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<DateTimeFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveDefault(AllTypes.NoopDate); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<GeolocationFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveDefault(AllTypes.NoopGeolocation); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<NumberFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveDefault(AllTypes.NoopFloat); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<ReferencesFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveReferences(field, args); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<StringFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveDefault(AllTypes.NoopString); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<TagsFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return ResolveDefault(AllTypes.NoopTags); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<UIFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return (null, null, null); |
|
||||
} |
|
||||
|
|
||||
public (IGraphType?, ValueResolver?, QueryArguments?) Visit(IField<JsonFieldProperties> field, Args args) |
|
||||
{ |
|
||||
return (AllTypes.NoopJson, ContentActions.Json.Resolver, ContentActions.Json.Arguments); |
|
||||
} |
|
||||
|
|
||||
private static (IGraphType?, ValueResolver?, QueryArguments?) ResolveDefault(IGraphType type) |
|
||||
{ |
|
||||
return (type, NoopResolver, null); |
|
||||
} |
|
||||
|
|
||||
private (IGraphType?, ValueResolver?, QueryArguments?) ResolveAssets() |
|
||||
{ |
|
||||
var resolver = new ValueResolver((value, _, context) => |
|
||||
{ |
|
||||
return context.GetReferencedAssetsAsync(value); |
|
||||
}); |
|
||||
|
|
||||
return (model.TypeFactory.AssetsList, resolver, null); |
|
||||
} |
|
||||
|
|
||||
private (IGraphType?, ValueResolver?, QueryArguments?) ResolveReferences(IField<ReferencesFieldProperties> field, Args args) |
|
||||
{ |
|
||||
IGraphType contentType = schemaTypes.GetOrDefault(field.Properties.SingleId()); |
|
||||
|
|
||||
if (contentType == null) |
|
||||
{ |
|
||||
var union = new ContentUnionGraphType(args.SchemaField, schemaTypes, field.Properties.SchemaIds); |
|
||||
|
|
||||
if (!union.PossibleTypes.Any()) |
|
||||
{ |
|
||||
return (null, null, null); |
|
||||
} |
|
||||
|
|
||||
contentType = union; |
|
||||
} |
|
||||
|
|
||||
var resolver = new ValueResolver((value, _, context) => |
|
||||
{ |
|
||||
return context.GetReferencedContentsAsync(value); |
|
||||
}); |
|
||||
|
|
||||
var schemaFieldType = new ListGraphType(new NonNullGraphType(contentType)); |
|
||||
|
|
||||
return (schemaFieldType, resolver, null); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,48 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System.Linq; |
|
||||
using GraphQL.Types; |
|
||||
using Squidex.Domain.Apps.Core.Schemas; |
|
||||
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents; |
|
||||
using Squidex.Domain.Apps.Entities.Schemas; |
|
||||
using Squidex.Infrastructure.Json.Objects; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
|
||||
{ |
|
||||
public sealed class NestedGraphType : ObjectGraphType<JsonObject> |
|
||||
{ |
|
||||
public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field, string fieldName) |
|
||||
{ |
|
||||
var schemaType = schema.TypeName(); |
|
||||
var schemaName = schema.DisplayName(); |
|
||||
|
|
||||
var fieldDisplayName = field.DisplayName(); |
|
||||
|
|
||||
Name = $"{schemaType}{fieldName}ChildDto"; |
|
||||
|
|
||||
foreach (var (nestedField, nestedName, typeName) in field.Fields.SafeFields().Where(x => x.Field.IsForApi())) |
|
||||
{ |
|
||||
var (resolvedType, valueResolver, args) = model.GetGraphType(schema, nestedField, typeName); |
|
||||
|
|
||||
if (resolvedType != null && valueResolver != null) |
|
||||
{ |
|
||||
AddField(new FieldType |
|
||||
{ |
|
||||
Name = nestedName, |
|
||||
Arguments = args, |
|
||||
ResolvedType = resolvedType, |
|
||||
Resolver = ContentResolvers.NestedValue(valueResolver, nestedField.Name), |
|
||||
Description = $"The {fieldDisplayName}/{nestedField.DisplayName()} nested field." |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
Description = $"The structure of the {schemaName}.{fieldDisplayName} nested schema."; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System.Linq; |
|
||||
using GraphQL.Types; |
|
||||
using Squidex.Domain.Apps.Core.Schemas; |
|
||||
using Squidex.Domain.Apps.Entities.Schemas; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
|
||||
{ |
|
||||
public sealed class NestedInputGraphType : InputObjectGraphType |
|
||||
{ |
|
||||
public NestedInputGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field, string fieldName) |
|
||||
{ |
|
||||
var schemaType = schema.TypeName(); |
|
||||
var schemaName = schema.DisplayName(); |
|
||||
|
|
||||
var fieldDisplayName = field.DisplayName(); |
|
||||
|
|
||||
Name = $"{schemaType}{fieldName}InputChildDto"; |
|
||||
|
|
||||
foreach (var (nestedField, nestedName, typeName) in field.Fields.SafeFields().Where(x => x.Field.IsForApi(true))) |
|
||||
{ |
|
||||
var resolvedType = model.GetInputGraphType(schema, nestedField, typeName); |
|
||||
|
|
||||
if (resolvedType != null) |
|
||||
{ |
|
||||
AddField(new FieldType |
|
||||
{ |
|
||||
Name = nestedName, |
|
||||
ResolvedType = resolvedType, |
|
||||
Resolver = null, |
|
||||
Description = $"The {fieldDisplayName}/{nestedField.DisplayName()} nested field." |
|
||||
}).WithSourceName(nestedField.Name); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
Description = $"The structure of the {schemaName}.{fieldDisplayName} nested schema."; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using GraphQL.Types; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils |
|
||||
{ |
|
||||
internal sealed class GeolocationInputGraphType : InputObjectGraphType |
|
||||
{ |
|
||||
public static readonly IGraphType Nullable = new GeolocationInputGraphType(); |
|
||||
|
|
||||
public static readonly IGraphType NonNull = new NonNullGraphType(Nullable); |
|
||||
|
|
||||
private GeolocationInputGraphType() |
|
||||
{ |
|
||||
Name = "GeolocationInputDto"; |
|
||||
|
|
||||
AddField(new FieldType |
|
||||
{ |
|
||||
Name = "latitude", |
|
||||
ResolvedType = AllTypes.NonNullFloat |
|
||||
}); |
|
||||
|
|
||||
AddField(new FieldType |
|
||||
{ |
|
||||
Name = "longitude", |
|
||||
ResolvedType = AllTypes.NonNullFloat |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,83 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using Squidex.Domain.Apps.Core.Schemas; |
||||
|
using Squidex.Domain.Apps.Entities.Schemas; |
||||
|
|
||||
|
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
|
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
||||
|
{ |
||||
|
public sealed record SchemaInfo(ISchemaEntity Schema, string TypeName, IReadOnlyList<FieldInfo> Fields) |
||||
|
{ |
||||
|
public string DisplayName { get; set; } = Schema.DisplayName(); |
||||
|
|
||||
|
public string ContentType { get; } = TypeName.SafeTypeName(); |
||||
|
|
||||
|
public string DataType { get; } = $"{TypeName}DataDto"; |
||||
|
|
||||
|
public string DataInputType { get; } = $"{TypeName}DataInputDto"; |
||||
|
|
||||
|
public string DataFlatType { get; } = $"{TypeName}FlatDataDto"; |
||||
|
|
||||
|
public string ResultType { get; } = $"{TypeName}ResultDto"; |
||||
|
|
||||
|
public static SchemaInfo Build(ISchemaEntity schema) |
||||
|
{ |
||||
|
var typeName = schema.TypeName(); |
||||
|
|
||||
|
var fields = |
||||
|
schema.SchemaDef.Fields.SafeFields() |
||||
|
.Select(x => FieldInfo.Build(x.Field, x.Name, $"{typeName}{x.Type}")) |
||||
|
.ToList(); |
||||
|
|
||||
|
return new SchemaInfo( |
||||
|
schema, |
||||
|
schema.TypeName(), |
||||
|
fields); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public sealed record FieldInfo(IField Field, string FieldName, string TypeName, IReadOnlyList<FieldInfo> Fields) |
||||
|
{ |
||||
|
private static readonly IReadOnlyList<FieldInfo> EmptyFields = new List<FieldInfo>(); |
||||
|
|
||||
|
public string DisplayName { get; set; } = Field.DisplayName(); |
||||
|
|
||||
|
public string LocalizedType { get; } = $"{TypeName}Dto"; |
||||
|
|
||||
|
public string LocalizedInputType { get; } = $"{TypeName}InputDto"; |
||||
|
|
||||
|
public string NestedType { get; } = $"{TypeName}ChildDto"; |
||||
|
|
||||
|
public string NestedInputType { get; } = $"{TypeName}ChildInputDto"; |
||||
|
|
||||
|
public string UnionType { get; } = $"{TypeName}UnionDto"; |
||||
|
|
||||
|
public static FieldInfo Build(IRootField rootField, string fieldName, string typeName) |
||||
|
{ |
||||
|
var fields = EmptyFields; |
||||
|
|
||||
|
if (rootField is IArrayField arrayField) |
||||
|
{ |
||||
|
fields = |
||||
|
arrayField.Fields.SafeFields() |
||||
|
.Select(x => Build(x.Field, x.Name, $"{typeName}{x.Type}")) |
||||
|
.ToList(); |
||||
|
} |
||||
|
|
||||
|
return new FieldInfo(rootField, fieldName, typeName, fields); |
||||
|
} |
||||
|
|
||||
|
public static FieldInfo Build(INestedField nestedField, string fieldName, string fieldTypeName) |
||||
|
{ |
||||
|
return new FieldInfo(nestedField, fieldName, fieldTypeName, EmptyFields); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue