Skip to content

Commit 09cddda

Browse files
authored
Add NativeAOT sample; bump GraphQL.NET to 8.3.0 (#1180)
1 parent 5e869ad commit 09cddda

13 files changed

+177
-3
lines changed

.github/workflows/test.yml

+68-2
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,81 @@ jobs:
7171
with:
7272
files: .coverage/GraphQL.Server.Transports.AspNetCore.Tests/coverage.net7.0.opencover.xml,.coverage/GraphQL.Server.Transports.AspNetCore.Tests/coverage.netcoreapp2.1.opencover.xml,.coverage/GraphQL.Server.Samples.Server.Tests/coverage.net7.0.opencover.xml
7373

74+
nativeaot:
75+
strategy:
76+
matrix:
77+
os: [ubuntu-latest, windows-latest]
78+
name: NativeAOT Sample on ${{ matrix.os }}
79+
runs-on: ${{ matrix.os }}
80+
steps:
81+
- name: Checkout source
82+
uses: actions/checkout@v4
83+
- name: Setup .NET SDK for NativeAOT
84+
uses: actions/setup-dotnet@v4
85+
with:
86+
dotnet-version: 8.0.x
87+
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
88+
env:
89+
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
- name: Publish NativeAOT sample
91+
working-directory: samples/Samples.NativeAot
92+
run: dotnet publish -c Release -o published
93+
- name: Start NativeAOT sample in background
94+
working-directory: samples/Samples.NativeAot/published
95+
shell: bash
96+
run: |
97+
if [ "$RUNNER_OS" == "Windows" ]; then
98+
./GraphQL.Server.Samples.NativeAot.exe &
99+
else
100+
./GraphQL.Server.Samples.NativeAot &
101+
fi
102+
- name: Wait for NativeAOT sample to spin up
103+
shell: bash
104+
run: |
105+
# Disable exit-on-error to allow retries
106+
set +e
107+
for i in {1..60}; do
108+
echo "Request $i to the GraphQL endpoint..."
109+
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/ || true)
110+
if [ "$response" -eq 200 ]; then
111+
echo "Received 200 response, NativeAOT sample is ready."
112+
exit 0
113+
fi
114+
echo "Did not receive a 200 response, sleeping for 0.5 second..."
115+
sleep 0.5
116+
done
117+
echo "NativeAOT sample did not spin up in time."
118+
exit 1
119+
- name: Run GraphQL query against NativeAOT sample
120+
working-directory: samples/Samples.NativeAot
121+
shell: bash
122+
run: |
123+
# Run a simple GraphQL query. Adjust the request as needed for your sample.
124+
curl -X POST -H "Content-Type: application/json" \
125+
-d @sample-request.json \
126+
http://localhost:5000/graphql > nativeaot_response.json
127+
- name: Print query result
128+
working-directory: samples/Samples.NativeAot
129+
shell: bash
130+
run: cat nativeaot_response.json
131+
- name: Compare query result to expected response
132+
working-directory: samples/Samples.NativeAot
133+
shell: bash
134+
run: |
135+
jq . nativeaot_response.json > actual-response.json
136+
jq . sample-response.json > expected-response.json
137+
diff -b actual-response.json expected-response.json
138+
74139
buildcheck:
75140
needs:
76141
- test
142+
- nativeaot
77143
runs-on: ubuntu-latest
78144
if: always()
79145
steps:
80146
- name: Pass build check
81-
if: ${{ needs.test.result == 'success' }}
147+
if: ${{ needs.test.result == 'success' && needs.nativeaot.result == 'success' }}
82148
run: exit 0
83149
- name: Fail build check
84-
if: ${{ needs.test.result != 'success' }}
150+
if: ${{ needs.test.result != 'success' || needs.nativeaot.result != 'success' }}
85151
run: exit 1

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<RootNamespace>GraphQL.Server.$(MSBuildProjectName)</RootNamespace>
3333
<PackageId>GraphQL.Server.$(MSBuildProjectName)</PackageId>
3434

35-
<GraphQLVersion>[8.2.1,9.0.0)</GraphQLVersion>
35+
<GraphQLVersion>[8.3.0,9.0.0)</GraphQLVersion>
3636

3737
<SignAssembly>true</SignAssembly>
3838
<_FriendAssembliesPublicKey>PublicKey=0024000004800000940000000602000000240000525341310004000001000100352162dbf27be78fc45136884b8f324aa9f1dfc928c96c24704bf1df1a8779b2f26c760ed8321eca5b95ea6bd9bb60cd025b300f73bd1f4ae1ee6e281f85c527fa013ab5cb2c3fc7a1cbef7f9bf0c9014152e6a21f6e0ac6a371f8b45c6d7139c9119df9eeecf1cf59063545bb7c07437b1bc12be2c57d108d72d6c27176fbb8</_FriendAssembliesPublicKey>

GraphQL.Server.sln

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.Upload", "samples\S
122122
EndProject
123123
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.Upload.Tests", "tests\Samples.Upload.Tests\Samples.Upload.Tests.csproj", "{DE3059F4-B548-4091-BFC0-5879246A2DF9}"
124124
EndProject
125+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.NativeAot", "samples\Samples.NativeAot\Samples.NativeAot.csproj", "{56042483-2E36-41DF-9DC4-71DC527A36E4}"
126+
EndProject
125127
Global
126128
GlobalSection(SolutionConfigurationPlatforms) = preSolution
127129
Debug|Any CPU = Debug|Any CPU
@@ -264,6 +266,10 @@ Global
264266
{DE3059F4-B548-4091-BFC0-5879246A2DF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
265267
{DE3059F4-B548-4091-BFC0-5879246A2DF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
266268
{DE3059F4-B548-4091-BFC0-5879246A2DF9}.Release|Any CPU.Build.0 = Release|Any CPU
269+
{56042483-2E36-41DF-9DC4-71DC527A36E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
270+
{56042483-2E36-41DF-9DC4-71DC527A36E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
271+
{56042483-2E36-41DF-9DC4-71DC527A36E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
272+
{56042483-2E36-41DF-9DC4-71DC527A36E4}.Release|Any CPU.Build.0 = Release|Any CPU
267273
EndGlobalSection
268274
GlobalSection(SolutionProperties) = preSolution
269275
HideSolutionNode = FALSE
@@ -304,6 +310,7 @@ Global
304310
{A204E359-05E8-4CEE-891C-4CCA6570FA52} = {BBD07745-C962-4D2D-B302-6DA1BCC2FF43}
305311
{33E2CDF5-F854-4F1A-80D5-DBF0BDF8EEA8} = {5C07AFA3-12F2-40EA-807D-7A1EEF29012B}
306312
{DE3059F4-B548-4091-BFC0-5879246A2DF9} = {BBD07745-C962-4D2D-B302-6DA1BCC2FF43}
313+
{56042483-2E36-41DF-9DC4-71DC527A36E4} = {5C07AFA3-12F2-40EA-807D-7A1EEF29012B}
307314
EndGlobalSection
308315
GlobalSection(ExtensibilityGlobals) = postSolution
309316
SolutionGuid = {3FC7FA59-E938-453C-8C4A-9D5635A9489A}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ typical ASP.NET Core scenarios.
11381138
| EndpointRouting | .NET 8 Minimal | Demonstrates configuring GraphQL through endpoint routing |
11391139
| Jwt | .NET 8 Minimal | Demonstrates authenticating GraphQL requests with a JWT bearer token over HTTP POST and WebSocket connections |
11401140
| MultipleSchemas | .NET 8 Minimal | Demonstrates configuring multiple schemas within a single server |
1141+
| NativeAot | .NET 8 Slim | Demonstrates configuring GraphQL for Native AOT publishing |
11411142
| Net48 | .NET Core 2.1 / .NET 4.8 | Demonstrates configuring GraphQL on .NET 4.8 / Core 2.1 |
11421143
| Pages | .NET 8 Minimal | Demonstrates configuring GraphQL on top of a Razor Pages template |
11431144
| Upload | .NET 8 Minimal | Demonstrates uploading files via the `multipart/form-data` content type |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using GraphQL.Types;
2+
3+
namespace GraphQL.Server.Samples.NativeAot.GraphTypes;
4+
5+
public class QueryType : ObjectGraphType
6+
{
7+
public QueryType()
8+
{
9+
Field<StringGraphType>("hello")
10+
.Resolve(context => "world");
11+
}
12+
}

samples/Samples.NativeAot/MySchema.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using GraphQL.Server.Samples.NativeAot.GraphTypes;
2+
using GraphQL.Types;
3+
4+
namespace GraphQL.Server.Samples.NativeAot;
5+
6+
public class MySchema : Schema
7+
{
8+
public MySchema(IServiceProvider services, QueryType queryType)
9+
: base(services)
10+
{
11+
Query = queryType;
12+
}
13+
}

samples/Samples.NativeAot/Program.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using GraphQL;
2+
using GraphQL.Server.Samples.NativeAot;
3+
using GraphQL.Server.Samples.NativeAot.GraphTypes;
4+
5+
var builder = WebApplication.CreateSlimBuilder(args);
6+
7+
builder.Services.AddGraphQL(b => b
8+
.AddSchema<MySchema>()
9+
.AddSystemTextJson());
10+
11+
builder.Services.AddTransient<QueryType>();
12+
13+
var app = builder.Build();
14+
15+
app.UseGraphQLGraphiQL("/");
16+
app.UseGraphQL();
17+
18+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"launchUrl": "",
9+
"applicationUrl": "http://localhost:5003",
10+
"environmentVariables": {
11+
"ASPNETCORE_ENVIRONMENT": "Development"
12+
}
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<InvariantGlobalization>true</InvariantGlobalization>
8+
<PublishAot>true</PublishAot>
9+
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\Transports.AspNetCore\Transports.AspNetCore.csproj" />
14+
<ProjectReference Include="..\..\src\Ui.GraphiQL\Ui.GraphiQL.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"query": "{ hello }"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"data": {
3+
"hello": "world"
4+
}
5+
}

0 commit comments

Comments
 (0)