From ee4e2d62c2944f46c65933dfb62c608cb8161b5a Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Aug 2022 15:08:29 +1000 Subject: [PATCH] GraphQL 7 --- readme.md | 26 ++-- src/Directory.Build.props | 2 +- .../GraphQL.FluentValidation.csproj | 2 +- ...aphQLControllerTests.RunQuery.verified.txt | 2 +- src/SampleWeb.Tests/SampleWeb.Tests.csproj | 2 +- src/SampleWeb/Query.cs | 24 ++-- src/SampleWeb/SampleWeb.csproj | 10 +- src/SampleWeb/Startup.cs | 4 - src/Tests/Arguments/ComplexInputInnerGraph.cs | 3 +- .../Arguments/ComplexInputListItemGraph.cs | 6 +- src/Tests/Query.cs | 126 +++++++++--------- src/Tests/Tests.csproj | 2 +- 12 files changed, 92 insertions(+), 117 deletions(-) diff --git a/readme.md b/readme.md index 07ee84b8..4cfaff4a 100644 --- a/readme.md +++ b/readme.md @@ -210,26 +210,20 @@ public class Query : ObjectGraphType { public Query() => - Field( - "inputQuery", - arguments: new( - new QueryArgument + Field("inputQuery") + .Argument("input") + .Resolve(context => { - Name = "input" + var input = context.GetValidatedArgument("input"); + return new Result + { + Data = input.Content + }; } - ), - resolve: context => - { - var input = context.GetValidatedArgument("input"); - return new Result - { - Data = input.Content - }; - } - ); + ); } ``` -snippet source | anchor +snippet source | anchor diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c1946532..bb01b6a0 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - 7.2.1 + 8.0.0 1.0.0 GraphQL, Validation, FluentValidation Add FluentValidation (https://fluentvalidation.net/) support to GraphQL.net (https://github.com/graphql-dotnet/graphql-dotnet) diff --git a/src/GraphQL.FluentValidation/GraphQL.FluentValidation.csproj b/src/GraphQL.FluentValidation/GraphQL.FluentValidation.csproj index 88d735db..d08a8ce2 100644 --- a/src/GraphQL.FluentValidation/GraphQL.FluentValidation.csproj +++ b/src/GraphQL.FluentValidation/GraphQL.FluentValidation.csproj @@ -4,7 +4,7 @@ - + diff --git a/src/SampleWeb.Tests/GraphQLControllerTests.RunQuery.verified.txt b/src/SampleWeb.Tests/GraphQLControllerTests.RunQuery.verified.txt index 5eedf3f3..a96ce8fe 100644 --- a/src/SampleWeb.Tests/GraphQLControllerTests.RunQuery.verified.txt +++ b/src/SampleWeb.Tests/GraphQLControllerTests.RunQuery.verified.txt @@ -3,7 +3,7 @@ Status: 200 OK, Content: { Headers: { - Content-Type: application/json + Content-Type: application/graphql+json; charset=utf-8 }, Value: { data: { diff --git a/src/SampleWeb.Tests/SampleWeb.Tests.csproj b/src/SampleWeb.Tests/SampleWeb.Tests.csproj index 759e43da..9457bd14 100644 --- a/src/SampleWeb.Tests/SampleWeb.Tests.csproj +++ b/src/SampleWeb.Tests/SampleWeb.Tests.csproj @@ -4,7 +4,7 @@ - + diff --git a/src/SampleWeb/Query.cs b/src/SampleWeb/Query.cs index 94bb14c3..b4ce04c3 100644 --- a/src/SampleWeb/Query.cs +++ b/src/SampleWeb/Query.cs @@ -7,23 +7,17 @@ public class Query : ObjectGraphType { public Query() => - Field( - "inputQuery", - arguments: new( - new QueryArgument + Field("inputQuery") + .Argument("input") + .Resolve(context => { - Name = "input" + var input = context.GetValidatedArgument("input"); + return new Result + { + Data = input.Content + }; } - ), - resolve: context => - { - var input = context.GetValidatedArgument("input"); - return new Result - { - Data = input.Content - }; - } - ); + ); } #endregion \ No newline at end of file diff --git a/src/SampleWeb/SampleWeb.csproj b/src/SampleWeb/SampleWeb.csproj index f6edda01..9b61b7f6 100644 --- a/src/SampleWeb/SampleWeb.csproj +++ b/src/SampleWeb/SampleWeb.csproj @@ -4,12 +4,12 @@ - - + + - - - + + + diff --git a/src/SampleWeb/Startup.cs b/src/SampleWeb/Startup.cs index fca78ae2..64dbf213 100644 --- a/src/SampleWeb/Startup.cs +++ b/src/SampleWeb/Startup.cs @@ -1,8 +1,5 @@ using FluentValidation; using GraphQL; -using GraphQL.MicrosoftDI; -using GraphQL.Server; -using GraphQL.SystemTextJson; using GraphQL.Types; public class Startup @@ -16,7 +13,6 @@ public void ConfigureServices(IServiceCollection services) services.AddValidatorsFromAssemblyContaining(); services.AddGraphQL(builder => builder - .AddHttpMiddleware() .AddSchema() .ConfigureExecutionOptions(options => { diff --git a/src/Tests/Arguments/ComplexInputInnerGraph.cs b/src/Tests/Arguments/ComplexInputInnerGraph.cs index cb7a636d..06a81931 100644 --- a/src/Tests/Arguments/ComplexInputInnerGraph.cs +++ b/src/Tests/Arguments/ComplexInputInnerGraph.cs @@ -4,7 +4,6 @@ public class ComplexInputInnerGraph : InputObjectGraphType { public ComplexInputInnerGraph() => - Field() - .Name("content") + Field("content") .Resolve(ctx => ctx.Source.Content); } \ No newline at end of file diff --git a/src/Tests/Arguments/ComplexInputListItemGraph.cs b/src/Tests/Arguments/ComplexInputListItemGraph.cs index 878d5148..4a653619 100644 --- a/src/Tests/Arguments/ComplexInputListItemGraph.cs +++ b/src/Tests/Arguments/ComplexInputListItemGraph.cs @@ -5,12 +5,10 @@ public class ComplexInputListItemGraph : { public ComplexInputListItemGraph() { - Field>() - .Name("id") + Field>("id") .Resolve(ctx => ctx.Source.Id); - Field() - .Name("content") + Field("content") .Resolve(ctx => ctx.Source.Content); } } \ No newline at end of file diff --git a/src/Tests/Query.cs b/src/Tests/Query.cs index 860840dd..b7fadbad 100644 --- a/src/Tests/Query.cs +++ b/src/Tests/Query.cs @@ -7,81 +7,75 @@ public class Query : { public Query() { - Field( - "noValidatorQuery", - arguments: new(new QueryArgument { Name = "input"}), - resolve: context => - { - var input = context.GetValidatedArgument("input"); - return new Result + Field("noValidatorQuery") + .Argument("input") + .Resolve(context => { - Data = input?.Content ?? "it was null" - }; - } - ); - Field( - "inputQuery", - arguments: new(new QueryArgument { Name = "input"}), - resolve: context => - { - var input = context.GetValidatedArgument("input"); - return new Result + var input = context.GetValidatedArgument("input"); + return new Result + { + Data = input?.Content ?? "it was null" + }; + } + ); + Field("inputQuery") + .Argument("input") + .Resolve(context => { - Data = input?.Content ?? "it was null" - }; - } - ); + var input = context.GetValidatedArgument("input"); + return new Result + { + Data = input?.Content ?? "it was null" + }; + } + ); - Field( - "complexInputQuery", - arguments: new(new QueryArgument { Name = "input" }), - resolve: context => - { - var input = context.GetValidatedArgument("input"); - return new Result + Field("complexInputQuery") + .Argument("input") + .Resolve(context => { - Data = JsonConvert.SerializeObject(input) - }; - } - ); + var input = context.GetValidatedArgument("input"); + return new Result + { + Data = JsonConvert.SerializeObject(input) + }; + } + ); - Field( - "derivedComplexInputQuery", - arguments: new(new QueryArgument { Name = "input" }), - resolve: context => - { - var input = context.GetValidatedArgument("input"); - return new Result + Field("derivedComplexInputQuery") + .Argument("input") + .Resolve(context => { - Data = JsonConvert.SerializeObject(input) - }; - } - ); + var input = context.GetValidatedArgument("input"); + return new Result + { + Data = JsonConvert.SerializeObject(input) + }; + } + ); - FieldAsync( - "asyncQuery", - arguments: new(new QueryArgument { Name = "input" }), - resolve: async context => - { - var input = await context.GetValidatedArgumentAsync("input"); - return new Result + Field("asyncQuery") + .Argument("input") + .ResolveAsync(async context => { - Data = input.Content - }; - } - ); + var input = await context.GetValidatedArgumentAsync("input"); + return new Result + { + Data = input.Content + }; + } + ); - FieldAsync( - "asyncComplexInputQuery", - arguments: new(new QueryArgument { Name = "input" }), - resolve: async context => - { - var input = await context.GetValidatedArgumentAsync("input"); - return new Result + Field("asyncComplexInputQuery") + .Argument("input") + .ResolveAsync(async context => { - Data = input.Inner!.Content - }; - } - ); + var input = await context.GetValidatedArgumentAsync("input"); + return new Result + { + Data = input.Inner!.Content + }; + } + ); } } \ No newline at end of file diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 9af266d3..d5b84fe4 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -4,7 +4,7 @@ - +