Browse Source

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
pull/987/head
Sebastian Stehle 4 years ago
committed by GitHub
parent
commit
0b53856fbe
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs
  2. 8
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs
  3. 27
      tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs

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

@ -86,7 +86,7 @@ internal sealed class ApplicationQueries : ObjectGraphType
AddField(new FieldType AddField(new FieldType
{ {
Name = "queryContents", Name = "queryContentsByIds",
Arguments = ContentActions.QueryByIds.Arguments, Arguments = ContentActions.QueryByIds.Arguments,
ResolvedType = new NonNullGraphType(new ListGraphType(new NonNullGraphType(unionType))), ResolvedType = new NonNullGraphType(new ListGraphType(new NonNullGraphType(unionType))),
Resolver = ContentActions.QueryByIds.Resolver, Resolver = ContentActions.QueryByIds.Resolver,

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

@ -86,7 +86,7 @@ public class GraphQLQueriesTests : GraphQLTestBase
var query = CreateQuery(@" var query = CreateQuery(@"
query { query {
queryContents(ids: [""<ID>""]) { queryContentsByIds(ids: [""<ID>""]) {
... on Content { ... on Content {
id id
} }
@ -109,7 +109,7 @@ public class GraphQLQueriesTests : GraphQLTestBase
{ {
data = new data = new
{ {
queryContents = new[] queryContentsByIds = new[]
{ {
new new
{ {
@ -134,7 +134,7 @@ public class GraphQLQueriesTests : GraphQLTestBase
var query = CreateQuery(@" var query = CreateQuery(@"
query { query {
queryContents(ids: [""<ID>""]) { queryContentsByIds(ids: [""<ID>""]) {
... on Content { ... on Content {
data: data__dynamic data: data__dynamic
} }
@ -152,7 +152,7 @@ public class GraphQLQueriesTests : GraphQLTestBase
{ {
data = new data = new
{ {
queryContents = new[] queryContentsByIds = new[]
{ {
new new
{ {

27
tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs

@ -227,6 +227,29 @@ public sealed class GraphQLTests : IClassFixture<GraphQLFixture>
Assert.Equal(new[] { "Saxony" }, stateNames); 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<JToken>(query);
var cityNames =
result["cities"]
.Select(x => x["data__dynamic"]["name"]["iv"].Value<string>())
.Order();
Assert.Equal(new[] { "Leipzig", "Munich" }, cityNames);
}
[Fact] [Fact]
public async Task Should_query_correct_content_type_for_graphql() public async Task Should_query_correct_content_type_for_graphql()
{ {
@ -260,7 +283,7 @@ public sealed class GraphQLTests : IClassFixture<GraphQLFixture>
{ {
query = @" query = @"
query ContentsQuery($ids: [String!]!) { query ContentsQuery($ids: [String!]!) {
queryContents(ids: $ids) { queryContentsByIds(ids: $ids) {
... on Content { ... on Content {
id id
} }
@ -285,7 +308,7 @@ public sealed class GraphQLTests : IClassFixture<GraphQLFixture>
var result = await _.Client.SharedDynamicContents.GraphQlAsync<JToken>(query); var result = await _.Client.SharedDynamicContents.GraphQlAsync<JToken>(query);
var names = var names =
result["queryContents"] result["queryContentsByIds"]
.Select(x => x["data"]["name"].Value<string>()) .Select(x => x["data"]["name"].Value<string>())
.Order(); .Order();

Loading…
Cancel
Save