Browse Source

Variables fix.

pull/567/head
Sebastian 5 years ago
parent
commit
b62581d8e0
  1. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLModel.cs
  2. 6
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLQuery.cs
  3. 18
      backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs
  4. 31
      backend/src/Squidex/Areas/Api/Controllers/Contents/Models/GraphQLGetDto.cs
  5. 32
      backend/src/Squidex/Areas/Api/Controllers/Contents/Models/GraphQLPostDto.cs
  6. 20
      backend/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs

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

@ -170,7 +170,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
context.Setup(execution); context.Setup(execution);
execution.Schema = graphQLSchema; execution.Schema = graphQLSchema;
execution.Inputs = query.Variables?.ToInputs(); execution.Inputs = query.Inputs;
execution.Query = query.Query; execution.Query = query.Query;
}).ConfigureAwait(false); }).ConfigureAwait(false);

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

@ -5,7 +5,7 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using Newtonsoft.Json.Linq; using GraphQL;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{ {
@ -13,10 +13,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{ {
public string OperationName { get; set; } public string OperationName { get; set; }
public string NamedQuery { get; set; }
public string Query { get; set; } public string Query { get; set; }
public JObject Variables { get; set; } public Inputs? Inputs { get; set; }
} }
} }

18
backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs

@ -55,9 +55,11 @@ namespace Squidex.Areas.Api.Controllers.Contents
[Route("content/{app}/graphql/")] [Route("content/{app}/graphql/")]
[ApiPermission] [ApiPermission]
[ApiCosts(2)] [ApiCosts(2)]
public async Task<IActionResult> GetGraphQL(string app, [FromQuery] GraphQLQuery? queries = null) public async Task<IActionResult> GetGraphQL(string app, [FromQuery] GraphQLGetDto? queries = null)
{ {
var (hasError, response) = await graphQl.QueryAsync(Context, queries ?? new GraphQLQuery()); var request = queries?.ToQuery() ?? new GraphQLQuery();
var (hasError, response) = await graphQl.QueryAsync(Context, request);
if (hasError) if (hasError)
{ {
@ -85,9 +87,11 @@ namespace Squidex.Areas.Api.Controllers.Contents
[Route("content/{app}/graphql/")] [Route("content/{app}/graphql/")]
[ApiPermission] [ApiPermission]
[ApiCosts(2)] [ApiCosts(2)]
public async Task<IActionResult> PostGraphQL(string app, [FromBody] GraphQLQuery query) public async Task<IActionResult> PostGraphQL(string app, [FromBody] GraphQLPostDto query)
{ {
var (hasError, response) = await graphQl.QueryAsync(Context, query); var request = query?.ToQuery() ?? new GraphQLQuery();
var (hasError, response) = await graphQl.QueryAsync(Context, request);
if (hasError) if (hasError)
{ {
@ -115,9 +119,11 @@ namespace Squidex.Areas.Api.Controllers.Contents
[Route("content/{app}/graphql/batch")] [Route("content/{app}/graphql/batch")]
[ApiPermission] [ApiPermission]
[ApiCosts(2)] [ApiCosts(2)]
public async Task<IActionResult> PostGraphQLBatch(string app, [FromBody] GraphQLQuery[] batch) public async Task<IActionResult> PostGraphQLBatch(string app, [FromBody] GraphQLPostDto[] batch)
{ {
var (hasError, response) = await graphQl.QueryAsync(Context, batch); var request = batch.Select(x => x.ToQuery()).ToArray();
var (hasError, response) = await graphQl.QueryAsync(Context, request);
if (hasError) if (hasError)
{ {

31
backend/src/Squidex/Areas/Api/Controllers/Contents/Models/GraphQLGetDto.cs

@ -0,0 +1,31 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using GraphQL;
using Squidex.Domain.Apps.Entities.Contents.GraphQL;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Areas.Api.Controllers.Contents.Models
{
public class GraphQLGetDto
{
public string OperationName { get; set; }
public string Query { get; set; }
public string Variables { get; set; }
public GraphQLQuery ToQuery()
{
var query = SimpleMapper.Map(this, new GraphQLQuery());
query.Inputs = Variables?.ToInputs();
return query;
}
}
}

32
backend/src/Squidex/Areas/Api/Controllers/Contents/Models/GraphQLPostDto.cs

@ -0,0 +1,32 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using GraphQL;
using Newtonsoft.Json.Linq;
using Squidex.Domain.Apps.Entities.Contents.GraphQL;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Areas.Api.Controllers.Contents.Models
{
public class GraphQLPostDto
{
public string OperationName { get; set; }
public string Query { get; set; }
public JObject Variables { get; set; }
public GraphQLQuery ToQuery()
{
var query = SimpleMapper.Map(this, new GraphQLQuery());
query.Inputs = Variables?.ToInputs();
return query;
}
}
}

20
backend/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs

@ -185,8 +185,8 @@ namespace TestSuite.ApiTests
var query = new var query = new
{ {
query = @" query = @"
{ query ContentsQuery($filter: String!) {
queryMyReadsContents(filter: ""data/number/iv gt 3 and data/number/iv lt 7"", orderby: ""data/number/iv asc"") { queryMyReadsContents(filter: $filter, orderby: ""data/number/iv asc"") {
id, id,
data { data {
number { number {
@ -194,7 +194,11 @@ namespace TestSuite.ApiTests
} }
} }
} }
}" }",
variables = new
{
filter = @"data/number/iv gt 3 and data/number/iv lt 7"
}
}; };
var result = await _.Contents.GraphQlAsync<QueryResult>(query); var result = await _.Contents.GraphQlAsync<QueryResult>(query);
@ -210,8 +214,8 @@ namespace TestSuite.ApiTests
var query = new var query = new
{ {
query = @" query = @"
{ query ContentsQuery($filter: String!) {
queryMyReadsContents(filter: ""data/number/iv gt 3 and data/number/iv lt 7"", orderby: ""data/number/iv asc"") { queryMyReadsContents(filter: $filter, orderby: ""data/number/iv asc"") {
id, id,
data { data {
number { number {
@ -219,7 +223,11 @@ namespace TestSuite.ApiTests
} }
} }
} }
}" }",
variables = new
{
filter = @"data/number/iv gt 3 and data/number/iv lt 7"
}
}; };
var result = await _.Contents.GraphQlGetAsync<QueryResult>(query); var result = await _.Contents.GraphQlGetAsync<QueryResult>(query);

Loading…
Cancel
Save