Skip to content

Commit be60ed2

Browse files
pleandrepleandremavenShane32
authored
Update to GraphQL 5.3 (#232)
* 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]>
1 parent 75ddcb4 commit be60ed2

File tree

57 files changed

+327
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+327
-375
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFrameworks>net6.0</TargetFrameworks>
5+
<LangVersion>9.0</LangVersion>
56
</PropertyGroup>
6-
7-
<PropertyGroup>
8-
<LangVersion>7.3</LangVersion>
9-
</PropertyGroup>
10-
7+
118
<ItemGroup>
129
<Compile Remove="wwwroot\**" />
1310
<Content Remove="wwwroot\**" />
@@ -16,12 +13,13 @@
1613
</ItemGroup>
1714

1815
<ItemGroup>
19-
<PackageReference Include="AutoMapper" Version="7.0.1" />
20-
<PackageReference Include="GraphQL.Conventions" Version="2.0.2" />
21-
<PackageReference Include="Microsoft.AspNetCore.App" />
22-
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
23-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
24-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
16+
<PackageReference Include="AutoMapper" Version="11.0.1" />
17+
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
18+
<PackageReference Include="GraphQL" Version="5.3.0" />
19+
<PackageReference Include="GraphQL.DataLoader" Version="5.3.0" />
20+
<ProjectReference Include="../../../src/GraphQL.Conventions/GraphQL.Conventions.csproj" />
21+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
22+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.6" />
2523
</ItemGroup>
2624

2725
</Project>

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/GraphController.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Linq;
33
using System.Net;
44
using System.Threading.Tasks;
5-
using GraphQL;
65
using GraphQL.Conventions;
76
using Microsoft.AspNetCore.Mvc;
87

@@ -13,13 +12,11 @@ namespace DataLoaderWithEFCore.GraphApi
1312
public class GraphController : ControllerBase
1413
{
1514
private readonly GraphQLEngine _engine;
16-
private readonly IUserContext _userContext;
1715
private readonly IDependencyInjector _injector;
1816

19-
public GraphController(GraphQLEngine engine, IUserContext userContext, IDependencyInjector injector)
17+
public GraphController(GraphQLEngine engine, IDependencyInjector injector)
2018
{
2119
_engine = engine;
22-
_userContext = userContext;
2320
_injector = injector;
2421
}
2522

@@ -30,12 +27,11 @@ public async Task<IActionResult> Post()
3027
using (var reader = new StreamReader(Request.Body))
3128
requestBody = await reader.ReadToEndAsync();
3229

33-
ExecutionResult result = await _engine
30+
var result = await _engine
3431
.NewExecutor()
35-
.WithUserContext(_userContext)
3632
.WithDependencyInjector(_injector)
3733
.WithRequest(requestBody)
38-
.Execute();
34+
.ExecuteAsync();
3935

4036
var responseBody = _engine.SerializeResult(result);
4137

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Mutation.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ namespace DataLoaderWithEFCore.GraphApi.Schema
77
{
88
public sealed class Mutation
99
{
10+
private readonly IMapper _mapper;
11+
12+
public Mutation(IMapper mapper)
13+
{
14+
_mapper = mapper;
15+
}
16+
1017
public async Task<Movie> UpdateMovieTitle([Inject] IMovieRepository movieRepository, UpdateMovieTitleParams @params)
11-
=> Mapper.Map<Movie>(await movieRepository.UpdateMovieTitle(@params.Id, @params.NewTitle));
18+
=> _mapper.Map<Movie>(await movieRepository.UpdateMovieTitle(@params.Id, @params.NewTitle));
1219
}
1320
}

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Actor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public sealed class Actor
1818

1919
public Guid MovieId { get; set; }
2020

21-
public async Task<Country> Country([Inject] ICountryRepository repository, [Inject] DataLoaderContext dataLoaderContext)
21+
public async Task<Country> Country([Inject] IMapper mapper, [Inject] ICountryRepository repository, [Inject] DataLoaderContext dataLoaderContext)
2222
{
2323
var loader = dataLoaderContext.GetOrAddBatchLoader<string, Models.Country>("Actor_Country", repository.GetCountries);
24-
return Mapper.Map<Country>(await loader.LoadAsync(CountryCode));
24+
return mapper.Map<Country>(await loader.LoadAsync(CountryCode).GetResultAsync());
2525
}
2626
}
2727
}

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Movie.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public sealed class Movie
1818

1919
public DateTime ReleaseDateUtc { get; set; }
2020

21-
public async Task<Actor[]> Actors([Inject] IActorRepository repository, [Inject] DataLoaderContext dataLoaderContext)
21+
public async Task<Actor[]> Actors([Inject] IMapper mapper, [Inject] IActorRepository repository, [Inject] DataLoaderContext dataLoaderContext)
2222
{
2323
var loader = dataLoaderContext.GetOrAddCollectionBatchLoader<Guid, Models.Actor>("Movie_Actors", repository.GetActorsPerMovie);
24-
return Mapper.Map<Actor[]>(await loader.LoadAsync(Id));
24+
return mapper.Map<Actor[]>(await loader.LoadAsync(Id).GetResultAsync());
2525
}
2626
}
2727
}

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/Query.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ namespace DataLoaderWithEFCore.GraphApi.Schema
88
{
99
public sealed class Query
1010
{
11+
private readonly IMapper _mapper;
12+
13+
public Query(IMapper mapper)
14+
{
15+
_mapper = mapper;
16+
}
17+
1118
public async Task<Movie> Movie([Inject] IMovieRepository repository, Guid id)
12-
=> Mapper.Map<Movie>(await repository.FindMovie(id));
19+
{
20+
return _mapper.Map<Movie>(await repository.FindMovie(id));
21+
}
1322

1423
public async Task<Movie[]> Movies([Inject] IMovieRepository repository)
15-
=> Mapper.Map<Movie[]>(await repository.GetMovies());
24+
=> _mapper.Map<Movie[]>(await repository.GetMovies());
1625
}
1726
}

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/UserContext.cs

-22
This file was deleted.

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Program.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
1+
using Microsoft.AspNetCore;
72
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
103

114
namespace DataLoaderWithEFCore
125
{

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/Startup.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.EntityFrameworkCore;
1111
using Microsoft.Extensions.Configuration;
1212
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.Extensions.Hosting;
1314
using Schema = DataLoaderWithEFCore.GraphApi.Schema;
1415

1516
namespace DataLoaderWithEFCore
@@ -26,31 +27,28 @@ public Startup(IConfiguration configuration)
2627
// This method gets called by the runtime. Use this method to add services to the container.
2728
public void ConfigureServices(IServiceCollection services)
2829
{
29-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
30-
3130
services.AddDbContext<MovieDbContext>(options =>
3231
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
3332

3433
services.AddScoped<IActorRepository, ActorRepository>();
3534
services.AddScoped<ICountryRepository, CountryRepository>();
3635
services.AddScoped<IMovieRepository, MovieRepository>();
3736

38-
services.AddSingleton(provider => new GraphQLEngine()
37+
services.AddSingleton(_ => new GraphQLEngine()
3938
.WithFieldResolutionStrategy(FieldResolutionStrategy.Normal)
4039
.BuildSchema(typeof(SchemaDefinition<Schema.Query, Schema.Mutation>)));
4140

4241
services.AddScoped<IDependencyInjector, Injector>();
43-
services.AddScoped<IUserContext, UserContext>();
4442
services.AddScoped<Schema.Query>();
4543
services.AddScoped<Schema.Mutation>();
4644

4745
services.AddScoped<DataLoaderContext>();
48-
49-
Mapper.Initialize(config => config.AddProfile<Mappings>());
46+
services.AddAutoMapper(typeof(Mappings));
47+
services.AddControllers();
5048
}
5149

5250
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
53-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
51+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5452
{
5553
if (env.IsDevelopment())
5654
{
@@ -62,7 +60,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
6260
}
6361

6462
app.UseHttpsRedirection();
65-
app.UseMvc();
63+
app.UseRouting();
64+
app.UseEndpoints(configure =>
65+
{
66+
configure.MapControllers();
67+
});
6668
}
6769
}
6870
}

samples/SimpleWebApp/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.IO;
22
using Microsoft.AspNetCore.Hosting;
3-
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Logging;
44

55
namespace GraphQL.Conventions.Tests.Server
66
{
@@ -13,6 +13,7 @@ public static void Main(string[] args)
1313
.UseContentRoot(Directory.GetCurrentDirectory())
1414
.UseIISIntegration()
1515
.UseStartup<Startup>()
16+
.ConfigureLogging(l => l.AddConsole())
1617
.Build();
1718

1819
host.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"SimpleWebApp": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:64575;http://localhost:64576"
10+
}
11+
}
12+
}

samples/SimpleWebApp/SimpleWebApp.csproj

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.0</TargetFramework>
5-
</PropertyGroup>
6-
7-
<PropertyGroup>
8-
<LangVersion>7.3</LangVersion>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<LangVersion>9.0</LangVersion>
6+
<RootNamespace>GraphQL.Conventions.Tests.Server</RootNamespace>
97
</PropertyGroup>
108

119
<ItemGroup>
1210
<Folder Include="wwwroot\" />
1311
</ItemGroup>
1412

1513
<ItemGroup>
16-
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
1714
<ProjectReference Include="../../src/GraphQL.Conventions/GraphQL.Conventions.csproj" />
1815
</ItemGroup>
1916

samples/SimpleWebApp/Startup.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public void ConfigureServices(IServiceCollection services)
2121

2222
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
2323
{
24-
loggerFactory.AddConsole();
25-
2624
var dependencyInjector = new DependencyInjector();
2725
dependencyInjector.Register<IBookRepository>(new BookRepository());
2826
dependencyInjector.Register<IAuthorRepository>(new AuthorRepository());
@@ -54,10 +52,10 @@ private async Task HandleRequest(HttpContext context)
5452
var body = streamReader.ReadToEnd();
5553
var userContext = new UserContext();
5654
var result = await _requestHandler
57-
.ProcessRequest(Request.New(body), userContext);
55+
.ProcessRequestAsync(Request.New(body), userContext);
5856
context.Response.Headers.Add("Content-Type", "application/json; charset=utf-8");
5957
context.Response.StatusCode = result.Errors?.Count > 0 ? 400 : 200;
60-
await context.Response.WriteAsync(result.Body);
58+
await context.Response.WriteAsync(result.GetBody());
6159
}
6260
}
6361
}

samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Controllers/GraphController.cs

-58
This file was deleted.

samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/Program.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
1+
using Microsoft.AspNetCore;
72
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
103

114
namespace SubscriptionExample
125
{

0 commit comments

Comments
 (0)