From 0b53856fbed56ea005939ff03085adc13538da69 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Wed, 5 Apr 2023 11:00:22 +0200 Subject: [PATCH] Graphql query by ids (#986) * Improve handling of default values. * Open Api fixes and parent id. * Query by IDs * Introspection fixes. * Rename field. * New test for data__dynamic. * Fix tests --- .../GraphQL/Types/ApplicationQueries.cs | 2 +- .../Contents/GraphQL/GraphQLQueriesTests.cs | 8 +++--- .../TestSuite.ApiTests/GraphQLTests.cs | 27 +++++++++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs index 6b418d1e4..0edcf5246 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs @@ -86,7 +86,7 @@ internal sealed class ApplicationQueries : ObjectGraphType AddField(new FieldType { - Name = "queryContents", + Name = "queryContentsByIds", Arguments = ContentActions.QueryByIds.Arguments, ResolvedType = new NonNullGraphType(new ListGraphType(new NonNullGraphType(unionType))), Resolver = ContentActions.QueryByIds.Resolver, diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs index a388cd3e3..fae484617 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs @@ -86,7 +86,7 @@ public class GraphQLQueriesTests : GraphQLTestBase var query = CreateQuery(@" query { - queryContents(ids: [""""]) { + queryContentsByIds(ids: [""""]) { ... on Content { id } @@ -109,7 +109,7 @@ public class GraphQLQueriesTests : GraphQLTestBase { data = new { - queryContents = new[] + queryContentsByIds = new[] { new { @@ -134,7 +134,7 @@ public class GraphQLQueriesTests : GraphQLTestBase var query = CreateQuery(@" query { - queryContents(ids: [""""]) { + queryContentsByIds(ids: [""""]) { ... on Content { data: data__dynamic } @@ -152,7 +152,7 @@ public class GraphQLQueriesTests : GraphQLTestBase { data = new { - queryContents = new[] + queryContentsByIds = new[] { new { diff --git a/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs b/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs index b57bec2e2..71af30a81 100644 --- a/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs @@ -227,6 +227,29 @@ public sealed class GraphQLTests : IClassFixture Assert.Equal(new[] { "Saxony" }, stateNames); } + [Fact] + public async Task Should_query_dynamic_data() + { + var query = new + { + query = @" + { + cities: queryCitiesContents { + data__dynamic + } + }" + }; + + var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); + + var cityNames = + result["cities"] + .Select(x => x["data__dynamic"]["name"]["iv"].Value()) + .Order(); + + Assert.Equal(new[] { "Leipzig", "Munich" }, cityNames); + } + [Fact] public async Task Should_query_correct_content_type_for_graphql() { @@ -260,7 +283,7 @@ public sealed class GraphQLTests : IClassFixture { query = @" query ContentsQuery($ids: [String!]!) { - queryContents(ids: $ids) { + queryContentsByIds(ids: $ids) { ... on Content { id } @@ -285,7 +308,7 @@ public sealed class GraphQLTests : IClassFixture var result = await _.Client.SharedDynamicContents.GraphQlAsync(query); var names = - result["queryContents"] + result["queryContentsByIds"] .Select(x => x["data"]["name"].Value()) .Order();