Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for GraphQL 5 #17

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move into core repo?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh... we could. With NRT it's pretty pointless, but it probably depends on how it's actually used. I had RequiredAttribute, OptionalAttribute, RequiredListAttribute and OptionalListAttribute with a pile of tests for each written here previously. It is extremely easy to rewrite these attributes if they are needed with the new way the attributes are applied ( nice teamwork here 👍 👍 👍 ) . I just didn't feel like updating the sample project in this repo, so I just moved the class over to the sample project.

So, to answer your question, I wouldn't. But if you think so, sure.

There is two attributes I think we should consider adding:

  • An attribute that sets the 'base' graph type (i.e. the graph type of the base clr type) without having to apply the list/non-null wrappers. (Right now the InputType or OutputType attributes overwrite the entire graph type, so any list/non-null wrappers need to be specified in the attribute.)
  • A couple special attributes for date or timespan fields to define which exact graph type was intended.

Btw, I did try to eliminate the need for this project altogether, but I found that my code works very well with the DI-injection supported here, so I'm still using it. It is rather nice being able to DI-inject services into the constructor of mutation graphs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that it would be useful to fill the main project with additional attributes even as examples and even if these attributes will be rarely in demand.

{
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