Browse Source

Fix JSON. (#1088)

* Fix JSON.

* Simplify json.
pull/1089/head
Sebastian Stehle 2 years ago
committed by GitHub
parent
commit
65315fe653
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/AssetGraphType.cs
  2. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/EnrichedAssetEventGraphType.cs
  3. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentFields.cs
  4. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/EnrichedContentEventGraphType.cs
  5. 6
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/FieldVisitor.cs
  6. 11
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Primitives/JsonGraphType.cs
  7. 37
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Primitives/JsonNoopGraphType.cs
  8. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Scalars.cs
  9. 3
      backend/src/Squidex/Config/Domain/QueryServices.cs
  10. 53
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/AssetGraphType.cs

@ -214,7 +214,7 @@ internal sealed class AssetGraphType : SharedObjectGraphType<EnrichedAsset>
{
Name = "metadata",
Arguments = AssetActions.Metadata.Arguments,
ResolvedType = Scalars.JsonNoop,
ResolvedType = Scalars.Json,
Resolver = AssetActions.Metadata.Resolver,
Description = FieldDescriptions.AssetMetadata
});

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Assets/EnrichedAssetEventGraphType.cs

@ -213,7 +213,7 @@ internal sealed class EnrichedAssetEventGraphType : SharedObjectGraphType<Enrich
{
Name = "metadata",
Arguments = AssetActions.Metadata.Arguments,
ResolvedType = Scalars.JsonNoop,
ResolvedType = Scalars.Json,
Resolver = AssetActions.Metadata.Resolver,
Description = FieldDescriptions.AssetMetadata
});

4
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentFields.cs

@ -215,7 +215,7 @@ internal static class ContentFields
public static readonly FieldType DataDynamic = new FieldType
{
Name = "data__dynamic",
ResolvedType = Scalars.JsonNoop,
ResolvedType = Scalars.Json,
Resolver = Resolve(x => x.Data),
Description = FieldDescriptions.ContentData
};
@ -241,7 +241,7 @@ internal static class ContentFields
public static readonly FieldType RichTextFieldValue = new FieldType
{
Name = "value",
ResolvedType = Scalars.JsonNoop,
ResolvedType = Scalars.Json,
Resolver = Resolvers.Sync<RichTextNode, JsonObject?>(x => x.Root),
Description = FieldDescriptions.RichTextFieldValue
};

4
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/EnrichedContentEventGraphType.cs

@ -110,7 +110,7 @@ internal sealed class EnrichedContentEventGraphType : SharedObjectGraphType<Enri
AddField(new FieldType
{
Name = "data",
ResolvedType = Scalars.JsonNoop,
ResolvedType = Scalars.Json,
Resolver = Resolve(x => x.Data),
Description = FieldDescriptions.ContentData
});
@ -118,7 +118,7 @@ internal sealed class EnrichedContentEventGraphType : SharedObjectGraphType<Enri
AddField(new FieldType
{
Name = "dataOld",
ResolvedType = Scalars.JsonNoop,
ResolvedType = Scalars.Json,
Resolver = Resolve(x => x.DataOld),
Description = FieldDescriptions.ContentDataOld
});

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

@ -24,7 +24,7 @@ public delegate Task<T> AsyncValueResolver<T>(JsonValue value, IResolveFieldCont
internal sealed class FieldVisitor : IFieldVisitor<FieldGraphSchema, FieldInfo>
{
public static readonly IFieldResolver JsonNoop = CreateValueResolver((value, fieldContext, contex) => value.Value);
public static readonly IFieldResolver JsonScalar = CreateValueResolver((value, fieldContext, contex) => value.Value);
public static readonly IFieldResolver JsonPath = CreateValueResolver(ContentActions.Json.Resolver);
private static readonly IFieldResolver JsonBoolean = CreateValueResolver((value, fieldContext, contex) =>
@ -171,7 +171,7 @@ internal sealed class FieldVisitor : IFieldVisitor<FieldGraphSchema, FieldInfo>
return default;
}
return new (type, JsonNoop, null);
return new (type, JsonScalar, null);
}
public FieldGraphSchema Visit(IField<ComponentsFieldProperties> field, FieldInfo args)
@ -197,7 +197,7 @@ internal sealed class FieldVisitor : IFieldVisitor<FieldGraphSchema, FieldInfo>
if (schema.Length > 0)
{
return new (schema[0], JsonNoop, null);
return new (schema[0], JsonScalar, null);
}
return new (Scalars.Json, JsonPath, ContentActions.Json.Arguments);

11
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Primitives/JsonGraphType.cs

@ -6,13 +6,22 @@
// ==========================================================================
using System.Globalization;
using GraphQL.Types;
using GraphQLParser.AST;
using Squidex.Infrastructure.Json.Objects;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives;
public sealed class JsonGraphType : JsonNoopGraphType
public sealed class JsonGraphType : ScalarGraphType
{
public JsonGraphType()
{
// The name is used for equal comparison. Therefore it is important to treat it as readonly.
Name = "JsonScalar";
Description = "Unstructured Json object";
}
public override object? Serialize(object? value)
{
return value;

37
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Primitives/JsonNoopGraphType.cs

@ -1,37 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using GraphQL.Types;
using GraphQLParser.AST;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives;
public class JsonNoopGraphType : ScalarGraphType
{
public JsonNoopGraphType()
{
// The name is used for equal comparison. Therefore it is important to treat it as readonly.
Name = "JsonScalar";
Description = "Unstructured Json object";
}
public override object? ParseLiteral(GraphQLValue value)
{
return value;
}
public override object? ParseValue(object? value)
{
return value;
}
public override object? Serialize(object? value)
{
return value;
}
}

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Scalars.cs

@ -20,8 +20,6 @@ public static class Scalars
public static readonly IGraphType Json = new JsonGraphType();
public static readonly IGraphType JsonNoop = new JsonNoopGraphType();
public static readonly IGraphType Float = new FloatGraphType();
public static readonly IGraphType String = new StringGraphType();

3
backend/src/Squidex/Config/Domain/QueryServices.cs

@ -31,8 +31,5 @@ public static class QueryServices
services.AddSingletonAs<JsonGraphType>()
.AsSelf();
services.AddSingletonAs<JsonNoopGraphType>()
.AsSelf();
}
}

53
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs

@ -127,6 +127,59 @@ public class GraphQLMutationTests : GraphQLTestBase
.MustHaveHappened();
}
[Fact]
public async Task Should_create_content_with_variable()
{
commandContext.Complete(content);
var actual = await ExecuteAsync(new TestQuery
{
Query = @"
mutation MyMutation($location: JsonScalar) {
createMySchemaContent(data: {
myGeolocation: {
iv: $location
}
}) {
id
}
}",
Args = new
{
fields = TestContent.AllFields
},
Variables = new
{
location = new
{
latitude = 42,
longitude = 13
}
},
Permission = PermissionIds.AppContentsCreate
});
var expected = new
{
data = new
{
createMySchemaContent = new
{
id = content.Id,
}
}
};
AssertResult(expected, actual);
A.CallTo(() => commandBus.PublishAsync(
A<CreateContent>.That.Matches(x =>
x.ExpectedVersion == EtagVersion.Any &&
x.SchemaId.Equals(TestSchemas.Default.NamedId())),
A<CancellationToken>._))
.MustHaveHappened();
}
[Fact]
public async Task Should_return_single_content_if_creating_content_with_custom_id()
{

Loading…
Cancel
Save