Browse Source

Fix for graphql and assets.

pull/362/head
Sebastian 7 years ago
parent
commit
a656c461b4
  1. 6
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AllTypes.cs
  2. 13
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AppQueriesGraphType.cs
  3. 9
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AssetGraphType.cs
  4. 14
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs
  5. 3
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs

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

@ -16,6 +16,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{
public static readonly Type None = typeof(NoopGraphType);
public static readonly Type NonNullTagsType = typeof(NonNullGraphType<ListGraphType<NonNullGraphType<StringGraphType>>>);
public static readonly IGraphType Int = new IntGraphType();
public static readonly IGraphType Guid = new GuidGraphType2();
@ -24,8 +26,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
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>();
@ -34,8 +34,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
public static readonly IGraphType Boolean = new BooleanGraphType();
public static readonly IGraphType References = new ListGraphType<NonNullGraphType<GuidGraphType2>>();
public static readonly IGraphType NonNullInt = new NonNullGraphType(Int);
public static readonly IGraphType NonNullGuid = new NonNullGraphType(Guid);

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

@ -169,7 +169,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{
new QueryArgument(AllTypes.None)
{
Name = "take",
Name = "top",
Description = $"Optional number of assets to take (Default: {pageSize}).",
DefaultValue = pageSize,
ResolvedType = AllTypes.Int
@ -183,8 +183,15 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
},
new QueryArgument(AllTypes.None)
{
Name = "search",
Description = "Optional query to limit the files by name.",
Name = "filter",
Description = "Optional OData filter.",
DefaultValue = string.Empty,
ResolvedType = AllTypes.String
},
new QueryArgument(AllTypes.None)
{
Name = "orderby",
Description = "Optional OData order definition.",
DefaultValue = string.Empty,
ResolvedType = AllTypes.String
}

9
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AssetGraphType.cs

@ -163,6 +163,15 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
Description = "The height of the image in pixels if the asset is an image."
});
AddField(new FieldType
{
Name = "tags",
ResolvedType = null,
Resolver = Resolve(x => x.Tags),
Description = "The height of the image in pixels if the asset is an image.",
Type = AllTypes.NonNullTagsType
});
if (model.CanGenerateAssetSourceUrl)
{
AddField(new FieldType

14
tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs

@ -39,7 +39,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
const string query = @"
query {
queryAssets(search: ""my-query"", take: 30, skip: 5) {
queryAssets(filter: ""my-query"", top: 30, skip: 5) {
id
version
created
@ -57,13 +57,14 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
isImage
pixelWidth
pixelHeight
tags
slug
}
}";
var asset = CreateAsset(Guid.NewGuid());
A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), A<Q>.That.Matches(x => x.ODataQuery == "?$take=30&$skip=5&$search=my-query")))
A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), A<Q>.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5&$filter=my-query")))
.Returns(ResultList.Create(0, asset));
var result = await sut.QueryAsync(context, new GraphQLQuery { Query = query });
@ -93,6 +94,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
isImage = true,
pixelWidth = 800,
pixelHeight = 600,
tags = new string[] { "tag1", "tag2" },
slug = "myfile.png"
}
}
@ -107,7 +109,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
const string query = @"
query {
queryAssetsWithTotal(search: ""my-query"", take: 30, skip: 5) {
queryAssetsWithTotal(filter: ""my-query"", top: 30, skip: 5) {
total
items {
id
@ -127,6 +129,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
isImage
pixelWidth
pixelHeight
tags
slug
}
}
@ -134,7 +137,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
var asset = CreateAsset(Guid.NewGuid());
A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), A<Q>.That.Matches(x => x.ODataQuery == "?$take=30&$skip=5&$search=my-query")))
A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), A<Q>.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5&$filter=my-query")))
.Returns(ResultList.Create(10, asset));
var result = await sut.QueryAsync(context, new GraphQLQuery { Query = query });
@ -167,6 +170,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
isImage = true,
pixelWidth = 800,
pixelHeight = 600,
tags = new string[] { "tag1", "tag2" },
slug = "myfile.png"
}
}
@ -203,6 +207,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
isImage
pixelWidth
pixelHeight
tags
slug
}}
}}";
@ -235,6 +240,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
isImage = true,
pixelWidth = 800,
pixelHeight = 600,
tags = new string[] { "tag1", "tag2" },
slug = "myfile.png"
}
}

3
tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs

@ -177,7 +177,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
MimeType = "image/png",
IsImage = true,
PixelWidth = 800,
PixelHeight = 600
PixelHeight = 600,
Tags = new[] { "tag1", "tag2" }.ToHashSet()
};
return asset;

Loading…
Cancel
Save