From be60ed2ae2932082333b55b5708e62d1276c81f6 Mon Sep 17 00:00:00 2001 From: Pierre Leandre Date: Mon, 4 Jul 2022 14:56:00 +0800 Subject: [PATCH] Update to GraphQL 5.3 (#232) * Update to GraphQL 5.3, Bump to 5.3 * Fix samples * Fix subscription Co-authored-by: Shane Krueger * Remove unused code Co-authored-by: Pierre leandre Co-authored-by: Shane Krueger --- .../DataLoaderWithEFCore.csproj | 22 ++--- .../GraphApi/GraphController.cs | 10 +- .../GraphApi/Schema/Mutation.cs | 9 +- .../GraphApi/Schema/OutputTypes/Actor.cs | 4 +- .../GraphApi/Schema/OutputTypes/Movie.cs | 4 +- .../GraphApi/Schema/Query.cs | 13 ++- .../GraphApi/UserContext.cs | 22 ----- .../DataLoaderWithEFCore/Program.cs | 9 +- .../DataLoaderWithEFCore/Startup.cs | 18 ++-- samples/SimpleWebApp/Program.cs | 3 +- .../Properties/launchSettings.json | 12 +++ samples/SimpleWebApp/SimpleWebApp.csproj | 9 +- samples/SimpleWebApp/Startup.cs | 6 +- .../Controllers/GraphController.cs | 58 ----------- .../SubscriptionExample/Program.cs | 9 +- .../SubscriptionExample/Startup.cs | 99 +++++++++++-------- .../SubscriptionExample.csproj | 19 ++-- .../Adapters/Engine/DocumentExecuter.cs | 4 +- .../DefaultErrorTransformation.cs | 5 +- .../Adapters/Engine/GraphQLEngine.cs | 24 +++-- .../Adapters/Engine/GraphQLExecutor.cs | 8 +- .../Adapters/Engine/IGraphQLExecutor.cs | 4 +- .../Adapters/GraphTypeAdapter.cs | 12 ++- .../Adapters/ResolutionContext.cs | 15 ++- .../Adapters/Resolvers/EventStreamResolver.cs | 21 ++-- .../Adapters/Resolvers/FieldResolver.cs | 12 +-- .../Resolvers/WrappedAsyncFieldResolver.cs | 4 +- .../Resolvers/WrappedSyncFieldResolver.cs | 5 +- .../Adapters/Types/GuidGraphType.cs | 6 +- .../Adapters/Types/Relay/CursorGraphType.cs | 6 +- .../Adapters/Types/TimeSpanGraphType.cs | 6 +- .../Adapters/Types/UriGraphType.cs | 6 +- .../Adapters/Types/UrlGraphType.cs | 6 +- .../Execution/IResolutionContext.cs | 2 +- .../GraphQL.Conventions.csproj | 14 +-- src/GraphQL.Conventions/Web/RequestHandler.cs | 6 +- src/GraphQL.Conventions/Web/Response.cs | 9 +- .../Adapters/ArgumentResolutionTests.cs | 8 +- .../Bugs/Bug73NullableInputListTests.cs | 2 +- .../Engine/DependencyInjectionTests.cs | 11 ++- .../Engine/DynamicConstructionTests.cs | 6 +- .../Adapters/Engine/GraphQLExecutorTests.cs | 4 +- .../Adapters/Engine/Types/CustomGraphType.cs | 6 +- .../Engine/Types/CustomJsonGraphType.cs | 24 ++--- .../Adapters/EventStreamResolverTest.cs | 27 +++-- .../Adapters/FieldDerivationTests.cs | 2 +- .../Adapters/TypeConstructionTests.cs | 4 +- .../Adapters/Types/GuidGraphTypeTests.cs | 8 +- .../Adapters/Types/ScalarTypeTestBase.cs | 4 +- .../Adapters/Types/TimeSpanGraphTypeTests.cs | 12 +-- .../Adapters/Types/UriGraphTypeTests.cs | 18 ++-- .../Adapters/Types/UrlGraphTypeTests.cs | 18 ++-- .../Relay/RelayMutationAttributeTests.cs | 2 +- .../FieldTypeMetaDataAttributeTests.cs | 13 ++- .../GraphQL.Conventions.Tests.csproj | 16 +-- .../Web/RequestHandlerTests.cs | 14 +-- .../Web/ResponseTests.cs | 2 +- 57 files changed, 327 insertions(+), 375 deletions(-) delete mode 100644 samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/UserContext.cs create mode 100644 samples/SimpleWebApp/Properties/launchSettings.json delete mode 100644 samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Controllers/GraphController.cs diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/DataLoaderWithEFCore.csproj b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/DataLoaderWithEFCore.csproj index fc68a5b6..3eb7f2b7 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/DataLoaderWithEFCore.csproj +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/DataLoaderWithEFCore.csproj @@ -1,13 +1,10 @@  - netcoreapp2.1 + net6.0 + 9.0 - - - 7.3 - - + @@ -16,12 +13,13 @@ - - - - - - + + + + + + + diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/GraphController.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/GraphController.cs index 23f86040..e9da09dc 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/GraphController.cs +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/GraphController.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Net; using System.Threading.Tasks; -using GraphQL; using GraphQL.Conventions; using Microsoft.AspNetCore.Mvc; @@ -13,13 +12,11 @@ namespace DataLoaderWithEFCore.GraphApi public class GraphController : ControllerBase { private readonly GraphQLEngine _engine; - private readonly IUserContext _userContext; private readonly IDependencyInjector _injector; - public GraphController(GraphQLEngine engine, IUserContext userContext, IDependencyInjector injector) + public GraphController(GraphQLEngine engine, IDependencyInjector injector) { _engine = engine; - _userContext = userContext; _injector = injector; } @@ -30,12 +27,11 @@ public async Task Post() using (var reader = new StreamReader(Request.Body)) requestBody = await reader.ReadToEndAsync(); - ExecutionResult result = await _engine + var result = await _engine .NewExecutor() - .WithUserContext(_userContext) .WithDependencyInjector(_injector) .WithRequest(requestBody) - .Execute(); + .ExecuteAsync(); var responseBody = _engine.SerializeResult(result); diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Mutation.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Mutation.cs index b3a8da26..addf053f 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Mutation.cs +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Mutation.cs @@ -7,7 +7,14 @@ namespace DataLoaderWithEFCore.GraphApi.Schema { public sealed class Mutation { + private readonly IMapper _mapper; + + public Mutation(IMapper mapper) + { + _mapper = mapper; + } + public async Task UpdateMovieTitle([Inject] IMovieRepository movieRepository, UpdateMovieTitleParams @params) - => Mapper.Map(await movieRepository.UpdateMovieTitle(@params.Id, @params.NewTitle)); + => _mapper.Map(await movieRepository.UpdateMovieTitle(@params.Id, @params.NewTitle)); } } diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Actor.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Actor.cs index 88c3a73b..0a345a7e 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Actor.cs +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Actor.cs @@ -18,10 +18,10 @@ public sealed class Actor public Guid MovieId { get; set; } - public async Task Country([Inject] ICountryRepository repository, [Inject] DataLoaderContext dataLoaderContext) + public async Task Country([Inject] IMapper mapper, [Inject] ICountryRepository repository, [Inject] DataLoaderContext dataLoaderContext) { var loader = dataLoaderContext.GetOrAddBatchLoader("Actor_Country", repository.GetCountries); - return Mapper.Map(await loader.LoadAsync(CountryCode)); + return mapper.Map(await loader.LoadAsync(CountryCode).GetResultAsync()); } } } diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Movie.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Movie.cs index bd2bcd15..292837d0 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Movie.cs +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Movie.cs @@ -18,10 +18,10 @@ public sealed class Movie public DateTime ReleaseDateUtc { get; set; } - public async Task Actors([Inject] IActorRepository repository, [Inject] DataLoaderContext dataLoaderContext) + public async Task Actors([Inject] IMapper mapper, [Inject] IActorRepository repository, [Inject] DataLoaderContext dataLoaderContext) { var loader = dataLoaderContext.GetOrAddCollectionBatchLoader("Movie_Actors", repository.GetActorsPerMovie); - return Mapper.Map(await loader.LoadAsync(Id)); + return mapper.Map(await loader.LoadAsync(Id).GetResultAsync()); } } } diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Query.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Query.cs index c1e25aca..7ed3fec5 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Query.cs +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Query.cs @@ -8,10 +8,19 @@ namespace DataLoaderWithEFCore.GraphApi.Schema { public sealed class Query { + private readonly IMapper _mapper; + + public Query(IMapper mapper) + { + _mapper = mapper; + } + public async Task Movie([Inject] IMovieRepository repository, Guid id) - => Mapper.Map(await repository.FindMovie(id)); + { + return _mapper.Map(await repository.FindMovie(id)); + } public async Task Movies([Inject] IMovieRepository repository) - => Mapper.Map(await repository.GetMovies()); + => _mapper.Map(await repository.GetMovies()); } } diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/UserContext.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/UserContext.cs deleted file mode 100644 index cb837e7e..00000000 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/UserContext.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using GraphQL.Conventions; -using GraphQL.DataLoader; - -namespace DataLoaderWithEFCore.GraphApi -{ - public class UserContext : IUserContext, IDataLoaderContextProvider - { - public DataLoaderContext _context { get; private set; } - - public UserContext(DataLoaderContext context) - { - _context = context; - } - - public Task FetchData(CancellationToken token) - { - return _context.DispatchAllAsync(token); - } - } -} diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Program.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Program.cs index 4087848e..89d06431 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Program.cs +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Program.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; namespace DataLoaderWithEFCore { diff --git a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Startup.cs b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Startup.cs index 9cdeb38e..a39d0611 100644 --- a/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Startup.cs +++ b/samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Startup.cs @@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Schema = DataLoaderWithEFCore.GraphApi.Schema; namespace DataLoaderWithEFCore @@ -26,8 +27,6 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); - services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); @@ -35,22 +34,21 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddScoped(); - services.AddSingleton(provider => new GraphQLEngine() + services.AddSingleton(_ => new GraphQLEngine() .WithFieldResolutionStrategy(FieldResolutionStrategy.Normal) .BuildSchema(typeof(SchemaDefinition))); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); - - Mapper.Initialize(config => config.AddProfile()); + services.AddAutoMapper(typeof(Mappings)); + services.AddControllers(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { @@ -62,7 +60,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) } app.UseHttpsRedirection(); - app.UseMvc(); + app.UseRouting(); + app.UseEndpoints(configure => + { + configure.MapControllers(); + }); } } } diff --git a/samples/SimpleWebApp/Program.cs b/samples/SimpleWebApp/Program.cs index e3bb7ab0..8196fc17 100644 --- a/samples/SimpleWebApp/Program.cs +++ b/samples/SimpleWebApp/Program.cs @@ -1,6 +1,6 @@ using System.IO; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; namespace GraphQL.Conventions.Tests.Server { @@ -13,6 +13,7 @@ public static void Main(string[] args) .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() + .ConfigureLogging(l => l.AddConsole()) .Build(); host.Run(); diff --git a/samples/SimpleWebApp/Properties/launchSettings.json b/samples/SimpleWebApp/Properties/launchSettings.json new file mode 100644 index 00000000..786098f4 --- /dev/null +++ b/samples/SimpleWebApp/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "SimpleWebApp": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:64575;http://localhost:64576" + } + } +} \ No newline at end of file diff --git a/samples/SimpleWebApp/SimpleWebApp.csproj b/samples/SimpleWebApp/SimpleWebApp.csproj index 874898c2..f4aedde6 100755 --- a/samples/SimpleWebApp/SimpleWebApp.csproj +++ b/samples/SimpleWebApp/SimpleWebApp.csproj @@ -1,11 +1,9 @@ - netcoreapp1.0 - - - - 7.3 + net6.0 + 9.0 + GraphQL.Conventions.Tests.Server @@ -13,7 +11,6 @@ - diff --git a/samples/SimpleWebApp/Startup.cs b/samples/SimpleWebApp/Startup.cs index 09181ac8..177b90fe 100644 --- a/samples/SimpleWebApp/Startup.cs +++ b/samples/SimpleWebApp/Startup.cs @@ -21,8 +21,6 @@ public void ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - loggerFactory.AddConsole(); - var dependencyInjector = new DependencyInjector(); dependencyInjector.Register(new BookRepository()); dependencyInjector.Register(new AuthorRepository()); @@ -54,10 +52,10 @@ private async Task HandleRequest(HttpContext context) var body = streamReader.ReadToEnd(); var userContext = new UserContext(); var result = await _requestHandler - .ProcessRequest(Request.New(body), userContext); + .ProcessRequestAsync(Request.New(body), userContext); context.Response.Headers.Add("Content-Type", "application/json; charset=utf-8"); context.Response.StatusCode = result.Errors?.Count > 0 ? 400 : 200; - await context.Response.WriteAsync(result.Body); + await context.Response.WriteAsync(result.GetBody()); } } } diff --git a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Controllers/GraphController.cs b/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Controllers/GraphController.cs deleted file mode 100644 index cc8971c9..00000000 --- a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Controllers/GraphController.cs +++ /dev/null @@ -1,58 +0,0 @@ -using GraphQL; -using GraphQL.Conventions; -using Microsoft.AspNetCore.Mvc; -using System.IO; -using System.Linq; -using System.Net; -using System.Threading.Tasks; - -namespace SubscriptionExample.Controllers -{ - [ApiController] - [Route("graphql")] - public sealed class GraphController : ControllerBase - { - private readonly GraphQLEngine _engine; - private readonly IDependencyInjector _injector; - - public GraphController(GraphQLEngine engine, IDependencyInjector injector) - { - _engine = engine; - _injector = injector; - } - - [HttpPost] - public async Task Post() - { - string requestBody; - using (var reader = new StreamReader(Request.Body)) - requestBody = await reader.ReadToEndAsync(); - - ExecutionResult result = await _engine - .NewExecutor() - .WithDependencyInjector(_injector) - .WithRequest(requestBody) - .Execute(); - - var responseBody = _engine.SerializeResult(result); - - HttpStatusCode statusCode = HttpStatusCode.OK; - - if (result.Errors?.Any() ?? false) - { - statusCode = HttpStatusCode.InternalServerError; - if (result.Errors.Any(x => x.Code == "VALIDATION_ERROR")) - statusCode = HttpStatusCode.BadRequest; - else if (result.Errors.Any(x => x.Code == "UNAUTHORIZED_ACCESS")) - statusCode = HttpStatusCode.Forbidden; - } - - return new ContentResult - { - Content = responseBody, - ContentType = "application/json; charset=utf-8", - StatusCode = (int)statusCode - }; - } - } -} \ No newline at end of file diff --git a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Program.cs b/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Program.cs index ea9359a1..88d3c43f 100644 --- a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Program.cs +++ b/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Program.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; namespace SubscriptionExample { diff --git a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Startup.cs b/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Startup.cs index a3083a2d..de46d0ec 100644 --- a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Startup.cs +++ b/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Startup.cs @@ -1,20 +1,25 @@ -using GraphQL; +using System.Threading.Tasks; +using GraphQL; using GraphQL.Conventions; using GraphQL.Conventions.Adapters; using GraphQL.Conventions.Builders; -using GraphQL.Http; +using GraphQL.Conventions.Types.Resolution; +using GraphQL.DataLoader; +using GraphQL.MicrosoftDI; +using GraphQL.NewtonsoftJson; using GraphQL.Server; -using GraphQL.Server.Internal; -using GraphQL.Server.Transports.Subscriptions.Abstractions; -using GraphQL.Server.Transports.WebSockets; -using GraphQL.Server.Ui.Playground; +using GraphQL.Server.Transports.AspNetCore; +using GraphQL.SystemTextJson; using GraphQL.Types; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Newtonsoft.Json; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using SubscriptionExample.Core; +using SubscriptionExample.GraphQl; +using DocumentExecuter = GraphQL.Conventions.DocumentExecuter; namespace SubscriptionExample { @@ -24,49 +29,63 @@ public class Startup // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - var typeAdapter = new GraphTypeAdapter(); - var constructor = new SchemaConstructor(typeAdapter); - var schema = constructor.Build(typeof(SchemaDefinition)); - var graphQLEngine = new GraphQLEngine() + services.AddSingleton(); + + // Graph QL Server Services + services.AddGraphQL(builder => + { + builder + .AddHttpMiddleware>() + .AddWebSocketsHttpMiddleware() + .AddDefaultEndpointSelectorPolicy() + .AddSystemTextJson() + .AddErrorInfoProvider(option => + { + option.ExposeExceptionStackTrace = true; + }) + .AddDataLoader() + .AddWebSockets() + .ConfigureExecutionOptions(options => + { + options.EnableMetrics = true; + var logger = options.RequestServices.GetRequiredService>(); + options.UnhandledExceptionDelegate = ctx => + { + logger.LogError($"GraphQL Unhandled Exception: {ctx.ErrorMessage}.", ctx.OriginalException); + return Task.CompletedTask; + }; + }); + }); + + // Graph QL Convention: Engine and Schema + var engine = new GraphQLEngine() .WithFieldResolutionStrategy(FieldResolutionStrategy.Normal) - .WithQuery() - .WithMutation() - .WithSubscription() + .WithQuery() + .WithMutation() + .WithSubscription() .BuildSchema(); - services.AddSingleton(); + var schema = engine.GetSchema(); + + // Add Graph QL Convention Services + services.AddSingleton(engine); services.AddSingleton(schema); - services.AddMvc(); services.AddTransient(); - services.AddSingleton(provider => graphQLEngine); - services.AddSingleton(); - services.AddSingleton(x => - { - var jsonSerializerSettings = x.GetRequiredService>(); - return new DocumentWriter(Formatting.None, jsonSerializerSettings.Value); - }); - services.AddTransient(typeof(IGraphQLExecuter<>), typeof(DefaultGraphQLExecuter<>)); - services.AddTransient, WebSocketConnectionFactory>(); - services.AddTransient(); - services.AddTransient(); + + // Replace GraphQL Server with GraphQL Convention Document Executer + services.Replace(new ServiceDescriptor(typeof(IDocumentExecuter), typeof(DocumentExecuter), ServiceLifetime.Singleton)); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseMvc(); app.UseWebSockets(); - app.UseGraphQLWebSockets(); - - app.UseGraphQLPlayground(new GraphQLPlaygroundOptions() + app.UseRouting(); + app.UseEndpoints(endpoints => { - Path = "/ui/playground", - GraphQLEndPoint = "/graphql" + endpoints.MapGraphQLWebSockets(); + endpoints.MapGraphQL(); + endpoints.MapGraphQLPlayground(); }); } } diff --git a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/SubscriptionExample.csproj b/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/SubscriptionExample.csproj index 580affa3..9cc03182 100644 --- a/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/SubscriptionExample.csproj +++ b/samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/SubscriptionExample.csproj @@ -1,22 +1,21 @@ - netcoreapp2.2 + net6.0 InProcess Linux 753d5ae8-af8c-469c-963e-7c45ef13bd7d - - - - 7.3 + 9.0 - - - - - + + + + + + + diff --git a/src/GraphQL.Conventions/Adapters/Engine/DocumentExecuter.cs b/src/GraphQL.Conventions/Adapters/Engine/DocumentExecuter.cs index 94b80afc..a0a08c94 100644 --- a/src/GraphQL.Conventions/Adapters/Engine/DocumentExecuter.cs +++ b/src/GraphQL.Conventions/Adapters/Engine/DocumentExecuter.cs @@ -27,7 +27,7 @@ public async Task ExecuteAsync(ISchema schema, object root, str .WithRootObject(root) .WithQueryString(query) .WithOperationName(operationName) - .WithInputs(inputs) + .WithVariables(inputs) .WithCancellationToken(cancellationToken) .WithValidationRules(rules) .ExecuteAsync(); @@ -41,7 +41,7 @@ public async Task ExecuteAsync(ExecutionOptions options) .WithRootObject(options.Root) .WithQueryString(options.Query) .WithOperationName(options.OperationName) - .WithInputs(options.Inputs) + .WithVariables(options.Variables) .WithCancellationToken(options.CancellationToken) .WithValidationRules(options.ValidationRules) .ExecuteAsync(); diff --git a/src/GraphQL.Conventions/Adapters/Engine/ErrorTransformations/DefaultErrorTransformation.cs b/src/GraphQL.Conventions/Adapters/Engine/ErrorTransformations/DefaultErrorTransformation.cs index da494765..31a051d1 100644 --- a/src/GraphQL.Conventions/Adapters/Engine/ErrorTransformations/DefaultErrorTransformation.cs +++ b/src/GraphQL.Conventions/Adapters/Engine/ErrorTransformations/DefaultErrorTransformation.cs @@ -1,5 +1,6 @@ using System.Linq; using GraphQL.Conventions.Execution; +using GraphQLParser; namespace GraphQL.Conventions.Adapters.Engine.ErrorTransformations { @@ -10,9 +11,9 @@ public ExecutionErrors Transform(ExecutionErrors errors) { var exception = new FieldResolutionException(executionError); var error = new ExecutionError(exception.Message, exception); - foreach (var location in executionError.Locations ?? Enumerable.Empty()) + foreach (var location in executionError.Locations ?? Enumerable.Empty()) { - error.AddLocation(location.Line, location.Column); + error.AddLocation(location); } error.Path = executionError.Path; result.Add(error); diff --git a/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs b/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs index 818bad00..02e23078 100644 --- a/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs +++ b/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs @@ -9,15 +9,16 @@ using GraphQL.Conventions.Adapters.Engine.Listeners.DataLoader; using GraphQL.Conventions.Builders; using GraphQL.Conventions.Extensions; +using GraphQL.Conventions.Relay; using GraphQL.Conventions.Types.Resolution; using GraphQL.Execution; using GraphQL.Instrumentation; -using GraphQL.Language.AST; using GraphQL.NewtonsoftJson; using GraphQL.Types; using GraphQL.Utilities; using GraphQL.Validation; using GraphQL.Validation.Complexity; +using GraphQLParser.AST; // ReSharper disable once CheckNamespace namespace GraphQL.Conventions @@ -36,7 +37,7 @@ public class GraphQLEngine private readonly DocumentValidator _documentValidator = new DocumentValidator(); - private readonly DocumentWriter _documentWriter = new DocumentWriter(); + private readonly GraphQLSerializer _documentSerializer = new GraphQLSerializer(); private SchemaPrinter _schemaPrinter; @@ -57,15 +58,14 @@ public class GraphQLEngine private class NoopValidationRule : IValidationRule { - public Task ValidateAsync(ValidationContext context) - => Task.FromResult(new NoopNodeVisitor()); + public ValueTask ValidateAsync(ValidationContext context) => new(new NoopNodeVisitor()); } private class NoopNodeVisitor : INodeVisitor { - public void Enter(INode node, ValidationContext context) { /* Noop */ } + public void Enter(ASTNode node, ValidationContext context) { /* Noop */ } - public void Leave(INode node, ValidationContext context) { /* Noop */ } + public void Leave(ASTNode node, ValidationContext context) { /* Noop */ } } private class WrappedDependencyInjector : IDependencyInjector @@ -270,13 +270,13 @@ public GraphQLEngine RegisterScalarType(string name = null) return this; } - public Task SerializeResultAsync(ExecutionResult result) => _documentWriter.WriteToStringAsync(result); + public string SerializeResult(ExecutionResult result) => _documentSerializer.Serialize(result); internal async Task ExecuteAsync( object rootObject, string query, string operationName, - Inputs inputs, + Inputs variables, IUserContext userContext, IDependencyInjector dependencyInjector, ComplexityConfiguration complexityConfiguration, @@ -300,7 +300,7 @@ internal async Task ExecuteAsync( Root = rootObject, Query = query, OperationName = operationName, - Inputs = inputs, + Variables = variables, EnableMetrics = enableProfiling, UserContext = new Dictionary() { @@ -347,7 +347,11 @@ internal async Task ExecuteAsync( internal async Task ValidateAsync(string queryString) { var document = _documentBuilder.Build(queryString); - var result = await _documentValidator.ValidateAsync(_schema, document, new VariableDefinitions()); + var result = await _documentValidator.ValidateAsync(new ValidationOptions() + { + Schema = _schema, + Document = document + }); return result.validationResult; } diff --git a/src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs b/src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs index 700d6170..42411125 100644 --- a/src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs +++ b/src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs @@ -49,7 +49,7 @@ public IGraphQLExecutor WithRequest(string requestBody) var query = _requestDeserializer.GetQueryFromRequestBody(requestBody); _queryString = query.QueryString; _operationName = query.OperationName; - return this.WithInputs(query.Variables); + return this.WithVariables(query.Variables); } public IGraphQLExecutor WithQueryString(string queryString) @@ -64,12 +64,12 @@ public IGraphQLExecutor WithOperationName(string operationName) return this; } - public IGraphQLExecutor WithInputs(Dictionary inputs) + public IGraphQLExecutor WithVariables(Dictionary inputs) { - return WithInputs(new Inputs(inputs ?? new Dictionary())); + return WithVariables(new Inputs(inputs ?? new Dictionary())); } - public IGraphQLExecutor WithInputs(Inputs inputs) + public IGraphQLExecutor WithVariables(Inputs inputs) { _inputs = inputs; return this; diff --git a/src/GraphQL.Conventions/Adapters/Engine/IGraphQLExecutor.cs b/src/GraphQL.Conventions/Adapters/Engine/IGraphQLExecutor.cs index 0983f1a5..3f40d12f 100644 --- a/src/GraphQL.Conventions/Adapters/Engine/IGraphQLExecutor.cs +++ b/src/GraphQL.Conventions/Adapters/Engine/IGraphQLExecutor.cs @@ -16,9 +16,9 @@ public interface IGraphQLExecutor IGraphQLExecutor WithOperationName(string operationName); - IGraphQLExecutor WithInputs(Inputs inputs); + IGraphQLExecutor WithVariables(Inputs inputs); - IGraphQLExecutor WithInputs(Dictionary inputs); + IGraphQLExecutor WithVariables(Dictionary inputs); IGraphQLExecutor WithRootObject(object rootValue); diff --git a/src/GraphQL.Conventions/Adapters/GraphTypeAdapter.cs b/src/GraphQL.Conventions/Adapters/GraphTypeAdapter.cs index 71b77db9..971c4513 100644 --- a/src/GraphQL.Conventions/Adapters/GraphTypeAdapter.cs +++ b/src/GraphQL.Conventions/Adapters/GraphTypeAdapter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using GraphQL.Conventions.Adapters.Resolvers; using GraphQL.Conventions.Types.Descriptors; using GraphQL.Conventions.Types.Resolution.Extensions; using GraphQL.Resolvers; @@ -85,8 +86,9 @@ private FieldType DeriveField(GraphFieldInfo fieldInfo) { if (fieldInfo.Type.IsObservable) { - var resolver = new Resolvers.EventStreamResolver(fieldInfo); - return new EventStreamFieldType + var resolver = FieldResolverFactory(fieldInfo); + var streamResolver = new EventStreamResolver(resolver); + return new FieldType { Name = fieldInfo.Name, Description = fieldInfo.Description, @@ -94,8 +96,8 @@ private FieldType DeriveField(GraphFieldInfo fieldInfo) DefaultValue = fieldInfo.DefaultValue, Type = GetType(fieldInfo.Type), Arguments = new QueryArguments(fieldInfo.Arguments.Where(arg => !arg.IsInjected).Select(DeriveArgument)), - Resolver = resolver, - Subscriber = resolver + Resolver = streamResolver, + StreamResolver = streamResolver }; } return new FieldType @@ -259,7 +261,7 @@ private IGraphType ConstructEnumerationType(GraphTypeInfo typeInfo) var graphType = ConstructType(typeof(Types.EnumerationGraphType<>), typeInfo); foreach (var value in typeInfo.Fields) { - graphType.AddValue(value.Name, value.Description, value.Value, value.DeprecationReason); + graphType.Add(value.Name, value.Value, value.Description, value.DeprecationReason); } return WrapNonNullableType(typeInfo, graphType); } diff --git a/src/GraphQL.Conventions/Adapters/ResolutionContext.cs b/src/GraphQL.Conventions/Adapters/ResolutionContext.cs index d9702c13..b2e962dd 100644 --- a/src/GraphQL.Conventions/Adapters/ResolutionContext.cs +++ b/src/GraphQL.Conventions/Adapters/ResolutionContext.cs @@ -12,7 +12,7 @@ public class ResolutionContext : IResolutionContext { private static readonly object Lock = new object(); - public ResolutionContext(GraphFieldInfo fieldInfo, ResolveFieldContext fieldContext) + public ResolutionContext(GraphFieldInfo fieldInfo, IResolveFieldContext fieldContext) { FieldContext = fieldContext; FieldInfo = fieldInfo; @@ -47,11 +47,16 @@ public void SetArgument(string name, object value) { lock (Lock) { - if (FieldContext.Arguments == null) + var fieldContext = FieldContext is ResolveFieldContext + ? (ResolveFieldContext) FieldContext + : new ResolveFieldContext(FieldContext); + + if (fieldContext.Arguments == null) { - FieldContext.Arguments = new Dictionary(); + fieldContext.Arguments = new Dictionary(); } - FieldContext.Arguments[name] = new ArgumentValue(value, ArgumentSource.Variable); + fieldContext.Arguments[name] = new ArgumentValue(value, ArgumentSource.Variable); + FieldContext = fieldContext; } } @@ -67,6 +72,6 @@ public void SetArgument(string name, object value) public IEnumerable Path => FieldContext.Path.Select(o => o?.ToString()); - public ResolveFieldContext FieldContext { get; } + public IResolveFieldContext FieldContext { get; private set; } } } diff --git a/src/GraphQL.Conventions/Adapters/Resolvers/EventStreamResolver.cs b/src/GraphQL.Conventions/Adapters/Resolvers/EventStreamResolver.cs index 81aca1b1..ee91bd51 100644 --- a/src/GraphQL.Conventions/Adapters/Resolvers/EventStreamResolver.cs +++ b/src/GraphQL.Conventions/Adapters/Resolvers/EventStreamResolver.cs @@ -1,20 +1,21 @@ -using GraphQL.Conventions.Types.Descriptors; -using GraphQL.Resolvers; -using GraphQL.Subscription; +using GraphQL.Resolvers; using System; using System.Threading.Tasks; namespace GraphQL.Conventions.Adapters.Resolvers { - public class EventStreamResolver : FieldResolver, IEventStreamResolver + public class EventStreamResolver : ISourceStreamResolver, IFieldResolver { - public EventStreamResolver(GraphFieldInfo fieldInfo) : base(fieldInfo) + private readonly IFieldResolver _fieldResolver; + + public EventStreamResolver(IFieldResolver fieldResolver) { + _fieldResolver = fieldResolver; } - public IObservable Subscribe(IResolveEventStreamContext context) + public async ValueTask> ResolveAsync(IResolveFieldContext context) { - var result = base.Resolve(context); + var result = await _fieldResolver.ResolveAsync(context); if (result is Task) { result = (result as Task).Result; @@ -22,9 +23,9 @@ public IObservable Subscribe(IResolveEventStreamContext context) return (IObservable)result; } - public override object Resolve(IResolveFieldContext context) + ValueTask IFieldResolver.ResolveAsync(IResolveFieldContext context) { - return context.Source; + return new(context.Source); } } -} +} \ No newline at end of file diff --git a/src/GraphQL.Conventions/Adapters/Resolvers/FieldResolver.cs b/src/GraphQL.Conventions/Adapters/Resolvers/FieldResolver.cs index aa23aad6..243565d9 100644 --- a/src/GraphQL.Conventions/Adapters/Resolvers/FieldResolver.cs +++ b/src/GraphQL.Conventions/Adapters/Resolvers/FieldResolver.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using GraphQL.Conventions.Attributes.Execution.Unwrappers; using GraphQL.Conventions.Extensions; using GraphQL.Conventions.Handlers; @@ -11,7 +12,7 @@ // ReSharper disable once CheckNamespace namespace GraphQL.Conventions.Adapters { - public class FieldResolver : IFieldResolver + public class FieldResolver : IFieldResolver { protected static readonly ExecutionFilterAttributeHandler ExecutionFilterHandler = new ExecutionFilterAttributeHandler(); @@ -25,12 +26,7 @@ public FieldResolver(GraphFieldInfo fieldInfo) _fieldInfo = fieldInfo; } - public virtual object Resolve(IResolveFieldContext context) - { - return Resolve(new ResolveFieldContext(context)); - } - - public object Resolve(ResolveFieldContext context) + public async ValueTask ResolveAsync(IResolveFieldContext context) { Func resolver; if (_fieldInfo.IsMethod) @@ -42,7 +38,7 @@ public object Resolve(ResolveFieldContext context) resolver = ctx => GetValue(_fieldInfo, ctx); } var resolutionContext = new ResolutionContext(_fieldInfo, context); - return ExecutionFilterHandler.Execute(resolutionContext, resolver); + return await ExecutionFilterHandler.Execute(resolutionContext, resolver); } private object GetValue(GraphFieldInfo fieldInfo, IResolutionContext context) diff --git a/src/GraphQL.Conventions/Adapters/Resolvers/WrappedAsyncFieldResolver.cs b/src/GraphQL.Conventions/Adapters/Resolvers/WrappedAsyncFieldResolver.cs index ea781b17..c7136d53 100644 --- a/src/GraphQL.Conventions/Adapters/Resolvers/WrappedAsyncFieldResolver.cs +++ b/src/GraphQL.Conventions/Adapters/Resolvers/WrappedAsyncFieldResolver.cs @@ -28,7 +28,7 @@ public WrappedAsyncFieldResolver(GraphFieldInfo fieldInfo) _fieldInfo = fieldInfo; } - public object Resolve(IResolveFieldContext context) + public async ValueTask ResolveAsync(IResolveFieldContext context) { Func resolver; if (_fieldInfo.IsMethod) @@ -40,7 +40,7 @@ public object Resolve(IResolveFieldContext context) resolver = ctx => GetValue(_fieldInfo, ctx); } var resolutionContext = new ResolutionContext(_fieldInfo, new ResolveFieldContext(context)); - return ExecutionFilterHandler.Execute(resolutionContext, resolver); + return await ExecutionFilterHandler.Execute(resolutionContext, resolver); } private object GetValue(GraphFieldInfo fieldInfo, IResolutionContext context) diff --git a/src/GraphQL.Conventions/Adapters/Resolvers/WrappedSyncFieldResolver.cs b/src/GraphQL.Conventions/Adapters/Resolvers/WrappedSyncFieldResolver.cs index 507327ec..f6ae9a1e 100644 --- a/src/GraphQL.Conventions/Adapters/Resolvers/WrappedSyncFieldResolver.cs +++ b/src/GraphQL.Conventions/Adapters/Resolvers/WrappedSyncFieldResolver.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Threading.Tasks; using GraphQL.Conventions.Attributes.Execution.Unwrappers; using GraphQL.Conventions.Extensions; using GraphQL.Conventions.Handlers; @@ -27,7 +28,7 @@ public WrappedSyncFieldResolver(GraphFieldInfo fieldInfo) _fieldInfo = fieldInfo; } - public object Resolve(IResolveFieldContext context) + public async ValueTask ResolveAsync(IResolveFieldContext context) { Func resolver; if (_fieldInfo.IsMethod) @@ -39,7 +40,7 @@ public object Resolve(IResolveFieldContext context) resolver = ctx => GetValue(_fieldInfo, ctx); } var resolutionContext = new ResolutionContext(_fieldInfo, new ResolveFieldContext(context)); - return ExecutionFilterHandler.Execute(resolutionContext, resolver); + return await ExecutionFilterHandler.Execute(resolutionContext, resolver); } private object GetValue(GraphFieldInfo fieldInfo, IResolutionContext context) diff --git a/src/GraphQL.Conventions/Adapters/Types/GuidGraphType.cs b/src/GraphQL.Conventions/Adapters/Types/GuidGraphType.cs index c0d29ca4..45b7f89e 100644 --- a/src/GraphQL.Conventions/Adapters/Types/GuidGraphType.cs +++ b/src/GraphQL.Conventions/Adapters/Types/GuidGraphType.cs @@ -1,8 +1,8 @@ using System; using GraphQL.Conventions.Adapters.Types.Extensions; using GraphQL.Conventions.Types.Descriptors; -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; namespace GraphQL.Conventions.Adapters.Types { @@ -27,9 +27,9 @@ public override object ParseValue(object value) : (Guid?)Guid.Parse(guid); } - public override object ParseLiteral(IValue value) + public override object ParseLiteral(GraphQLValue value) { - if (value is StringValue str) + if (value is GraphQLStringValue str) { return ParseValue(str.Value); } diff --git a/src/GraphQL.Conventions/Adapters/Types/Relay/CursorGraphType.cs b/src/GraphQL.Conventions/Adapters/Types/Relay/CursorGraphType.cs index 631d9cd5..797270a9 100644 --- a/src/GraphQL.Conventions/Adapters/Types/Relay/CursorGraphType.cs +++ b/src/GraphQL.Conventions/Adapters/Types/Relay/CursorGraphType.cs @@ -1,7 +1,7 @@ using GraphQL.Conventions.Adapters.Types.Extensions; using GraphQL.Conventions.Types.Descriptors; -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; using static GraphQL.Conventions.Utilities; namespace GraphQL.Conventions.Adapters.Types.Relay @@ -25,9 +25,9 @@ public override object ParseValue(object value) return NullableCursor(cursor); } - public override object ParseLiteral(IValue value) + public override object ParseLiteral(GraphQLValue value) { - if (value is StringValue str) + if (value is GraphQLStringValue str) { return ParseValue(str.Value); } diff --git a/src/GraphQL.Conventions/Adapters/Types/TimeSpanGraphType.cs b/src/GraphQL.Conventions/Adapters/Types/TimeSpanGraphType.cs index 1b376f30..8b59c596 100644 --- a/src/GraphQL.Conventions/Adapters/Types/TimeSpanGraphType.cs +++ b/src/GraphQL.Conventions/Adapters/Types/TimeSpanGraphType.cs @@ -2,8 +2,8 @@ using System.Globalization; using GraphQL.Conventions.Adapters.Types.Extensions; using GraphQL.Conventions.Types.Descriptors; -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; namespace GraphQL.Conventions.Adapters.Types { @@ -28,9 +28,9 @@ public override object ParseValue(object value) : (TimeSpan?)TimeSpan.Parse(timespan, CultureInfo.CurrentCulture); } - public override object ParseLiteral(IValue value) + public override object ParseLiteral(GraphQLValue value) { - if (value is StringValue str) + if (value is GraphQLStringValue str) { return ParseValue(str.Value); } diff --git a/src/GraphQL.Conventions/Adapters/Types/UriGraphType.cs b/src/GraphQL.Conventions/Adapters/Types/UriGraphType.cs index 4dd6e7fc..cf681f79 100644 --- a/src/GraphQL.Conventions/Adapters/Types/UriGraphType.cs +++ b/src/GraphQL.Conventions/Adapters/Types/UriGraphType.cs @@ -1,8 +1,8 @@ using System; using GraphQL.Conventions.Adapters.Types.Extensions; using GraphQL.Conventions.Types.Descriptors; -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; namespace GraphQL.Conventions.Adapters.Types { @@ -27,9 +27,9 @@ public override object ParseValue(object value) : new Uri(uri); } - public override object ParseLiteral(IValue value) + public override object ParseLiteral(GraphQLValue value) { - if (value is StringValue str) + if (value is GraphQLStringValue str) { return ParseValue(str.Value); } diff --git a/src/GraphQL.Conventions/Adapters/Types/UrlGraphType.cs b/src/GraphQL.Conventions/Adapters/Types/UrlGraphType.cs index cf0c70d1..127a727b 100644 --- a/src/GraphQL.Conventions/Adapters/Types/UrlGraphType.cs +++ b/src/GraphQL.Conventions/Adapters/Types/UrlGraphType.cs @@ -1,7 +1,7 @@ using GraphQL.Conventions.Adapters.Types.Extensions; using GraphQL.Conventions.Types.Descriptors; -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; namespace GraphQL.Conventions.Adapters.Types { @@ -26,9 +26,9 @@ public override object ParseValue(object value) : new Url(url); } - public override object ParseLiteral(IValue value) + public override object ParseLiteral(GraphQLValue value) { - if (value is StringValue str) + if (value is GraphQLStringValue str) { return ParseValue(str.Value); } diff --git a/src/GraphQL.Conventions/Execution/IResolutionContext.cs b/src/GraphQL.Conventions/Execution/IResolutionContext.cs index c06baa47..b97aedb0 100644 --- a/src/GraphQL.Conventions/Execution/IResolutionContext.cs +++ b/src/GraphQL.Conventions/Execution/IResolutionContext.cs @@ -27,6 +27,6 @@ public interface IResolutionContext IEnumerable Path { get; } - ResolveFieldContext FieldContext { get; } + IResolveFieldContext FieldContext { get; } } } diff --git a/src/GraphQL.Conventions/GraphQL.Conventions.csproj b/src/GraphQL.Conventions/GraphQL.Conventions.csproj index cfeddea7..3f169982 100644 --- a/src/GraphQL.Conventions/GraphQL.Conventions.csproj +++ b/src/GraphQL.Conventions/GraphQL.Conventions.csproj @@ -2,11 +2,11 @@ GraphQL Conventions for .NET - 4.3.0 - 4.3.0 + 5.3.0 + 5.3.0 Tommy Lillehagen net6.0;netstandard2.0 - 7.1 + 9.0 old portable GraphQL.Conventions @@ -29,10 +29,10 @@ - - - - + + + + diff --git a/src/GraphQL.Conventions/Web/RequestHandler.cs b/src/GraphQL.Conventions/Web/RequestHandler.cs index 96878e6b..89490eec 100644 --- a/src/GraphQL.Conventions/Web/RequestHandler.cs +++ b/src/GraphQL.Conventions/Web/RequestHandler.cs @@ -237,7 +237,7 @@ public async Task ProcessRequestAsync(Request request, IUserContext us var result = await _engine .NewExecutor() .WithQueryString(request.QueryString) - .WithInputs(request.Variables) + .WithVariables(request.Variables) .WithOperationName(request.OperationName) .WithDependencyInjector(dependencyInjector ?? _dependencyInjector) .WithUserContext(userContext) @@ -269,7 +269,7 @@ public async Task ProcessRequestAsync(Request request, IUserContext us if (result == null) return response; result.Errors = new ExecutionErrors(); result.Errors.AddRange(response.Errors); - response.SetBody(await _engine.SerializeResultAsync(result)); + response.SetBody(_engine.SerializeResult(result)); return response; } @@ -292,7 +292,7 @@ public async Task DescribeSchemaAsync( .WithQueryString(IntrospectionQuery) .ExecuteAsync(); - return await _engine.SerializeResultAsync(result); + return _engine.SerializeResult(result); } _engine.PrintFieldDescriptions(includeFieldDescriptions); diff --git a/src/GraphQL.Conventions/Web/Response.cs b/src/GraphQL.Conventions/Web/Response.cs index b0ba84d5..252f6dce 100644 --- a/src/GraphQL.Conventions/Web/Response.cs +++ b/src/GraphQL.Conventions/Web/Response.cs @@ -7,7 +7,7 @@ namespace GraphQL.Conventions.Web { public class Response { - private static readonly DocumentWriter Writer = new DocumentWriter(); + private static readonly GraphQLSerializer Serializer = new GraphQLSerializer(); private string _body; @@ -35,12 +35,11 @@ public Response( public Validation.IValidationResult ValidationResult { get; } - public async Task GetBodyAsync() + public string GetBody() { if (string.IsNullOrWhiteSpace(_body) && ExecutionResult != null) - _body = await Writer - .WriteToStringAsync(ExecutionResult) - .ConfigureAwait(false); + _body = Serializer + .Serialize(ExecutionResult); return _body; } diff --git a/test/GraphQL.Conventions.Tests/Adapters/ArgumentResolutionTests.cs b/test/GraphQL.Conventions.Tests/Adapters/ArgumentResolutionTests.cs index 05208384..c143f24d 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/ArgumentResolutionTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/ArgumentResolutionTests.cs @@ -657,7 +657,7 @@ private async Task ExecuteQuery( var result = await engine .NewExecutor() .WithQueryString(query) - .WithInputs(inputs) + .WithVariables(inputs) .WithUserContext(userContext) .WithDependencyInjector(new DependencyInjector()) .ExecuteAsync(); @@ -769,11 +769,11 @@ enum TestEnum { Foo, - [Name("BAZ")] + [GraphQL.Conventions.Name("BAZ")] Bar, } - [InputType] + [GraphQL.Conventions.InputType] class InputObject { public string Field1 { get; set; } @@ -788,7 +788,7 @@ public override string ToString() => $"{Field1}-{Field2}-{Field3}-{Field4}"; } - [InputType] + [GraphQL.Conventions.InputType] class ComplexInputObject { public Id Identifier { get; set; } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Engine/Bugs/Bug73NullableInputListTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Engine/Bugs/Bug73NullableInputListTests.cs index 839d146d..ce601b40 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Engine/Bugs/Bug73NullableInputListTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Engine/Bugs/Bug73NullableInputListTests.cs @@ -31,7 +31,7 @@ public async Task Can_Accept_Null_List_From_Input() var result = await engine .NewExecutor() .WithQueryString(@"query _($inputs:[TestInput]) { example(testInputs:$inputs) }") - .WithInputs(new Dictionary + .WithVariables(new Dictionary { { "inputs", null} , }) diff --git a/test/GraphQL.Conventions.Tests/Adapters/Engine/DependencyInjectionTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Engine/DependencyInjectionTests.cs index a5c5e791..580133c2 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Engine/DependencyInjectionTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Engine/DependencyInjectionTests.cs @@ -6,7 +6,8 @@ using GraphQL.Conventions; using GraphQL.Conventions.Execution; using GraphQL.Execution; -using GraphQL.Language.AST; +using GraphQL.Types; +using GraphQLParser.AST; using Tests.Templates; using Tests.Templates.Extensions; @@ -216,6 +217,7 @@ public ScopedExecutionStrategy(IDependencyInjector injector, IExecutionStrategy _innerStrategy = innerStrategy; } + public async Task ExecuteAsync(ExecutionContext context) { var key = typeof(IDependencyInjector).FullName ?? nameof(IDependencyInjector); @@ -232,7 +234,12 @@ public async Task ExecuteAsync(ExecutionContext context) } } - public Dictionary GetSubFields(ExecutionContext executionContext, ExecutionNode executionNode) + public async Task ExecuteNodeTreeAsync(ExecutionContext context, ExecutionNode rootNode) + { + throw new NotImplementedException(); + } + + Dictionary IExecutionStrategy.GetSubFields(ExecutionContext executionContext, ExecutionNode executionNode) { return _innerStrategy.GetSubFields(executionContext, executionNode); } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Engine/DynamicConstructionTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Engine/DynamicConstructionTests.cs index d0a59e73..333d77fd 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Engine/DynamicConstructionTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Engine/DynamicConstructionTests.cs @@ -83,8 +83,10 @@ public CustomResolver(UserRepository userRepository) _userRepository = userRepository; } - public object Resolve(IResolveFieldContext context) => - _userRepository; + public ValueTask ResolveAsync(IResolveFieldContext context) + { + return new ValueTask(_userRepository); + } } class User diff --git a/test/GraphQL.Conventions.Tests/Adapters/Engine/GraphQLExecutorTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Engine/GraphQLExecutorTests.cs index 2d130f08..50f2d261 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Engine/GraphQLExecutorTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Engine/GraphQLExecutorTests.cs @@ -16,7 +16,7 @@ public async Task Can_Disable_Validation() var result = await engine .NewExecutor() .WithQueryString("query Test($arg: Int!, $arg: Int!) { hello(var: $arg) }") - .WithInputs(new Dictionary { { "arg", 1 } }) + .WithVariables(new Dictionary { { "arg", 1 } }) .DisableValidation() .ExecuteAsync(); @@ -32,7 +32,7 @@ public async Task Can_Enable_Validation() var result = await engine .NewExecutor() .WithQueryString("query Test($arg: Int!, $arg: Int!) { hello(var: $arg) }") - .WithInputs(new Dictionary { { "arg", 1 } }) + .WithVariables(new Dictionary { { "arg", 1 } }) .EnableValidation() .ExecuteAsync(); diff --git a/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomGraphType.cs b/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomGraphType.cs index 52ff93ac..236dbd75 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomGraphType.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomGraphType.cs @@ -1,5 +1,5 @@ -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; namespace Tests.Adapters.Engine.Types { @@ -24,9 +24,9 @@ public override object ParseValue(object value) }; } - public override object ParseLiteral(IValue value) + public override object ParseLiteral(GraphQLValue value) { - if (value is StringValue str) + if (value is GraphQLStringValue str) { return ParseValue(str.Value); } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomJsonGraphType.cs b/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomJsonGraphType.cs index 5086a756..2a9ec89d 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomJsonGraphType.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Engine/Types/CustomJsonGraphType.cs @@ -1,14 +1,18 @@ using System.Collections.Generic; -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; // ReSharper disable InconsistentNaming namespace Tests.Adapters.Engine.Types { #region .NET Class - public class JSON : ValueNode> + public class JSON : GraphQLValue { + public IDictionary Value { get; protected set; } + + public override string ToString() => $"{GetType().Name}{{value={Value}}}"; + public JSON() { @@ -18,6 +22,8 @@ public JSON(IDictionary value) { Value = value; } + + public override ASTNodeKind Kind { get => ASTNodeKind.Field; } } #endregion @@ -30,12 +36,6 @@ public JSONScalarGraphType() Description = "Untyped JSON Structure"; } - - public override object Serialize(object value) - { - return ParseValue(value); - } - public override object ParseValue(object value) { if (value == null) @@ -49,16 +49,12 @@ public override object ParseValue(object value) return value; } - public override object ParseLiteral(IValue value) + + public override object ParseLiteral(GraphQLValue value) { var jsonValue = value as JSON; return jsonValue?.Value; } - - public override IValue ToAST(object value) - { - return new JSON(value as IDictionary); - } } #endregion } diff --git a/test/GraphQL.Conventions.Tests/Adapters/EventStreamResolverTest.cs b/test/GraphQL.Conventions.Tests/Adapters/EventStreamResolverTest.cs index 87374b2c..b07b3f68 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/EventStreamResolverTest.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/EventStreamResolverTest.cs @@ -1,9 +1,7 @@ using System; +using System.Reactive.Subjects; using System.Threading.Tasks; -using GraphQL; using GraphQL.Conventions; -using GraphQL.Conventions.Adapters.Resolvers; -using GraphQL.Subscription; using Tests.Templates; using Tests.Types; @@ -11,20 +9,10 @@ namespace Tests.Adapters { public class EventStreamResolverTest : TestBase { - [Test] - public void Can_Resolve_Value() - { - var result = "testring"; - var context = new ResolveFieldContext { Source = result }; - var resolver = new EventStreamResolver(null); - - Assert.AreEqual(result, resolver.Resolve(context)); - } - [Test] public async Task Can_Subscribe() { - var engine = GraphQLEngine.New(new SubscriptionDocumentExecuter()) + var engine = GraphQLEngine.New(new GraphQL.DocumentExecuter()) .WithQuery() .WithSubscription(); var result = await engine @@ -32,14 +20,21 @@ public async Task Can_Subscribe() .WithQueryString("subscription { test }") .ExecuteAsync(); - Assert.AreEqual(1, ((SubscriptionExecutionResult)result).Streams.Count); + Assert.AreEqual(1, result.Streams.Count); } } class Subscription { + private readonly Subject _subject; + + public Subscription() + { + _subject = new Subject(); + } + // ReSharper disable once UnusedMember.Global // ReSharper disable once UnassignedGetOnlyAutoProperty - public IObservable Test { get; } + public IObservable Test => _subject; } } diff --git a/test/GraphQL.Conventions.Tests/Adapters/FieldDerivationTests.cs b/test/GraphQL.Conventions.Tests/Adapters/FieldDerivationTests.cs index d91d654f..52d20f1d 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/FieldDerivationTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/FieldDerivationTests.cs @@ -142,7 +142,7 @@ public void Can_Derive_Observables() { var type = OutputType(); type.ShouldHaveFields(1); - type.Fields.ToList()[0].ShouldBeOfType(); + type.Fields.ToList()[0].ShouldBeOfType(); } class OutputTypeWithNoFields diff --git a/test/GraphQL.Conventions.Tests/Adapters/TypeConstructionTests.cs b/test/GraphQL.Conventions.Tests/Adapters/TypeConstructionTests.cs index 6c3e262d..ba1db158 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/TypeConstructionTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/TypeConstructionTests.cs @@ -173,7 +173,7 @@ class OutputType { } - [InputType] + [GraphQL.Conventions.InputType] class InputType { } @@ -187,7 +187,7 @@ class TypeWithDescription { } - [Name("Foo")] + [GraphQL.Conventions.Name("Foo")] class TypeWithOverriddenName { } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Types/GuidGraphTypeTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Types/GuidGraphTypeTests.cs index aac324d3..5b7c4554 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Types/GuidGraphTypeTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Types/GuidGraphTypeTests.cs @@ -1,6 +1,6 @@ using System; using GraphQL.Conventions.Adapters.Types; -using GraphQL.Language.AST; +using GraphQLParser.AST; namespace Tests.Adapters.Types { @@ -25,9 +25,9 @@ public override void Can_Parse_Value() [Test] public override void Can_Parse_Literal() { - ShouldParseLiteral(new NullValue(), null); - ShouldParseLiteral(new StringValue("ad9da688-1fd4-4e00-ad89-b4d3fef08280"), new Guid("ad9da688-1fd4-4e00-ad89-b4d3fef08280")); - ShouldParseLiteral(new IntValue(0), null); + ShouldParseLiteral(new GraphQLNullValue(), null); + ShouldParseLiteral(new GraphQLStringValue("ad9da688-1fd4-4e00-ad89-b4d3fef08280"), new Guid("ad9da688-1fd4-4e00-ad89-b4d3fef08280")); + ShouldParseLiteral(new GraphQLIntValue(0), null); } } } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Types/ScalarTypeTestBase.cs b/test/GraphQL.Conventions.Tests/Adapters/Types/ScalarTypeTestBase.cs index aba3db20..7dcd52b7 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Types/ScalarTypeTestBase.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Types/ScalarTypeTestBase.cs @@ -1,5 +1,5 @@ -using GraphQL.Language.AST; using GraphQL.Types; +using GraphQLParser.AST; using Tests.Templates; using Tests.Templates.Extensions; @@ -20,7 +20,7 @@ protected void ShouldParseValue(TSerializedRepresentation data, TNativeRepresent _graphType.ParseValue(data).ShouldEqual(expected); } - protected void ShouldParseLiteral(IValue data, TNativeRepresentation expected) + protected void ShouldParseLiteral(GraphQLValue data, TNativeRepresentation expected) { _graphType.ParseLiteral(data).ShouldEqual(expected); } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Types/TimeSpanGraphTypeTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Types/TimeSpanGraphTypeTests.cs index 86951f12..3d348165 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Types/TimeSpanGraphTypeTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Types/TimeSpanGraphTypeTests.cs @@ -1,6 +1,6 @@ using System; using GraphQL.Conventions.Adapters.Types; -using GraphQL.Language.AST; +using GraphQLParser.AST; namespace Tests.Adapters.Types { @@ -28,11 +28,11 @@ public override void Can_Parse_Value() [Test] public override void Can_Parse_Literal() { - ShouldParseLiteral(new StringValue("10.20:30:40.0500000"), new TimeSpan(10, 20, 30, 40, 50)); - ShouldParseLiteral(new StringValue("10.20:30:40.05"), new TimeSpan(10, 20, 30, 40, 50)); - ShouldParseLiteral(new StringValue("5.10:20:30"), new TimeSpan(5, 10, 20, 30)); - ShouldParseLiteral(new StringValue("05:10:20"), new TimeSpan(5, 10, 20)); - ShouldParseLiteral(new IntValue(0), null); + ShouldParseLiteral(new GraphQLStringValue("10.20:30:40.0500000"), new TimeSpan(10, 20, 30, 40, 50)); + ShouldParseLiteral(new GraphQLStringValue("10.20:30:40.05"), new TimeSpan(10, 20, 30, 40, 50)); + ShouldParseLiteral(new GraphQLStringValue("5.10:20:30"), new TimeSpan(5, 10, 20, 30)); + ShouldParseLiteral(new GraphQLStringValue("05:10:20"), new TimeSpan(5, 10, 20)); + ShouldParseLiteral(new GraphQLIntValue(0), null); } } } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Types/UriGraphTypeTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Types/UriGraphTypeTests.cs index 67b0aee8..85a71a99 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Types/UriGraphTypeTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Types/UriGraphTypeTests.cs @@ -1,6 +1,6 @@ using System; using GraphQL.Conventions.Adapters.Types; -using GraphQL.Language.AST; +using GraphQLParser.AST; namespace Tests.Adapters.Types { @@ -30,14 +30,14 @@ public override void Can_Parse_Value() [Test] public override void Can_Parse_Literal() { - ShouldParseLiteral(new NullValue(), null); - ShouldParseLiteral(new StringValue("http://www.google.com/"), new Uri("http://www.google.com/")); - ShouldParseLiteral(new StringValue("mailto:someone@somewhere.com"), new Uri("mailto:someone@somewhere.com")); - ShouldParseLiteral(new StringValue("\"http://www.google.com/\""), new Uri("http://www.google.com/")); - ShouldParseLiteral(new StringValue("mp4:af93420c0dff"), new Uri("mp4:af93420c0dff")); - ShouldThrow(() => ShouldParseLiteral(new StringValue("www.google.com"), null)); - ShouldThrow(() => ShouldParseLiteral(new StringValue("\"\"http://www.google.com/\"\""), null)); - ShouldParseLiteral(new IntValue(0), null); + ShouldParseLiteral(new GraphQLNullValue(), null); + ShouldParseLiteral(new GraphQLStringValue("http://www.google.com/"), new Uri("http://www.google.com/")); + ShouldParseLiteral(new GraphQLStringValue("mailto:someone@somewhere.com"), new Uri("mailto:someone@somewhere.com")); + ShouldParseLiteral(new GraphQLStringValue("\"http://www.google.com/\""), new Uri("http://www.google.com/")); + ShouldParseLiteral(new GraphQLStringValue("mp4:af93420c0dff"), new Uri("mp4:af93420c0dff")); + ShouldThrow(() => ShouldParseLiteral(new GraphQLStringValue("www.google.com"), null)); + ShouldThrow(() => ShouldParseLiteral(new GraphQLStringValue("\"\"http://www.google.com/\"\""), null)); + ShouldParseLiteral(new GraphQLIntValue(0), null); } } } diff --git a/test/GraphQL.Conventions.Tests/Adapters/Types/UrlGraphTypeTests.cs b/test/GraphQL.Conventions.Tests/Adapters/Types/UrlGraphTypeTests.cs index 48faaefa..31393ff1 100644 --- a/test/GraphQL.Conventions.Tests/Adapters/Types/UrlGraphTypeTests.cs +++ b/test/GraphQL.Conventions.Tests/Adapters/Types/UrlGraphTypeTests.cs @@ -1,7 +1,7 @@ using System; using GraphQL.Conventions; using GraphQL.Conventions.Adapters.Types; -using GraphQL.Language.AST; +using GraphQLParser.AST; namespace Tests.Adapters.Types { @@ -30,14 +30,14 @@ public override void Can_Parse_Value() [Test] public override void Can_Parse_Literal() { - ShouldParseLiteral(new NullValue(), null); - ShouldParseLiteral(new StringValue("http://www.google.com/"), new Url("http://www.google.com/")); - ShouldParseLiteral(new StringValue("mailto:someone@somewhere.com"), new Url("mailto:someone@somewhere.com")); - ShouldParseLiteral(new StringValue("\"http://www.google.com/\""), new Url("http://www.google.com/")); - ShouldThrow(() => ShouldParseLiteral(new StringValue("www.google.com"), null)); - ShouldThrow(() => ShouldParseLiteral(new StringValue("mp4:af93420c0dff"), null)); - ShouldThrow(() => ShouldParseLiteral(new StringValue("\"\"http://www.google.com/\"\""), null)); - ShouldParseLiteral(new IntValue(0), null); + ShouldParseLiteral(new GraphQLNullValue(), null); + ShouldParseLiteral(new GraphQLStringValue("http://www.google.com/"), new Url("http://www.google.com/")); + ShouldParseLiteral(new GraphQLStringValue("mailto:someone@somewhere.com"), new Url("mailto:someone@somewhere.com")); + ShouldParseLiteral(new GraphQLStringValue("\"http://www.google.com/\""), new Url("http://www.google.com/")); + ShouldThrow(() => ShouldParseLiteral(new GraphQLStringValue("www.google.com"), null)); + ShouldThrow(() => ShouldParseLiteral(new GraphQLStringValue("mp4:af93420c0dff"), null)); + ShouldThrow(() => ShouldParseLiteral(new GraphQLStringValue("\"\"http://www.google.com/\"\""), null)); + ShouldParseLiteral(new GraphQLIntValue(0), null); } } } diff --git a/test/GraphQL.Conventions.Tests/Attributes/Execution/Relay/RelayMutationAttributeTests.cs b/test/GraphQL.Conventions.Tests/Attributes/Execution/Relay/RelayMutationAttributeTests.cs index f325abef..8a493597 100644 --- a/test/GraphQL.Conventions.Tests/Attributes/Execution/Relay/RelayMutationAttributeTests.cs +++ b/test/GraphQL.Conventions.Tests/Attributes/Execution/Relay/RelayMutationAttributeTests.cs @@ -114,7 +114,7 @@ private async Task ExecuteMutation(string query, Dictionary< var result = await engine .NewExecutor() .WithQueryString(query) - .WithInputs(inputs) + .WithVariables(inputs) .ExecuteAsync(); return result; diff --git a/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs b/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs index 18b0be00..1fe3b9ed 100644 --- a/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs +++ b/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs @@ -4,8 +4,8 @@ using GraphQL; using GraphQL.Conventions; using GraphQL.Conventions.Execution; -using GraphQL.Language.AST; using GraphQL.Validation; +using GraphQLParser.AST; using Tests.Templates; using Tests.Templates.Extensions; @@ -49,7 +49,6 @@ public void ClassMethod_Without_CustomAttribute_ShouldBeNull() public async Task When_UserIsMissingAll_ValidationFieldTypeMetaData_ErrorsAreReturned() { var result = await Resolve_Query(); - result.ShouldHaveErrors(4); var expectedMessages = new[] { $"Required validation '{nameof(SomeTopLevelValidation)}' is not present. Query will not be executed.", @@ -139,9 +138,9 @@ public TestCustomAttribute(string permission) public class TestValidation : IValidationRule { - public Task ValidateAsync(ValidationContext context) + public ValueTask ValidateAsync(ValidationContext context) { - return Task.FromResult(new TestValidationNodeVisitor(context.GetUserContext() as TestUserContext)); + return new ValueTask(new TestValidationNodeVisitor(context.GetUserContext() as TestUserContext)); } } @@ -154,7 +153,7 @@ public TestValidationNodeVisitor(TestUserContext user) _user = user; } - public void Enter(INode node, ValidationContext context) + public void Enter(ASTNode node, ValidationContext context) { var fieldDef = context.TypeInfo.GetFieldDef(); if (fieldDef == null) return; @@ -165,13 +164,13 @@ public void Enter(INode node, ValidationContext context) if (_user == null || _user.AccessPermissions.All(p => p != requiredValidation)) context.ReportError( new ValidationError( /* When reporting such errors no data would be returned use with cautious */ - context.Document.OriginalQuery, + context.Document.Source, "Authorization", $"Required validation '{requiredValidation}' is not present. Query will not be executed.", node)); } } - public void Leave(INode node, ValidationContext context) { /* Noop */ } + public void Leave(ASTNode node, ValidationContext context) { /* Noop */ } } } diff --git a/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj b/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj index 9d6e230d..9c4c2546 100755 --- a/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj +++ b/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj @@ -8,23 +8,23 @@ - default + 9.0 - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs b/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs index 28cf2894..adf4131b 100644 --- a/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs +++ b/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs @@ -27,7 +27,7 @@ public async Task Can_Run_Query() response.Errors.Count.ShouldEqual(0); response.Warnings.Count.ShouldEqual(0); - var body = await response.GetBodyAsync(); + var body = response.GetBody(); body.ShouldEqual("{\"data\":{\"hello\":\"World\"}}"); } @@ -46,7 +46,7 @@ public async Task Can_Run_Simple_Query_Using_ComplexityConfiguration() response.Errors.Count.ShouldEqual(0); response.Warnings.Count.ShouldEqual(0); - var body = await response.GetBodyAsync(); + var body = response.GetBody(); body.ShouldEqual("{\"data\":{\"hello\":\"World\"}}"); } @@ -77,7 +77,7 @@ public async Task Can_Enrich_With_Profiling_Information() .Generate() .ProcessRequestAsync(request, null); - var body = await response.GetBodyAsync(); + var body = response.GetBody(); body.ShouldContain("\"extensions\":{\"tracing\":"); } @@ -93,7 +93,7 @@ public async Task Can_Ignore_Types_From_Unwanted_Namespaces() .Generate() .ProcessRequestAsync(request, null); - var body = await response.GetBodyAsync(); + var body = response.GetBody(); body.ShouldEqual("{\"data\":{\"earth\":{\"hello\":\"World\"},\"mars\":{\"hello\":\"World From Mars\"}}}"); // Exclude types from 'Unwanted' namespace, i.e. TypeQuery2 from CompositeQuery schema @@ -107,7 +107,7 @@ public async Task Can_Ignore_Types_From_Unwanted_Namespaces() response.Errors.Count.ShouldEqual(1); response.Errors[0].Message.ShouldContain("Cannot query field 'mars' on type 'CompositeQuery'."); - body = await response.GetBodyAsync(); + body = response.GetBody(); body.ShouldContain("FIELD_RESOLUTION"); } @@ -126,7 +126,7 @@ public async Task Can_Run_Query_With_Type_Extensions() response.Errors.Count.ShouldEqual(0); response.Warnings.Count.ShouldEqual(0); - var body = await response.GetBodyAsync(); + var body = response.GetBody(); body.ShouldEqual("{\"data\":{\"helloExtended\":\"Extended-10\"}}"); } @@ -144,7 +144,7 @@ public async Task Can_Run_Query_With_Nested_Type_Extensions() response.Errors.Count.ShouldEqual(0); response.Warnings.Count.ShouldEqual(0); - var body = await response.GetBodyAsync(); + var body = response.GetBody(); body.ShouldEqual("{\"data\":{\"helloType\":{\"myName\":\"Name-1\"}}}"); } diff --git a/test/GraphQL.Conventions.Tests/Web/ResponseTests.cs b/test/GraphQL.Conventions.Tests/Web/ResponseTests.cs index d825214e..7fa4000b 100644 --- a/test/GraphQL.Conventions.Tests/Web/ResponseTests.cs +++ b/test/GraphQL.Conventions.Tests/Web/ResponseTests.cs @@ -53,7 +53,7 @@ public async void Can_Instantiate_Response_Object_With_No_Data() response.HasData.ShouldEqual(false); response.HasErrors.ShouldEqual(false); - var body = await response.GetBodyAsync(); + var body = response.GetBody(); body.ShouldEqual("{\"extensions\":{\"trace\":{\"foo\":1,\"bar\":{\"baz\":\"hello\"}}}}"); } }