Skip to content

Commit

Permalink
Update to GraphQL 5.3 (#232)
Browse files Browse the repository at this point in the history
* Update to GraphQL 5.3, Bump to 5.3

* Fix samples

* Fix subscription

Co-authored-by: Shane Krueger <[email protected]>

* Remove unused code

Co-authored-by: Pierre leandre <[email protected]>
Co-authored-by: Shane Krueger <[email protected]>
  • Loading branch information
3 people authored Jul 4, 2022
1 parent 75ddcb4 commit be60ed2
Show file tree
Hide file tree
Showing 57 changed files with 327 additions and 375 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
<LangVersion>7.3</LangVersion>
</PropertyGroup>


<ItemGroup>
<Compile Remove="wwwroot\**" />
<Content Remove="wwwroot\**" />
Expand All @@ -16,12 +13,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="GraphQL.Conventions" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="GraphQL" Version="5.3.0" />
<PackageReference Include="GraphQL.DataLoader" Version="5.3.0" />
<ProjectReference Include="../../../src/GraphQL.Conventions/GraphQL.Conventions.csproj" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.6" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.Conventions;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -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;
}

Expand All @@ -30,12 +27,11 @@ public async Task<IActionResult> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Movie> UpdateMovieTitle([Inject] IMovieRepository movieRepository, UpdateMovieTitleParams @params)
=> Mapper.Map<Movie>(await movieRepository.UpdateMovieTitle(@params.Id, @params.NewTitle));
=> _mapper.Map<Movie>(await movieRepository.UpdateMovieTitle(@params.Id, @params.NewTitle));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public sealed class Actor

public Guid MovieId { get; set; }

public async Task<Country> Country([Inject] ICountryRepository repository, [Inject] DataLoaderContext dataLoaderContext)
public async Task<Country> Country([Inject] IMapper mapper, [Inject] ICountryRepository repository, [Inject] DataLoaderContext dataLoaderContext)
{
var loader = dataLoaderContext.GetOrAddBatchLoader<string, Models.Country>("Actor_Country", repository.GetCountries);
return Mapper.Map<Country>(await loader.LoadAsync(CountryCode));
return mapper.Map<Country>(await loader.LoadAsync(CountryCode).GetResultAsync());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public sealed class Movie

public DateTime ReleaseDateUtc { get; set; }

public async Task<Actor[]> Actors([Inject] IActorRepository repository, [Inject] DataLoaderContext dataLoaderContext)
public async Task<Actor[]> Actors([Inject] IMapper mapper, [Inject] IActorRepository repository, [Inject] DataLoaderContext dataLoaderContext)
{
var loader = dataLoaderContext.GetOrAddCollectionBatchLoader<Guid, Models.Actor>("Movie_Actors", repository.GetActorsPerMovie);
return Mapper.Map<Actor[]>(await loader.LoadAsync(Id));
return mapper.Map<Actor[]>(await loader.LoadAsync(Id).GetResultAsync());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> Movie([Inject] IMovieRepository repository, Guid id)
=> Mapper.Map<Movie>(await repository.FindMovie(id));
{
return _mapper.Map<Movie>(await repository.FindMovie(id));
}

public async Task<Movie[]> Movies([Inject] IMovieRepository repository)
=> Mapper.Map<Movie[]>(await repository.GetMovies());
=> _mapper.Map<Movie[]>(await repository.GetMovies());
}
}

This file was deleted.

9 changes: 1 addition & 8 deletions samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Program.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
18 changes: 10 additions & 8 deletions samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,31 +27,28 @@ 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<MovieDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

services.AddScoped<IActorRepository, ActorRepository>();
services.AddScoped<ICountryRepository, CountryRepository>();
services.AddScoped<IMovieRepository, MovieRepository>();

services.AddSingleton(provider => new GraphQLEngine()
services.AddSingleton(_ => new GraphQLEngine()
.WithFieldResolutionStrategy(FieldResolutionStrategy.Normal)
.BuildSchema(typeof(SchemaDefinition<Schema.Query, Schema.Mutation>)));

services.AddScoped<IDependencyInjector, Injector>();
services.AddScoped<IUserContext, UserContext>();
services.AddScoped<Schema.Query>();
services.AddScoped<Schema.Mutation>();

services.AddScoped<DataLoaderContext>();

Mapper.Initialize(config => config.AddProfile<Mappings>());
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())
{
Expand All @@ -62,7 +60,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
}

app.UseHttpsRedirection();
app.UseMvc();
app.UseRouting();
app.UseEndpoints(configure =>
{
configure.MapControllers();
});
}
}
}
3 changes: 2 additions & 1 deletion samples/SimpleWebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace GraphQL.Conventions.Tests.Server
{
Expand All @@ -13,6 +13,7 @@ public static void Main(string[] args)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.ConfigureLogging(l => l.AddConsole())
.Build();

host.Run();
Expand Down
12 changes: 12 additions & 0 deletions samples/SimpleWebApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"SimpleWebApp": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:64575;http://localhost:64576"
}
}
}
9 changes: 3 additions & 6 deletions samples/SimpleWebApp/SimpleWebApp.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<LangVersion>7.3</LangVersion>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<RootNamespace>GraphQL.Conventions.Tests.Server</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
<ProjectReference Include="../../src/GraphQL.Conventions/GraphQL.Conventions.csproj" />
</ItemGroup>

Expand Down
6 changes: 2 additions & 4 deletions samples/SimpleWebApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBookRepository>(new BookRepository());
dependencyInjector.Register<IAuthorRepository>(new AuthorRepository());
Expand Down Expand Up @@ -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());
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Loading

0 comments on commit be60ed2

Please sign in to comment.