Skip to content

Commit

Permalink
Update for GraphQL 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Apr 22, 2022
1 parent aa161fc commit 1d6ebbf
Show file tree
Hide file tree
Showing 58 changed files with 232 additions and 5,310 deletions.
9 changes: 9 additions & 0 deletions Sample/RequiredAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using GraphQL.Types;

namespace Sample
{
public class RequiredAttribute : GraphQL.GraphQLAttribute
{
public override void Modify(TypeInformation typeInformation) => typeInformation.IsNullable = false;
}
}
8 changes: 5 additions & 3 deletions Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

<ItemGroup>
<PackageReference Include="EfLocalDb" Version="8.5.0" />
<PackageReference Include="GraphQL.MicrosoftDI" Version="4.6.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="5.0.2" />
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="5.0.2" />
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.1.1" />
<PackageReference Include="GraphQL.DataLoader" Version="5.1.1" />
<PackageReference Include="GraphQL.SystemTextJson" Version="5.1.1" />
<PackageReference Include="GraphQL.AspNetCore3" Version="2.1.0" />
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.16" />
</ItemGroup>

Expand Down
40 changes: 19 additions & 21 deletions Sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using EfLocalDb;
using GraphQL;
using GraphQL.AspNetCore3;
using GraphQL.DI;
using GraphQL.MicrosoftDI;
using GraphQL.Server;
using GraphQL.SystemTextJson;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -29,25 +33,22 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();

services.AddGraphQL(opts => {
opts.UnhandledExceptionDelegate = e => {
Debug.WriteLine($"Unhandled exception:\n{e.Exception}\n");
};
})
services.AddGraphQL(b => b
.ConfigureExecutionOptions(opts => opts.UnhandledExceptionDelegate = async e => Debug.WriteLine($"Unhandled exception:\n{e.Exception}\n"))
.AddSystemTextJson()
.AddGraphTypes();
services.AddSingleton<DIDocumentExecuter>();
.AddDIGraphTypes()
.AddGraphTypes());
services.AddSingleton<TodoSchema>();
foreach (var type in typeof(TodoSchema).Assembly.GetTypes().Where(x => x.IsClass && !x.IsAbstract && !x.IsGenericTypeDefinition)) {
var baseType = type.BaseType;
while (baseType != null) {
if (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(DIObjectGraphBase<>)) {
services.AddScoped(type);
break;
}
baseType = baseType.BaseType;
}
}
//foreach (var type in typeof(TodoSchema).Assembly.GetTypes().Where(x => x.IsClass && !x.IsAbstract && !x.IsGenericTypeDefinition)) {
// var baseType = type.BaseType;
// while (baseType != null) {
// if (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(DIObjectGraphBase<>)) {
// services.AddScoped(type);
// break;
// }
// baseType = baseType.BaseType;
// }
//}

//construct temporary database with scoped dbcontext instances
services.AddSingleton(_ => new SqlInstance<TodoDbContext>(builder => new TodoDbContext(builder.Options)));
Expand Down Expand Up @@ -76,11 +77,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

app.UseAuthorization();

//GET calls to /graphql
var graphQlPath = new Microsoft.AspNetCore.Http.PathString("/graphql");
app.MapWhen(context => context.Request.Method == "GET" && context.Request.Path.Equals(graphQlPath, StringComparison.OrdinalIgnoreCase), app2 => app2.UseGraphQLGraphiQL("/graphql"));
//POST calls to /graphql
app.UseGraphQL<TodoSchema>();
app.UseGraphQLGraphiQL();

app.UseEndpoints(endpoints =>
{
Expand Down
122 changes: 0 additions & 122 deletions src/GraphQL.DI/AutoInputObjectGraphType.cs

This file was deleted.

Loading

0 comments on commit 1d6ebbf

Please sign in to comment.