Skip to content
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 @@ -40,6 +40,7 @@ public FusionComposeCommand() : base("compose")
AddOption(watchModeOption);
AddOption(printSchemaOption);
AddOption(Opt<WorkingDirectoryOption>.Instance);
AddOption(Opt<ExcludeTagListOption>.Instance);

this.SetHandler(async context =>
{
Expand All @@ -51,6 +52,7 @@ public FusionComposeCommand() : base("compose")
var includeSatisfiabilityPaths = context.ParseResult.GetValueForOption(includeSatisfiabilityPathsOption);
var watchMode = context.ParseResult.GetValueForOption(watchModeOption);
var printSchema = context.ParseResult.GetValueForOption(printSchemaOption);
var tagsToExclude = context.ParseResult.GetValueForOption(Opt<ExcludeTagListOption>.Instance);

context.ExitCode = await ExecuteAsync(
context.Console,
Expand All @@ -62,6 +64,7 @@ public FusionComposeCommand() : base("compose")
includeSatisfiabilityPaths,
watchMode,
printSchema,
tagsToExclude,
context.GetCancellationToken());
});
}
Expand All @@ -76,6 +79,7 @@ private static async Task<int> ExecuteAsync(
bool? includeSatisfiabilityPaths,
bool watchMode,
bool printSchema,
List<string>? tagsToExclude,
CancellationToken cancellationToken)
{
archiveFile ??= workingDirectory;
Expand Down Expand Up @@ -119,6 +123,7 @@ private static async Task<int> ExecuteAsync(
environment,
enableGlobalObjectIdentification,
includeSatisfiabilityPaths,
tagsToExclude,
cancellationToken);
}

Expand All @@ -136,6 +141,10 @@ private static async Task<int> ExecuteAsync(
Satisfiability = new CompositionSettings.SatisfiabilitySettings
{
IncludeSatisfiabilityPaths = includeSatisfiabilityPaths
},
Preprocessor = new CompositionSettings.PreprocessorSettings
{
ExcludeByTag = tagsToExclude?.ToHashSet()
}
},
printSchema,
Expand All @@ -150,6 +159,7 @@ private static async Task<int> WatchComposeAsync(
string? environment,
bool? enableGlobalObjectIdentification,
bool? includeSatisfiabilityPaths,
List<string>? tagsToExclude,
CancellationToken cancellationToken)
{
console.Out.WriteLine("🔍 Starting watch mode...");
Expand All @@ -169,6 +179,10 @@ await ComposeAsync(
Satisfiability = new CompositionSettings.SatisfiabilitySettings
{
IncludeSatisfiabilityPaths = includeSatisfiabilityPaths
},
Preprocessor = new CompositionSettings.PreprocessorSettings
{
ExcludeByTag = tagsToExclude?.ToHashSet()
}
},
false,
Expand All @@ -194,6 +208,7 @@ await ComposeAsync(
environment,
enableGlobalObjectIdentification,
includeSatisfiabilityPaths,
tagsToExclude,
cancellationToken);

var sourceSchemaFileWatchers = new List<FileSystemWatcher>();
Expand Down Expand Up @@ -311,6 +326,7 @@ private static async Task ProcessCompositionRequestsAsync(
string? environment,
bool? enableGlobalObjectIdentification,
bool? includeSatisfiabilityPaths,
List<string>? tagsToExclude,
CancellationToken cancellationToken)
{
var lastComposition = DateTime.MinValue;
Expand Down Expand Up @@ -350,6 +366,10 @@ await ComposeAsync(
Satisfiability = new CompositionSettings.SatisfiabilitySettings
{
IncludeSatisfiabilityPaths = includeSatisfiabilityPaths
},
Preprocessor = new CompositionSettings.PreprocessorSettings
{
ExcludeByTag = tagsToExclude?.ToHashSet()
}
},
false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace ChilliCream.Nitro.CommandLine.Options;

public sealed class ExcludeTagListOption : Option<List<string>>
{
public ExcludeTagListOption() : this(false)
{
}

public ExcludeTagListOption(bool isRequired) : base("--exclude-by-tag")
{
Description = "One or more tags to exclude from the composition.";
IsRequired = isRequired;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public sealed class FusionComposeCommandTests : IDisposable
private static readonly string s_invalidExample1CompositeSchema =
File.ReadAllText("__resources__/invalid-example-1-result/composite-schema.graphqls");

private static readonly string s_validExcludeByTagCompositeSchema =
File.ReadAllText("__resources__/valid-exclude-by-tag-result/composite-schema.graphqls");

[Fact]
public async Task Compose_ValidExample1_FromSpecified_ToStdOut()
{
Expand Down Expand Up @@ -401,6 +404,43 @@ public async Task Compose_IgnoredNonAccessibleFields()
Assert.Equal(0, exitCode);
}

[Fact]
public async Task Compose_Valid_ExcludeTag()
{
// arrange
var archiveFileName = CreateTempFile();
var builder = GetCommandLineBuilder();

string[] args =
[
"fusion",
"compose",
"--source-schema-file",
"__resources__/valid-exclude-by-tag/source-schema-1.graphqls",
"--source-schema-file",
"__resources__/valid-exclude-by-tag/source-schema-2.graphqls",
"--exclude-by-tag",
"exclude-1",
"--exclude-by-tag",
"exclude-2",
"--archive",
archiveFileName
];
var testConsole = new TestConsole();

// act
var exitCode = await builder.Build().InvokeAsync(args, testConsole);

// assert
Assert.Equal(0, exitCode);

using var archive = FusionArchive.Open(archiveFileName);
var config = await archive.TryGetGatewayConfigurationAsync(WellKnownVersions.LatestGatewayFormatVersion);
Assert.NotNull(config);
var sourceText = await ReadSchemaAsync(config);
sourceText.ReplaceLineEndings("\n").MatchInlineSnapshot(s_validExcludeByTagCompositeSchema);
}

private static CommandLineBuilder GetCommandLineBuilder()
{
var rootCommand = new Command("nitro");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
schema {
query: Query
}

type Query
@fusion__type(schema: SCHEMA1)
@fusion__type(schema: SCHEMA2) {
schema1Field: Int!
@fusion__field(schema: SCHEMA1)
schema2Field: Int!
@fusion__field(schema: SCHEMA2)
}

"The fusion__Schema enum is a generated type used within an execution schema document to refer to a source schema in a type-safe manner."
enum fusion__Schema {
SCHEMA1
@fusion__schema_metadata(name: "Schema1")
SCHEMA2
@fusion__schema_metadata(name: "Schema2")
}

"The fusion__FieldDefinition scalar is used to represent a GraphQL field definition specified in the GraphQL spec."
scalar fusion__FieldDefinition

"The fusion__FieldSelectionMap scalar is used to represent the FieldSelectionMap type specified in the GraphQL Composite Schemas Spec."
scalar fusion__FieldSelectionMap

"The fusion__FieldSelectionPath scalar is used to represent a path of field names relative to the Query type."
scalar fusion__FieldSelectionPath

"The fusion__FieldSelectionSet scalar is used to represent a GraphQL selection set. To simplify the syntax, the outermost selection set is not wrapped in curly braces."
scalar fusion__FieldSelectionSet

"The @fusion__cost directive specifies cost metadata for each source schema."
directive @fusion__cost("The name of the source schema that defined the cost metadata." schema: fusion__Schema! "The weight defined in the source schema." weight: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM | INPUT_FIELD_DEFINITION

"The @fusion__enumValue directive specifies which source schema provides an enum value."
directive @fusion__enumValue("The name of the source schema that provides the specified enum value." schema: fusion__Schema!) repeatable on ENUM_VALUE

"The @fusion__field directive specifies which source schema provides a field in a composite type and what execution behavior it has."
directive @fusion__field("Indicates that this field is only partially provided and must be combined with `provides`." partial: Boolean! = false "A selection set of fields this field provides in the composite schema." provides: fusion__FieldSelectionSet "The name of the source schema that originally provided this field." schema: fusion__Schema! "The field type in the source schema if it differs in nullability or structure." sourceType: String) repeatable on FIELD_DEFINITION

"The @fusion__implements directive specifies on which source schema an interface is implemented by an object or interface type."
directive @fusion__implements("The name of the interface type." interface: String! "The name of the source schema on which the annotated type implements the specified interface." schema: fusion__Schema!) repeatable on OBJECT | INTERFACE

"The @fusion__inaccessible directive is used to prevent specific type system members from being accessible through the client-facing composite schema, even if they are accessible in the underlying source schemas."
directive @fusion__inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The @fusion__inputField directive specifies which source schema provides an input field in a composite input type."
directive @fusion__inputField("The name of the source schema that originally provided this input field." schema: fusion__Schema! "The field type in the source schema if it differs in nullability or structure." sourceType: String) repeatable on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION

"The @fusion__listSize directive specifies list size metadata for each source schema."
directive @fusion__listSize("The assumed size of the list as defined in the source schema." assumedSize: Int "The single slicing argument requirement of the list as defined in the source schema." requireOneSlicingArgument: Boolean "The name of the source schema that defined the list size metadata." schema: fusion__Schema! "The sized fields of the list as defined in the source schema." sizedFields: [String!] "The slicing argument default value of the list as defined in the source schema." slicingArgumentDefaultValue: Int "The slicing arguments of the list as defined in the source schema." slicingArguments: [String!]) repeatable on FIELD_DEFINITION

"The @fusion__lookup directive specifies how the distributed executor can resolve data for an entity type from a source schema by a stable key."
directive @fusion__lookup("The GraphQL field definition in the source schema that can be used to look up the entity." field: fusion__FieldDefinition! "Is the lookup meant as an entry point or just to provide more data." internal: Boolean! = false "A selection set on the annotated entity type that describes the stable key for the lookup." key: fusion__FieldSelectionSet! "The map describes how the key values are resolved from the annotated entity type." map: [fusion__FieldSelectionMap!]! "The path to the lookup field relative to the Query type." path: fusion__FieldSelectionPath "The name of the source schema where the annotated entity type can be looked up from." schema: fusion__Schema!) repeatable on OBJECT | INTERFACE | UNION

"The @fusion__requires directive specifies if a field has requirements on a source schema."
directive @fusion__requires("The GraphQL field definition in the source schema that this field depends on." field: fusion__FieldDefinition! "The map describes how the argument values for the source schema are resolved from the arguments of the field exposed in the client-facing composite schema and from required data relative to the current type." map: [fusion__FieldSelectionMap]! "A selection set on the annotated field that describes its requirements." requirements: fusion__FieldSelectionSet! "The name of the source schema where this field has requirements to data on other source schemas." schema: fusion__Schema!) repeatable on FIELD_DEFINITION

"The @fusion__schema_metadata directive is used to provide additional metadata for a source schema."
directive @fusion__schema_metadata("The name of the source schema." name: String!) on ENUM_VALUE

"The @fusion__type directive specifies which source schemas provide parts of a composite type."
directive @fusion__type("The name of the source schema that originally provided part of the annotated type." schema: fusion__Schema!) repeatable on SCALAR | OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT

"The @fusion__unionMember directive specifies which source schema provides a member type of a union."
directive @fusion__unionMember("The name of the member type." member: String! "The name of the source schema that provides the specified member type." schema: fusion__Schema!) repeatable on UNION
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Schema1",
"transports": {
"http": {
"url": "http://localhost/graphql"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema {
query: Query
}

type Query {
schema1Field: Int!
schema2Field: Boolean! @tag(name: "exclude-1")
schema3Field: String! @tag(name: "exclude-2")
}

directive @tag("The name of the tag." name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Schema2",
"transports": {
"http": {
"url": "http://localhost/graphql"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
schema {
query: Query
}

type Query {
schema2Field: Int!
}
Loading