Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return status codes from Fusion CLI commands #7001

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

[RequiresUnreferencedCode(
"Calls System.Text.Json.JsonSerializer.SerializeToDocument<TValue>(TValue, JsonSerializerOptions)")]
private static async Task ExecuteAsync(
private static async Task<int> ExecuteAsync(
IConsole console,
FileInfo packageFile,
List<string>? subgraphPackageFiles,
Expand Down Expand Up @@ -125,7 +125,7 @@
if (settings is null)
{
console.WriteLine("Fusion graph settings are invalid.");
return;
return 1;

Check warning on line 128 in src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L128 was not covered by tests
}

if (enableNodes.HasValue && enableNodes.Value)
Expand All @@ -145,7 +145,7 @@
if (fusionGraph is null)
{
console.WriteLine("Fusion graph composition failed.");
return;
return 1;

Check warning on line 148 in src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L148 was not covered by tests
}

var fusionGraphDoc = Utf8GraphQLParser.Parse(SchemaFormatter.FormatAsString(fusionGraph));
Expand All @@ -164,6 +164,8 @@
}

console.WriteLine("Fusion graph composed.");

return 0;
}

private static FusionFeatureCollection CreateFeatures(
Expand Down Expand Up @@ -382,4 +384,4 @@
[JsonPropertyOrder(10)]
public string? DefaultClientName { get; set; } = "Fusion";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

var graphFile = new Option<FileInfo?>("--file");
graphFile.AddAlias("-f");

AddOption(fusionPackageFile);
AddOption(graphFile);

Expand All @@ -31,40 +31,42 @@
Bind.FromServiceProvider<CancellationToken>());
}

private static async Task ExecuteAsync(
private static async Task<int> 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));
packageFile = new FileInfo(Combine(packageFile.FullName, "gateway" + FusionPackage));

Check warning on line 46 in src/HotChocolate/Fusion/src/CommandLine/Commands/ExportGraphCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L46 was not covered by tests
}
else if (!packageFile.Extension.EqualsOrdinal(FusionPackage) &&
!packageFile.Extension.EqualsOrdinal(ZipPackage))
{
packageFile = new FileInfo(packageFile.FullName + FusionPackage);
packageFile = new FileInfo(packageFile.FullName + FusionPackage);

Check warning on line 51 in src/HotChocolate/Fusion/src/CommandLine/Commands/ExportGraphCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L51 was not covered by tests
}

if (!packageFile.Exists)
{
console.WriteLine($"The package file `{packageFile.FullName}` does not exist.");
return;
return 1;

Check warning on line 57 in src/HotChocolate/Fusion/src/CommandLine/Commands/ExportGraphCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L57 was not covered by tests
}
}

graphFile ??= new FileInfo(Combine(packageFile.DirectoryName!, "fusion.graphql"));

await using var package = FusionGraphPackage.Open(packageFile.FullName);

var graph = await package.GetFusionGraphAsync(cancellationToken);
var options = new SyntaxSerializerOptions { Indented = true, MaxDirectivesPerLine = 0, };

await File.WriteAllTextAsync(graphFile.FullName, graph.ToString(options), Encoding.UTF8, cancellationToken);

Check warning on line 69 in src/HotChocolate/Fusion/src/CommandLine/Commands/ExportGraphCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L69 was not covered by tests
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Bind.FromServiceProvider<CancellationToken>());
}

private static async Task ExecuteAsync(
private static async Task<int> ExecuteAsync(
IConsole console,
FileInfo? packageFile,
FileInfo? schemaFile,
Expand All @@ -56,13 +56,13 @@
if (!schemaFile.Exists)
{
console.WriteLine($"The schema file `{schemaFile.FullName}` does not exist.");
return;
return 1;

Check warning on line 59 in src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L59 was not covered by tests
}

if (!configFile.Exists)
{
console.WriteLine($"The config file `{configFile.FullName}` does not exist.");
return;
return 1;

Check warning on line 65 in src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L65 was not covered by tests
}

if (extensionFiles.Count == 0)
Expand All @@ -81,7 +81,7 @@
{
console.WriteLine(
$"The extension file `{extensionFiles.First(t => !t.Exists).FullName}` does not exist.");
return;
return 1;

Check warning on line 84 in src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L84 was not covered by tests
}

if (packageFile is null)
Expand Down Expand Up @@ -115,5 +115,7 @@
cancellationToken);

console.WriteLine($"{packageFile.FullName} created.");

Check warning on line 118 in src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L118 was not covered by tests
return 0;
}
}
Loading