Skip to content

Commit b8bf8f6

Browse files
committed
Make GRAPHQL conditional
1 parent 9f71ebf commit b8bf8f6

4 files changed

Lines changed: 68 additions & 55 deletions

File tree

src/AasxServerAspNetCore/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ public void ConfigureServices(IServiceCollection services)
108108
services.AddTransient<IPersistenceService, EntityFrameworkPersistenceService>();
109109

110110
// Add GraphQL services
111+
#if GRAPHQL
111112
services
112113
.AddGraphQLServer()
113114
.AddQueryType<Query>();
115+
#endif
114116

115117
// Add framework services.
116118
services

src/AasxServerBlazor/AasxServerBlazor.csproj

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</PropertyGroup>
1010

1111
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
12-
<DefineConstants>DEBUG;TRACE;UseAasxCompatibilityModels</DefineConstants>
1312
<DebugType>portable</DebugType>
1413
<DebugSymbols>true</DebugSymbols>
1514
</PropertyGroup>
@@ -22,19 +21,21 @@
2221
<Using Include="AasCore.Aas3_0" />
2322
</ItemGroup>
2423

25-
<ItemGroup>
26-
<PackageReference Include="HotChocolate.AspNetCore" Version="13.9.6" />
27-
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.6" />
28-
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
29-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
30-
<PrivateAssets>all</PrivateAssets>
31-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
32-
</PackageReference>
33-
<PackageReference Include="ScottPlot" Version="4.1.74" />
34-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
35-
</ItemGroup>
24+
<ItemGroup Condition="'$(DefineConstants)' != '' and $(DefineConstants.Contains('GRAPHQL'))">
25+
<PackageReference Include="HotChocolate.AspNetCore" Version="13.9.6" />
26+
</ItemGroup>
27+
<ItemGroup>
28+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.6" />
29+
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
30+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
31+
<PrivateAssets>all</PrivateAssets>
32+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
33+
</PackageReference>
34+
<PackageReference Include="ScottPlot" Version="4.1.74" />
35+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
36+
</ItemGroup>
3637

37-
<ItemGroup>
38+
<ItemGroup>
3839
<ProjectReference Include="..\AasSecurity\AasSecurity.csproj" />
3940
<ProjectReference Include="..\AasxServerStandardBib\AasxServerStandardBib.csproj" />
4041
<ProjectReference Include="..\IO.Swagger.Lib.V3\IO.Swagger.Lib.V3.csproj" />
@@ -82,30 +83,30 @@
8283
<Folder Include="wwwroot\webfonts\" />
8384
</ItemGroup>
8485

85-
<ItemGroup>
86-
<None Include="schema.json">
87-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
88-
</None>
86+
<ItemGroup>
87+
<None Include="schema.json">
88+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
89+
</None>
8990
</ItemGroup>
9091

91-
<ItemGroup>
92-
<Content Update="Pages\Trustlist.razor">
93-
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
94-
</Content>
95-
<Content Update="Pages\Access.razor">
96-
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
97-
</Content>
92+
<ItemGroup>
93+
<Content Update="Pages\Trustlist.razor">
94+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
95+
</Content>
96+
<Content Update="Pages\Access.razor">
97+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
98+
</Content>
9899
</ItemGroup>
99100

100101
<ItemGroup>
101-
<None Update="accessrules.txt">
102-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
102+
<None Update="accessrules.txt">
103+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
103104
</None>
104-
<None Update="jsonschema-query.txt">
105-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
105+
<None Update="jsonschema-query.txt">
106+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
106107
</None>
107-
<None Update="jsonschema-access.txt">
108-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
108+
<None Update="jsonschema-access.txt">
109+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
109110
</None>
110111
<None Update="LICENSE.TXT">
111112
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>

src/AasxServerBlazor/Configuration/ServerConfiguration.cs

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ namespace AasxServerBlazor.Configuration;
3838
using System.Text.Json.Serialization;
3939
using AdminShellNS;
4040
using Contracts;
41+
#if GRAPHQL
42+
using HotChocolate.AspNetCore;
43+
#endif
4144
using IO.Swagger.Lib.V3.GraphQL;
4245

4346
public static class ServerConfiguration
@@ -65,23 +68,25 @@ public static void ConfigureServer(IServiceCollection services)
6568
ConfigureCors(services);
6669

6770
services.AddControllers();
68-
services.AddLazyResolution();
69-
71+
services.AddLazyResolution();
72+
73+
#if GRAPHQL
7074
services.AddGraphQLServer()
7175
.AddQueryType<GraphQLAPI>()
7276
.UseField<ParameterNamesMiddleware>()
7377
.SetRequestOptions(_ =>
7478
new HotChocolate.Execution.Options.RequestExecutorOptions {
7579
ExecutionTimeout = TimeSpan.FromMinutes(10),
7680
IncludeExceptionDetails = true
77-
});
81+
});
82+
#endif
7883
}
79-
80-
/// <summary>
81-
/// Adds framework-specific services required by the application.
82-
/// </summary>
83-
/// <param name="services">The collection of services to configure.</param>
84-
public static void AddFrameworkServices(IServiceCollection services)
84+
85+
/// <summary>
86+
/// Adds framework-specific services required by the application.
87+
/// </summary>
88+
/// <param name="services">The collection of services to configure.</param>
89+
public static void AddFrameworkServices(IServiceCollection services)
8590
{
8691
services.AddLogging(loggingBuilder => { loggingBuilder.AddConsole(); });
8792

@@ -139,31 +144,36 @@ public static void ConfigureEnvironment(IApplicationBuilder app, IWebHostEnviron
139144
app.UseRouting();
140145
app.UseAuthorization();
141146
app.UseCors(CorsPolicyName);
142-
147+
143148
app.UseEndpoints(ConfigureEndpoints);
144149
}
145150

146151
#region Endpoint Configuration
147152

148153
private static void ConfigureEndpoints(IEndpointRouteBuilder endpoints)
149-
{
154+
{
150155
endpoints.MapBlazorHub(options =>
151-
{
152-
// Do NOT use Websockets
153-
options.Transports =
154-
HttpTransportType.ServerSentEvents |
155-
HttpTransportType.LongPolling;
156-
});
156+
{
157+
// Do NOT use Websockets
158+
options.Transports =
159+
HttpTransportType.ServerSentEvents |
160+
HttpTransportType.LongPolling;
161+
});
157162
endpoints.MapFallbackToPage(FallbackHostPattern);
158163
endpoints.MapControllers();
159-
endpoints.MapGraphQL();
164+
#if GRAPHQL
165+
endpoints.MapGraphQL().WithOptions(new GraphQLServerOptions
166+
{
167+
Tool = { Enable = true }
168+
});
169+
#endif
160170
}
161-
162-
#endregion
163-
164-
#region Server Configuration
165-
166-
private static void ConfigureCors(IServiceCollection services) =>
171+
172+
#endregion
173+
174+
#region Server Configuration
175+
176+
private static void ConfigureCors(IServiceCollection services) =>
167177
services.AddCors(options =>
168178
{
169179
options.AddPolicy(CorsPolicyName, builder =>

src/AasxServerBlazor/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"AasxServerBlazor": {
1212
"commandName": "Project",
13-
"commandLineArgs": "--no-security --with-db --start-index 1000 --save-temp 5 --secret-string-api 1234 --data-path \"C:\\Development\\p5\" --edit --external-blazor http://localhost:5001",
13+
"commandLineArgs": "--with-db --start-index 1000 --save-temp 5 --secret-string-api 1234 --data-path \"C:\\Development\\p5\" --edit --external-blazor http://localhost:5001",
1414
"launchBrowser": true,
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development",

0 commit comments

Comments
 (0)