-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue with the file watcher for the gateway
- Loading branch information
1 parent
215d5e5
commit fb87acc
Showing
6 changed files
with
179 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
src/HotChocolate/Fusion/test/CommandLine.Tests/ComposeCommandTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
using System.Collections.Concurrent; | ||
using System.CommandLine.Parsing; | ||
using CookieCrumble; | ||
using HotChocolate.Fusion; | ||
using HotChocolate.Fusion.CommandLine; | ||
using HotChocolate.Fusion.CommandLine.Helpers; | ||
using HotChocolate.Fusion.Composition; | ||
using HotChocolate.Fusion.Shared; | ||
using static HotChocolate.Fusion.Shared.DemoProjectSchemaExtensions; | ||
|
||
namespace CommandLine.Tests; | ||
|
||
public class ComposeCommandTests : IDisposable | ||
{ | ||
private readonly ConcurrentBag<string> _files = new(); | ||
|
||
[Fact] | ||
public async Task Compose_Fusion_Graph() | ||
{ | ||
// arrange | ||
using var demoProject = await DemoProject.CreateAsync(); | ||
var accountConfig = demoProject.Accounts.ToConfiguration(AccountsExtensionSdl); | ||
var account = CreateFiles(accountConfig); | ||
var subgraphPackageFile = CreateTempFile(); | ||
|
||
await PackageHelper.CreateSubgraphPackageAsync( | ||
subgraphPackageFile, | ||
new SubgraphFiles( | ||
account.SchemaFile, | ||
account.TransportConfigFile, | ||
account.ExtensionFiles)); | ||
|
||
var packageFile = CreateTempFile(); | ||
|
||
// act | ||
var app = App.CreateBuilder().Build(); | ||
await app.InvokeAsync(new[] | ||
{ | ||
"compose", | ||
"-p", | ||
packageFile, | ||
"-s", | ||
subgraphPackageFile | ||
}); | ||
|
||
// assert | ||
Assert.True(File.Exists(packageFile)); | ||
|
||
await using var package = FusionGraphPackage.Open(packageFile, FileAccess.Read); | ||
|
||
var fusionGraph = await package.GetFusionGraphAsync(); | ||
var schema = await package.GetSchemaAsync(); | ||
var subgraphs = await package.GetSubgraphConfigurationsAsync(); | ||
|
||
var snapshot = new Snapshot(); | ||
|
||
snapshot.Add(schema, "Schema Document"); | ||
snapshot.Add(fusionGraph, "Fusion Graph Document"); | ||
|
||
foreach (var subgraph in subgraphs) | ||
{ | ||
snapshot.Add(subgraph, $"{subgraph.Name} Subgraph Configuration"); | ||
} | ||
|
||
snapshot.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public async Task Compose_Fusion_Graph_Append_Subgraph() | ||
{ | ||
// arrange | ||
using var demoProject = await DemoProject.CreateAsync(); | ||
var accountConfig = demoProject.Accounts.ToConfiguration(AccountsExtensionSdl); | ||
var account = CreateFiles(accountConfig); | ||
var accountSubgraphPackageFile = CreateTempFile(); | ||
|
||
await PackageHelper.CreateSubgraphPackageAsync( | ||
accountSubgraphPackageFile, | ||
new SubgraphFiles( | ||
account.SchemaFile, | ||
account.TransportConfigFile, | ||
account.ExtensionFiles)); | ||
|
||
var reviewConfig = demoProject.Reviews2.ToConfiguration(ReviewsExtensionSdl); | ||
var review = CreateFiles(reviewConfig); | ||
var reviewSubgraphPackageFile = CreateTempFile(); | ||
|
||
await PackageHelper.CreateSubgraphPackageAsync( | ||
reviewSubgraphPackageFile, | ||
new SubgraphFiles( | ||
review.SchemaFile, | ||
review.TransportConfigFile, | ||
review.ExtensionFiles)); | ||
|
||
var packageFile = CreateTempFile(); | ||
|
||
var app = App.CreateBuilder().Build(); | ||
await app.InvokeAsync(new[] | ||
{ | ||
"compose", | ||
"-p", | ||
packageFile, | ||
"-s", | ||
accountSubgraphPackageFile | ||
}); | ||
|
||
// act | ||
app = App.CreateBuilder().Build(); | ||
await app.InvokeAsync(new[] | ||
{ | ||
"compose", | ||
"-p", | ||
packageFile, | ||
"-s", | ||
reviewSubgraphPackageFile | ||
}); | ||
|
||
// assert | ||
Assert.True(File.Exists(packageFile)); | ||
|
||
await using var package = FusionGraphPackage.Open(packageFile, FileAccess.Read); | ||
|
||
var fusionGraph = await package.GetFusionGraphAsync(); | ||
var schema = await package.GetSchemaAsync(); | ||
var subgraphs = await package.GetSubgraphConfigurationsAsync(); | ||
|
||
var snapshot = new Snapshot(); | ||
|
||
snapshot.Add(schema, "Schema Document"); | ||
snapshot.Add(fusionGraph, "Fusion Graph Document"); | ||
|
||
foreach (var subgraph in subgraphs) | ||
{ | ||
snapshot.Add(subgraph, $"{subgraph.Name} Subgraph Configuration"); | ||
} | ||
|
||
snapshot.MatchSnapshot(); | ||
} | ||
|
||
private Files CreateFiles(SubgraphConfiguration configuration) | ||
{ | ||
var files = new Files(CreateTempFile(), CreateTempFile(), new[] { CreateTempFile() }); | ||
var configJson = PackageHelper.FormatSubgraphConfig( | ||
new(configuration.Name, configuration.Clients)); | ||
File.WriteAllText(files.SchemaFile, configuration.Schema); | ||
File.WriteAllText(files.TransportConfigFile, configJson); | ||
File.WriteAllText(files.ExtensionFiles[0], configuration.Extensions[0]); | ||
return files; | ||
} | ||
|
||
private string CreateTempFile() | ||
{ | ||
var file = Path.GetTempFileName(); | ||
_files.Add(file); | ||
return file; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
while (_files.TryTake(out var file)) | ||
{ | ||
File.Delete(file); | ||
} | ||
} | ||
|
||
public record Files(string SchemaFile, string TransportConfigFile, string[] ExtensionFiles); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.