Skip to content

net5 TFM #87

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

Merged
merged 3 commits into from
Feb 27, 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Examples for [GraphQL.NET](https://github.com/graphql-dotnet/graphql-dotnet).

| Project | Description |
|------------------|-------------|
| AspNetCore | ASP.NET Core 3.1 app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project |
| AspNetCoreMulti | ASP.NET Core 3.1 multi-tenant (two schemas) app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project |
| AspNetCoreCustom | ASP.NET Core 3.1 app with custom GraphQL and UI middlewares |
| AspNetWebApi | .NET Framework 4.6.1 Web API example |
| AspNetCore | ASP.NET Core 5 app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project |
| AspNetCoreMulti | ASP.NET Core 5 multi-tenant (two schemas) app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project |
| AspNetCoreCustom | ASP.NET Core 5 app with custom GraphQL and UI middlewares |
| AspNetWebApi | .NET Framework 4.8 Web API example |
| AzureFunctions | Using GraphQL in Azure Functions |
| StarWars | StarWars demo schema used in all examples |
| ClientNet462 | Example GraphQL client written in .NET 4.6.2 using Newtonsoft.Json 4.0.1 |
Expand Down
6 changes: 3 additions & 3 deletions src/AspNetCore/Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net6</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>latest</LangVersion>
<RestoreAdditionalProjectSources Condition="$(PublishNativeAot) == True">
Expand All @@ -11,8 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="5.2.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="5.2.0" />
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" Condition="$(PublishNativeAot) == True" />
</ItemGroup>

Expand Down
12 changes: 6 additions & 6 deletions src/AspNetCore/Example/GraphQL.rd.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<Directives>
<Application>
<Assembly Name="System.Text.Json">
<Type Name="System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5[[GraphQL.Instrumentation.ApolloTrace,GraphQL],[System.DateTime,System.Private.CoreLib],[System.Double,System.Private.CoreLib],[System.Object,System.Private.CoreLib],[System.Object,System.Private.CoreLib]]" Dynamic="Required All" />
<Type Name="System.Text.Json.Serialization.Converters.ListOfTConverter`2[[System.Collections.Generic.List`1[[GraphQL.Instrumentation.ApolloTrace+ResolverTrace,GraphQL]],System.Private.CoreLib],[GraphQL.Instrumentation.ApolloTrace+ResolverTrace,GraphQL]]" Dynamic="Required All" />
</Assembly>
</Application>
<Application>
<Assembly Name="System.Text.Json">
<Type Name="System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5[[GraphQL.Instrumentation.ApolloTrace,GraphQL],[System.DateTime,System.Private.CoreLib],[System.Double,System.Private.CoreLib],[System.Object,System.Private.CoreLib],[System.Object,System.Private.CoreLib]]" Dynamic="Required All" />
<Type Name="System.Text.Json.Serialization.Converters.ListOfTConverter`2[[System.Collections.Generic.List`1[[GraphQL.Instrumentation.ApolloTrace+ResolverTrace,GraphQL]],System.Private.CoreLib],[GraphQL.Instrumentation.ApolloTrace+ResolverTrace,GraphQL]]" Dynamic="Required All" />
</Assembly>
</Application>
</Directives>
32 changes: 16 additions & 16 deletions src/AspNetCore/Example/Microsoft.AspNetCore.rd.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<Directives>
<Application>
<Assembly Name="System.Text.Json">
<Type Name="System.Text.Json.Serialization.Converters.DictionaryOfTKeyTValueConverter`3[[System.Collections.Generic.Dictionary`2[[System.String,System.Private.CoreLib],[System.Object,System.Private.CoreLib]],System.Private.CoreLib],[System.String,System.Private.CoreLib],[System.Object,System.Private.CoreLib]]" Dynamic="Required All" />
</Assembly>
<Assembly Name="Microsoft.AspNetCore.Mvc.Razor">
<Type Name="Microsoft.AspNetCore.Mvc.ApplicationParts.ConsolidatedAssemblyApplicationPartFactory" Dynamic="Required All" />
</Assembly>
<Assembly Name="Microsoft.AspNetCore.Mvc.Core" Dynamic="Required All">
<Type Name="Microsoft.Extensions.Internal.PropertyHelper">
<Method Name="CallPropertySetter" Dynamic="Required">
<GenericArgument Name="Microsoft.AspNetCore.Mvc.Razor.RazorPageBase, Microsoft.AspNetCore.Mvc.Razor" />
<GenericArgument Name="System.Boolean, System.Private.CoreLib" />
</Method>
</Type>
</Assembly>
</Application>
<Application>
<Assembly Name="System.Text.Json">
<Type Name="System.Text.Json.Serialization.Converters.DictionaryOfTKeyTValueConverter`3[[System.Collections.Generic.Dictionary`2[[System.String,System.Private.CoreLib],[System.Object,System.Private.CoreLib]],System.Private.CoreLib],[System.String,System.Private.CoreLib],[System.Object,System.Private.CoreLib]]" Dynamic="Required All" />
</Assembly>
<Assembly Name="Microsoft.AspNetCore.Mvc.Razor">
<Type Name="Microsoft.AspNetCore.Mvc.ApplicationParts.ConsolidatedAssemblyApplicationPartFactory" Dynamic="Required All" />
</Assembly>
<Assembly Name="Microsoft.AspNetCore.Mvc.Core" Dynamic="Required All">
<Type Name="Microsoft.Extensions.Internal.PropertyHelper">
<Method Name="CallPropertySetter" Dynamic="Required">
<GenericArgument Name="Microsoft.AspNetCore.Mvc.Razor.RazorPageBase, Microsoft.AspNetCore.Mvc.Razor" />
<GenericArgument Name="System.Boolean, System.Private.CoreLib" />
</Method>
</Type>
</Assembly>
</Application>
</Directives>
17 changes: 7 additions & 10 deletions src/AspNetCore/Example/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,21 @@ public void ConfigureServices(IServiceCollection services)
services.AddLogging(builder => builder.AddConsole());
services.AddHttpContextAccessor();

services.AddGraphQL(options =>
{
options.EnableMetrics = true;
})
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true)
.AddSystemTextJson()
.AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User });
#pragma warning disable CS0612 // Type or member is obsolete
services
.AddGraphQL(options => options.EnableMetrics = true)
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true)
.AddSystemTextJson()
.AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User });
#pragma warning restore CS0612 // Type or member is obsolete
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();

// add http for Schema at default url /graphql
app.UseGraphQL<ISchema>();

// use graphql-playground at default url /ui/playground
app.UseGraphQLPlayground();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/AspNetCoreCustom/Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="5.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 9 additions & 5 deletions src/AspNetCoreCustom/Example/GraphQLMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ private async Task ExecuteAsync(HttpContext context, ISchema schema)
{
var request = Deserialize<GraphQLRequest>(context.Request.Body);

var start = DateTime.UtcNow;

var result = await _executer.ExecuteAsync(_ =>
{
_.Schema = schema;
_.Query = request?.Query;
_.OperationName = request?.OperationName;
_.Inputs = request?.Variables.ToInputs();
_.UserContext = _settings.BuildUserContext?.Invoke(context);
_.ValidationRules = DocumentValidator.CoreRules.Concat(new [] { new InputValidationRule() });
_.ValidationRules = DocumentValidator.CoreRules.Concat(new[] { new InputValidationRule() });
_.EnableMetrics = _settings.EnableMetrics;
if (_settings.EnableMetrics)
{
_.FieldMiddleware.Use<InstrumentFieldsMiddleware>();
}
});


if (_settings.EnableMetrics)
{
result.EnrichWithApolloTracing(start);
}

await WriteResponseAsync(context, result);
}

Expand Down
6 changes: 3 additions & 3 deletions src/AspNetCoreMulti/Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="5.2.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="5.2.0" />
</ItemGroup>

</Project>
18 changes: 9 additions & 9 deletions src/AspNetCoreMulti/Example/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public void ConfigureServices(IServiceCollection services)
services.AddLogging(builder => builder.AddConsole());
services.AddHttpContextAccessor();

services.AddGraphQL(options =>
{
options.EnableMetrics = true;
})
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true)
.AddSystemTextJson()
.AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User });
#pragma warning disable CS0612 // Type or member is obsolete
services
.AddGraphQL(options => options.EnableMetrics = true)
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true)
.AddSystemTextJson()
.AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User });
#pragma warning restore CS0612 // Type or member is obsolete
Comment on lines +23 to +29
Copy link
Member

Choose a reason for hiding this comment

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

Should use non-obsolete methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll change usages after April release.

}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand All @@ -37,8 +37,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseGraphQL<DogSchema>("/api/dogs");
app.UseGraphQL<CatSchema>("/api/cats");

app.UseGraphQLPlayground(new GraphQLPlaygroundOptions { GraphQLEndPoint = "/api/dogs", Path = "/ui/dogs" });
app.UseGraphQLPlayground(new GraphQLPlaygroundOptions { GraphQLEndPoint = "/api/cats", Path = "/ui/cats" });
app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/dogs" }, "/ui/dogs");
app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/cats" }, "/ui/cats");
}
}
}
1 change: 0 additions & 1 deletion src/AspNetWebApi/WebApi/Controllers/GraphQLController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public async Task<HttpResponseMessage> PostAsync(HttpRequestMessage request, Gra
_.Inputs = inputs;

_.ComplexityConfiguration = new ComplexityConfiguration { MaxDepth = 15 };
_.FieldMiddleware.Use<InstrumentFieldsMiddleware>();

}).ConfigureAwait(false);

Expand Down
Loading