Skip to content

Commit 1dec109

Browse files
authored
Improve GraphQL configuration (#93)
Frontend - build using vite - make defer-directive work (resolves Optimize relay config #69) - persisted queries (resolves Persisted queries #74) Backend - only allow persisted queries (resolves Persisted queries #74) - react relay persisted-query.json (resolves Persisted queries #74)
1 parent c1d2494 commit 1dec109

File tree

301 files changed

+2046
-10586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

301 files changed

+2046
-10586
lines changed

src/Backend/src/Authoring.GraphQL/Authoring.GraphQL.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,15 @@
3131
<Folder Include="Vault.Authentication" />
3232
</ItemGroup>
3333

34+
<ItemGroup>
35+
<EmbeddedResource Include="../../../Frontend/persisted_queries.json" Pack="true" CopyToOutputDirectory="Always">
36+
<LogicalName>Confix.Authoring.GraphQL.Persisted.UI</LogicalName>
37+
</EmbeddedResource>
38+
<EmbeddedResource Include="../Tooling/persisted/queries.json" Pack="true" CopyToOutputDirectory="Always">
39+
<LogicalName>Confix.Authoring.GraphQL.Persisted.Tooling</LogicalName>
40+
</EmbeddedResource>
41+
<EmbeddedResource Include="../Vault.Configuration/persisted/queries.json" Pack="true" CopyToOutputDirectory="Always">
42+
<LogicalName>Confix.Authoring.GraphQL.Persisted.Vault</LogicalName>
43+
</EmbeddedResource>
44+
</ItemGroup>
3445
</Project>

src/Backend/src/Authoring.GraphQL/GraphQLServiceCollectionExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System.Diagnostics;
12
using HotChocolate.Diagnostics;
3+
using HotChocolate.Execution;
24
using HotChocolate.Execution.Configuration;
35
using Microsoft.Extensions.DependencyInjection;
46

@@ -43,12 +45,15 @@ public static IRequestExecutorBuilder AddConfixSchema(this IRequestExecutorBuild
4345
o.Scopes = ActivityScopes.Default;
4446
})
4547
.AddDiagnosticEventListener<ErrorLoggingDiagnosticEventListener>()
48+
.ConfigureSchemaServices(x => x.AddSingleton<IReadStoredQueries, RelayResourceManifestQueryStorage>())
4649
.ModifyOptions(x =>
4750
{
4851
x.EnableFlagEnums = true;
4952
x.EnableOneOf = true;
5053
x.EnableDefer = true;
51-
});
54+
})
55+
.ModifyRequestOptions(o => o.OnlyAllowPersistedQueries = !Debugger.IsAttached)
56+
.UsePersistedQueryPipeline();
5257

5358
return builder;
5459
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Confix.Authoring.GraphQL.Tests")]
4+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Reflection;
2+
using System.Text.Json;
3+
using HotChocolate.Execution;
4+
using HotChocolate.Language;
5+
6+
namespace Confix.Authoring.GraphQL;
7+
8+
internal sealed class RelayResourceManifestQueryStorage : IReadStoredQueries
9+
{
10+
private readonly Dictionary<string, QueryDocument> _lookup = new();
11+
12+
public RelayResourceManifestQueryStorage()
13+
{
14+
LoadQueries("Confix.Authoring.GraphQL.Persisted.UI");
15+
LoadQueries("Confix.Authoring.GraphQL.Persisted.Tooling");
16+
LoadQueries("Confix.Authoring.GraphQL.Persisted.Vault");
17+
}
18+
19+
private void LoadQueries(string resourceName)
20+
{
21+
Assembly assembly = typeof(RelayResourceManifestQueryStorage).Assembly;
22+
using Stream? jsonStream = assembly.GetManifestResourceStream(resourceName);
23+
24+
if (jsonStream is not null &&
25+
JsonSerializer.Deserialize<Dictionary<string, string>>(jsonStream) is { } queries)
26+
{
27+
foreach (var (key, query) in queries)
28+
{
29+
_lookup[key] = new QueryDocument(Utf8GraphQLParser.Parse(query));
30+
}
31+
}
32+
}
33+
34+
/// <inheritdoc />
35+
public Task<QueryDocument?> TryReadQueryAsync(
36+
string queryId,
37+
CancellationToken cancellationToken = default)
38+
{
39+
if (string.IsNullOrWhiteSpace(queryId))
40+
{
41+
throw new ArgumentNullException(nameof(queryId));
42+
}
43+
44+
return Task.FromResult(_lookup.GetValueOrDefault(queryId));
45+
}
46+
}

src/Backend/src/Authoring.Host/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
var builder = WebApplication.CreateBuilder(args);
1111

12+
builder.Configuration
13+
.AddJsonFile("appsettings.json")
14+
.AddJsonFile("appsettings.user.json", true)
15+
.AddJsonFile("appsettings.Development.json", true);
16+
1217
builder.Services
1318
.AddConfixAuthoringServer()
1419
.UseMongoDbStores()

src/Backend/src/Authoring.Host/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"environmentVariables": {
1111
"ASPNETCORE_ENVIRONMENT": "Development"
1212
},
13-
"applicationUrl": "http://localhost:5000"
13+
"applicationUrl": "https://localhost:5000"
1414
}
1515
}
16-
}
16+
}

src/Backend/src/Authoring.Host/appsettings.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"LogLevel": {
44
"Default": "Information",
55
"Microsoft": "Warning",
6-
"Microsoft.Hosting.Lifetime": "Information"
6+
"Microsoft.Hosting.Lifetime": "Information",
7+
"Yarp":"Warning"
78
}
89
},
910
"AllowedHosts": "*",
@@ -29,16 +30,20 @@
2930
"AdminRequirement": {
3031
"Type": "sub",
3132
"Value": "[email protected]"
32-
}
33-
}
34-
},
35-
"Kestrel": {
36-
"Endpoints": {
37-
"Http": {
38-
"Url": "http://localhost:5000"
3933
},
40-
"Https": {
41-
"Url": "https://localhost:5001"
34+
"Database": {
35+
"Mongo": {
36+
"DatabaseName": "Confix",
37+
"ConnectionString": "mongodb://localhost:27017"
38+
}
39+
}
40+
},
41+
"Encryption": {
42+
"DataEncryptionKey": {
43+
"Mongo": {
44+
"DatabaseName": "Confix",
45+
"ConnectionString": "mongodb://localhost:27017"
46+
}
4247
}
4348
}
4449
},

src/Backend/src/Tooling/.graphqlrc.json

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,7 @@
77
"url": "http://localhost:5000/graphql/",
88
"dependencyInjection": true,
99
"strictSchemaValidation": true,
10-
"hashAlgorithm": "md5",
11-
"useSingleFile": true,
12-
"requestStrategy": "Default",
13-
"outputDirectoryName": "Generated",
14-
"noStore": false,
15-
"emitGeneratedCode": false,
16-
"razorComponents": false,
17-
"records": {
18-
"inputs": true,
19-
"entities": false
20-
},
21-
"transportProfiles": [
22-
{
23-
"default": "Http",
24-
"subscription": "WebSocket"
25-
}
26-
]
10+
"noStore": true
2711
}
2812
}
2913
}

src/Backend/src/Tooling/Tooling.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
<IsPackable>true</IsPackable>
1010
<PackAsTool>true</PackAsTool>
1111
<UseAppHost>false</UseAppHost>
12+
<GraphQLPersistedQueryOutput>persisted</GraphQLPersistedQueryOutput>
13+
<GraphQLPersistedQueryFormat>relay</GraphQLPersistedQueryFormat>
1214
</PropertyGroup>
1315

14-
1516
<ItemGroup>
1617
<PackageReference Include="System.CommandLine" />
1718
<PackageReference Include="Spectre.Console" />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"a3239eccea76f7eaa99c3e4bf24d3722": "mutation ClaimApplicationPart($input: ClaimVersionInput!) { claimVersion(input: $input) { __typename errors { __typename ... Error } result { __typename version { __typename ... ClaimedVersion } decryptionKey token } } } fragment Error on UserError { message code } fragment ClaimedVersion on ClaimedVersion { id tag claimedAt publishedApplicationPart { __typename version } }"
3+
}

0 commit comments

Comments
 (0)