-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced Fusion Export Command (#6541)
- Loading branch information
1 parent
dd6c3cd
commit af204e7
Showing
5 changed files
with
90 additions
and
1 deletion.
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
1 change: 1 addition & 0 deletions
1
src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.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
19 changes: 19 additions & 0 deletions
19
src/HotChocolate/Fusion/src/CommandLine/Commands/ExportCommand.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,19 @@ | ||
using System.CommandLine; | ||
|
||
namespace HotChocolate.Fusion.CommandLine.Commands; | ||
|
||
/// <summary> | ||
/// The export command | ||
/// </summary> | ||
internal sealed class ExportCommand : Command | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="ExportCommand"/>. | ||
/// </summary> | ||
public ExportCommand() : base("export") | ||
{ | ||
Description = "Export commands."; | ||
|
||
AddCommand(new ExportGraphCommand()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/HotChocolate/Fusion/src/CommandLine/Commands/ExportGraphCommand.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,65 @@ | ||
using System.CommandLine; | ||
using System.Text; | ||
using HotChocolate.Fusion.CommandLine.Helpers; | ||
using HotChocolate.Utilities; | ||
using static System.IO.Path; | ||
using static HotChocolate.Fusion.CommandLine.Extensions; | ||
|
||
namespace HotChocolate.Fusion.CommandLine.Commands; | ||
|
||
internal sealed class ExportGraphCommand : Command | ||
{ | ||
public ExportGraphCommand() : base("graph") | ||
{ | ||
var fusionPackageFile = new Option<FileInfo?>("--package-file"); | ||
fusionPackageFile.AddAlias("--package"); | ||
fusionPackageFile.AddAlias("-p"); | ||
|
||
var graphFile = new Option<FileInfo?>("--file"); | ||
graphFile.AddAlias("-f"); | ||
|
||
AddOption(fusionPackageFile); | ||
AddOption(graphFile); | ||
|
||
this.SetHandler( | ||
ExecuteAsync, | ||
Bind.FromServiceProvider<IConsole>(), | ||
fusionPackageFile, | ||
graphFile, | ||
Bind.FromServiceProvider<CancellationToken>()); | ||
} | ||
|
||
private static async Task ExecuteAsync( | ||
IConsole console, | ||
FileInfo? packageFile, | ||
FileInfo? graphFile, | ||
CancellationToken cancellationToken) | ||
{ | ||
packageFile ??= new FileInfo(Combine(Environment.CurrentDirectory, "gateway" + FusionPackage)); | ||
|
||
if (!packageFile.Exists) | ||
{ | ||
if (Directory.Exists(packageFile.FullName)) | ||
{ | ||
packageFile = new FileInfo(Combine(packageFile.FullName, "gateway" + FusionPackage)); | ||
} | ||
else if (!packageFile.Extension.EqualsOrdinal(FusionPackage) && | ||
!packageFile.Extension.EqualsOrdinal(ZipPackage)) | ||
{ | ||
packageFile = new FileInfo(packageFile.FullName + FusionPackage); | ||
} | ||
|
||
if (!packageFile.Exists) | ||
{ | ||
console.WriteLine($"The package file `{packageFile.FullName}` does not exist."); | ||
return; | ||
} | ||
} | ||
|
||
graphFile ??= new FileInfo(Combine(packageFile.DirectoryName!, "fusion.graphql")); | ||
|
||
await using var package = FusionGraphPackage.Open(packageFile.FullName); | ||
var graph = await package.GetFusionGraphAsync(cancellationToken); | ||
await File.WriteAllTextAsync(graphFile.FullName, graph.ToString(true), Encoding.UTF8, cancellationToken); | ||
} | ||
} |
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