Browse Source

Temp.

pull/297/head
Sebastian 8 years ago
parent
commit
dd89947fa5
  1. 2
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLModel.cs
  2. 30
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AllTypes.cs
  3. 13
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ContentDataGraphInputType.cs
  4. 18
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/InputFieldVisitor.cs
  5. 4
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/NestedGraphType.cs
  6. 47
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/NestedInputGraphType.cs
  7. 6
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/QueryGraphTypeVisitor.cs
  8. 10
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JsonConverter.cs
  9. 42
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JsonGraphType.cs
  10. 8
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JsonValue.cs
  11. 6
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/NoopGraphType.cs

2
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLModel.cs

@ -54,7 +54,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
schemasById = schemas.ToDictionary(x => x.Id);
graphQLSchema = BuildSchema(this);
graphQLSchema.RegisterValueConverter(JTokenConverter.Instance);
graphQLSchema.RegisterValueConverter(JsonConverter.Instance);
InitializeContentTypes();
}

30
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AllTypes.cs

@ -22,13 +22,21 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
public static readonly IGraphType Date = new DateGraphType();
public static readonly IGraphType Json = new JsonGraphType();
public static readonly IGraphType Tags = new ListGraphType<NonNullGraphType<StringGraphType>>();
public static readonly IGraphType Float = new FloatGraphType();
public static readonly IGraphType Status = new EnumerationGraphType<Status>();
public static readonly IGraphType String = new StringGraphType();
public static readonly IGraphType Boolean = new BooleanGraphType();
public static readonly IGraphType StatusType = new EnumerationGraphType<Status>();
public static readonly IGraphType References = new ListGraphType<NonNullGraphType<GuidGraphType>>();
public static readonly IGraphType GeolocationInput = new GeolocationInputGraphType();
public static readonly IGraphType NonNullInt = new NonNullGraphType(Int);
@ -42,28 +50,24 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
public static readonly IGraphType NonNullBoolean = new NonNullGraphType(Boolean);
public static readonly IGraphType NonNullStatusType = new NonNullGraphType(StatusType);
public static readonly IGraphType NonNullStatusType = new NonNullGraphType(Status);
public static readonly IGraphType NoopArray = new NoopGraphType("Array");
public static readonly IGraphType NoopDate = new NoopGraphType("Date");
public static readonly IGraphType NoopJson = new NoopGraphType("Json");
public static readonly IGraphType NoopDate = new NoopGraphType(Date);
public static readonly IGraphType NoopTags = new NoopGraphType("Tags");
public static readonly IGraphType NoopJson = new NoopGraphType(Json);
public static readonly IGraphType NoopFloat = new NoopGraphType("Float");
public static readonly IGraphType NoopTags = new NoopGraphType(Tags);
public static readonly IGraphType NoopString = new NoopGraphType("String");
public static readonly IGraphType NoopFloat = new NoopGraphType(Float);
public static readonly IGraphType NoopBoolean = new NoopGraphType("Boolean");
public static readonly IGraphType NoopString = new NoopGraphType(String);
public static readonly IGraphType NoopGeolocation = new NoopGraphType("Geolocation");
public static readonly IGraphType NoopBoolean = new NoopGraphType(Boolean);
public static readonly IGraphType NoopReferences = new NoopGraphType("References");
public static readonly IGraphType NoopGeolocation = new NoopGraphType(GeolocationInput);
public static readonly IGraphType CommandVersion = new CommandVersionGraphType();
public static readonly IGraphType GeolocationInput = new GeolocationInputGraphType();
}
}

13
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ContentDataGraphInputType.cs

@ -5,12 +5,8 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Collections.Generic;
using System.Linq;
using GraphQL.Resolvers;
using GraphQL.Types;
using Newtonsoft.Json.Linq;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure;
@ -50,23 +46,18 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
fieldGraphType.AddField(new FieldType
{
Name = partitionItem.Key,
ResolvedType = inputType,
Resolver = null,
ResolvedType = inputType,
Description = field.RawProperties.Hints
});
}
fieldGraphType.Description = $"The input structure of the {fieldName} of a {schemaName} content type.";
var fieldResolver = new FuncFieldResolver<NamedContentData, IReadOnlyDictionary<string, JToken>>(c =>
{
return c.Source.GetOrDefault(field.Name);
});
AddField(new FieldType
{
Name = field.Name.ToCamelCase(),
Resolver = fieldResolver,
Resolver = null,
ResolvedType = fieldGraphType,
Description = $"The {fieldName} field."
});

18
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/InputFieldVisitor.cs

@ -25,47 +25,47 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
public IGraphType Visit(IField<AssetsFieldProperties> field)
{
return AllTypes.NoopReferences;
return AllTypes.References;
}
public IGraphType Visit(IField<BooleanFieldProperties> field)
{
return AllTypes.NoopBoolean;
return AllTypes.Boolean;
}
public IGraphType Visit(IField<DateTimeFieldProperties> field)
{
return AllTypes.NoopDate;
return AllTypes.Date;
}
public IGraphType Visit(IField<GeolocationFieldProperties> field)
{
return AllTypes.NoopGeolocation;
return AllTypes.GeolocationInput;
}
public IGraphType Visit(IField<JsonFieldProperties> field)
{
return AllTypes.NoopJson;
return AllTypes.Json;
}
public IGraphType Visit(IField<NumberFieldProperties> field)
{
return AllTypes.NoopFloat;
return AllTypes.Float;
}
public IGraphType Visit(IField<ReferencesFieldProperties> field)
{
return AllTypes.NoopReferences;
return AllTypes.References;
}
public IGraphType Visit(IField<StringFieldProperties> field)
{
return AllTypes.NoopString;
return AllTypes.String;
}
public IGraphType Visit(IField<TagsFieldProperties> field)
{
return AllTypes.NoopTags;
return AllTypes.Tags;
}
}
}

4
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/NestedObjectGraphType.cs → src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/NestedGraphType.cs

@ -15,9 +15,9 @@ using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{
public sealed class NestedObjectGraphType : ObjectGraphType<JObject>
public sealed class NestedGraphType : ObjectGraphType<JObject>
{
public NestedObjectGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field)
public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field)
{
var schemaType = schema.TypeName();
var schemaName = schema.DisplayName();

47
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/NestedInputGraphType.cs

@ -0,0 +1,47 @@
// ==========================================================================
// 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;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{
public sealed class NestedInputGraphType : InputObjectGraphType
{
public NestedInputGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field)
{
var schemaType = schema.TypeName();
var schemaName = schema.DisplayName();
var fieldType = field.TypeName();
var fieldName = field.DisplayName();
Name = $"{schemaType}{fieldName}ChildDto";
foreach (var nestedField in field.Fields.Where(x => !x.IsHidden))
{
var fieldInfo = model.GetGraphType(schema, nestedField);
if (fieldInfo.ResolveType != null)
{
AddField(new FieldType
{
Name = nestedField.Name.ToCamelCase(),
Resolver = null,
ResolvedType = fieldInfo.ResolveType,
Description = $"The {fieldName}/{nestedField.DisplayName()} nested field."
});
}
}
Description = $"The structure of a {schemaName}.{fieldName} nested schema.";
}
}
}

6
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/QueryGraphTypeVisitor.cs

@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
public (IGraphType ResolveType, ValueResolver Resolver) Visit(IField<AssetsFieldProperties> field)
{
return ResolveAssets(assetListType);
return ResolveAssets();
}
public (IGraphType ResolveType, ValueResolver Resolver) Visit(IField<BooleanFieldProperties> field)
@ -88,12 +88,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
private (IGraphType ResolveType, ValueResolver Resolver) ResolveNested(IArrayField field)
{
var schemaFieldType = new ListGraphType(new NonNullGraphType(new NestedObjectGraphType(model, schema, field)));
var schemaFieldType = new ListGraphType(new NonNullGraphType(new NestedGraphType(model, schema, field)));
return (schemaFieldType, NoopResolver);
}
private (IGraphType ResolveType, ValueResolver Resolver) ResolveAssets(IGraphType assetListType)
private (IGraphType ResolveType, ValueResolver Resolver) ResolveAssets()
{
var resolver = new ValueResolver((value, c) =>
{

10
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JTokenConverter.cs → src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JsonConverter.cs

@ -11,22 +11,22 @@ using Newtonsoft.Json.Linq;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils
{
public sealed class JTokenConverter : IAstFromValueConverter
public sealed class JsonConverter : IAstFromValueConverter
{
public static readonly JTokenConverter Instance = new JTokenConverter();
public static readonly JsonConverter Instance = new JsonConverter();
private JTokenConverter()
private JsonConverter()
{
}
public IValue Convert(object value, IGraphType type)
{
return new JTokenValue(value as JToken);
return new JsonValue(value as JObject);
}
public bool Matches(object value, IGraphType type)
{
return value is JToken;
return value is JObject;
}
}
}

42
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JsonGraphType.cs

@ -0,0 +1,42 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using GraphQL.Language.AST;
using GraphQL.Types;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils
{
public sealed class JsonGraphType : ScalarGraphType
{
public JsonGraphType()
{
Name = "Json";
Description = "Unstructured Json object";
}
public override object Serialize(object value)
{
return value;
}
public override object ParseValue(object value)
{
return value;
}
public override object ParseLiteral(IValue value)
{
if (value is JsonValue jsonGraphType)
{
return jsonGraphType.Value;
}
return value;
}
}
}

8
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JTokenValue.cs → src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/JsonValue.cs

@ -10,16 +10,16 @@ using Newtonsoft.Json.Linq;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils
{
public sealed class JTokenValue : ValueNode<JToken>
public sealed class JsonValue : ValueNode<JObject>
{
public JTokenValue(JToken value)
public JsonValue(JObject value)
{
Value = value;
}
protected override bool Equals(ValueNode<JToken> node)
protected override bool Equals(ValueNode<JObject> node)
{
return node.Value.Equals(Value);
return false;
}
}
}

6
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Utils/NoopGraphType.cs

@ -17,6 +17,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils
Name = name;
}
public NoopGraphType(IGraphType type)
: this(type.Name)
{
Description = type.Description;
}
public override object Serialize(object value)
{
return value;

Loading…
Cancel
Save