Skip to content

Commit d9517b1

Browse files
Return status codes from Fusion CLI commands (#7001)
1 parent 184f1e2 commit d9517b1

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ComposeCommand() : base("compose")
6363

6464
[RequiresUnreferencedCode(
6565
"Calls System.Text.Json.JsonSerializer.SerializeToDocument<TValue>(TValue, JsonSerializerOptions)")]
66-
private static async Task ExecuteAsync(
66+
private static async Task<int> ExecuteAsync(
6767
IConsole console,
6868
FileInfo packageFile,
6969
List<string>? subgraphPackageFiles,
@@ -125,7 +125,7 @@ private static async Task ExecuteAsync(
125125
if (settings is null)
126126
{
127127
console.WriteLine("Fusion graph settings are invalid.");
128-
return;
128+
return 1;
129129
}
130130

131131
if (enableNodes.HasValue && enableNodes.Value)
@@ -145,7 +145,7 @@ private static async Task ExecuteAsync(
145145
if (fusionGraph is null)
146146
{
147147
console.WriteLine("Fusion graph composition failed.");
148-
return;
148+
return 1;
149149
}
150150

151151
var fusionGraphDoc = Utf8GraphQLParser.Parse(SchemaFormatter.FormatAsString(fusionGraph));
@@ -164,6 +164,8 @@ private static async Task ExecuteAsync(
164164
}
165165

166166
console.WriteLine("Fusion graph composed.");
167+
168+
return 0;
167169
}
168170

169171
private static FusionFeatureCollection CreateFeatures(
@@ -382,4 +384,4 @@ public sealed class Transport
382384
[JsonPropertyOrder(10)]
383385
public string? DefaultClientName { get; set; } = "Fusion";
384386
}
385-
}
387+
}

src/HotChocolate/Fusion/src/CommandLine/Commands/ExportGraphCommand.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ExportGraphCommand() : base("graph")
1919

2020
var graphFile = new Option<FileInfo?>("--file");
2121
graphFile.AddAlias("-f");
22-
22+
2323
AddOption(fusionPackageFile);
2424
AddOption(graphFile);
2525

@@ -31,40 +31,42 @@ public ExportGraphCommand() : base("graph")
3131
Bind.FromServiceProvider<CancellationToken>());
3232
}
3333

34-
private static async Task ExecuteAsync(
34+
private static async Task<int> ExecuteAsync(
3535
IConsole console,
3636
FileInfo? packageFile,
3737
FileInfo? graphFile,
3838
CancellationToken cancellationToken)
3939
{
4040
packageFile ??= new FileInfo(Combine(Environment.CurrentDirectory, "gateway" + FusionPackage));
41-
41+
4242
if (!packageFile.Exists)
4343
{
4444
if (Directory.Exists(packageFile.FullName))
4545
{
46-
packageFile = new FileInfo(Combine(packageFile.FullName, "gateway" + FusionPackage));
46+
packageFile = new FileInfo(Combine(packageFile.FullName, "gateway" + FusionPackage));
4747
}
4848
else if (!packageFile.Extension.EqualsOrdinal(FusionPackage) &&
4949
!packageFile.Extension.EqualsOrdinal(ZipPackage))
5050
{
51-
packageFile = new FileInfo(packageFile.FullName + FusionPackage);
51+
packageFile = new FileInfo(packageFile.FullName + FusionPackage);
5252
}
5353

5454
if (!packageFile.Exists)
5555
{
5656
console.WriteLine($"The package file `{packageFile.FullName}` does not exist.");
57-
return;
57+
return 1;
5858
}
5959
}
6060

6161
graphFile ??= new FileInfo(Combine(packageFile.DirectoryName!, "fusion.graphql"));
62-
62+
6363
await using var package = FusionGraphPackage.Open(packageFile.FullName);
6464

6565
var graph = await package.GetFusionGraphAsync(cancellationToken);
6666
var options = new SyntaxSerializerOptions { Indented = true, MaxDirectivesPerLine = 0, };
67-
67+
6868
await File.WriteAllTextAsync(graphFile.FullName, graph.ToString(options), Encoding.UTF8, cancellationToken);
69+
70+
return 0;
6971
}
70-
}
72+
}

src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public SubgraphPackCommand() : base("pack")
3737
Bind.FromServiceProvider<CancellationToken>());
3838
}
3939

40-
private static async Task ExecuteAsync(
40+
private static async Task<int> ExecuteAsync(
4141
IConsole console,
4242
FileInfo? packageFile,
4343
FileInfo? schemaFile,
@@ -56,13 +56,13 @@ private static async Task ExecuteAsync(
5656
if (!schemaFile.Exists)
5757
{
5858
console.WriteLine($"The schema file `{schemaFile.FullName}` does not exist.");
59-
return;
59+
return 1;
6060
}
6161

6262
if (!configFile.Exists)
6363
{
6464
console.WriteLine($"The config file `{configFile.FullName}` does not exist.");
65-
return;
65+
return 1;
6666
}
6767

6868
if (extensionFiles.Count == 0)
@@ -81,7 +81,7 @@ private static async Task ExecuteAsync(
8181
{
8282
console.WriteLine(
8383
$"The extension file `{extensionFiles.First(t => !t.Exists).FullName}` does not exist.");
84-
return;
84+
return 1;
8585
}
8686

8787
if (packageFile is null)
@@ -115,5 +115,7 @@ await CreateSubgraphPackageAsync(
115115
cancellationToken);
116116

117117
console.WriteLine($"{packageFile.FullName} created.");
118+
119+
return 0;
118120
}
119121
}

0 commit comments

Comments
 (0)