Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9d8bccf
adds feature flag for nested mutations
severussundar Jan 18, 2024
76d7a0b
updates schema file, adds tests
severussundar Jan 21, 2024
5a09b89
updates ref config files, adds method and class descriptions
severussundar Jan 21, 2024
c54e454
updates parsing logic to handle env vars, fixes tests
severussundar Jan 24, 2024
e4413bc
updates insert => create
severussundar Jan 31, 2024
49b5ab0
fixes tests after rename to create
severussundar Jan 31, 2024
9b803c6
renames the option to use create instead of insert
severussundar Jan 31, 2024
f361623
updates sample config files
severussundar Jan 31, 2024
a241277
addressing review comments
severussundar Jan 31, 2024
cf35d11
fixing tests
severussundar Jan 31, 2024
3a64a47
Merge branch 'main' into dev/shyamsundarj/adds-feature-flag-cli-option
severussundar Jan 31, 2024
156ecb5
adds a sanity test to ensure old config works
severussundar Feb 1, 2024
122241c
updates graphqlql runtime initialization logic
severussundar Feb 1, 2024
a78426c
adds test summary, test category
severussundar Feb 1, 2024
7eb21a1
adds logic to not write out nested mutation open when null
severussundar Feb 6, 2024
c4898cc
updates tests
severussundar Feb 6, 2024
82b1cce
incorporating review feedback
severussundar Feb 6, 2024
23295bf
adds deserialization tests for invalid values in nested mutation section
severussundar Feb 7, 2024
2e85aee
updates reference config files with true
severussundar Feb 7, 2024
539e6c7
updates test description
severussundar Feb 7, 2024
b4ce4b0
fixing snapshot files
severussundar Feb 7, 2024
b480c27
adds additionalProperties to draft schema file
severussundar Feb 7, 2024
ffcc893
simplifies logic in a helper function
severussundar Feb 8, 2024
6a7b029
updates test descriptions
severussundar Feb 8, 2024
ef7c3ef
Merge branch 'dev/NestedMutations' into dev/shyamsundarj/adds-feature…
severussundar Feb 23, 2024
02aa7b6
updating snapshot files as per latest
severussundar Feb 23, 2024
03af546
incorporating review comments
severussundar Mar 1, 2024
dd034f8
fixing typo in variable name
severussundar Mar 5, 2024
8968bef
removing fields from non-mssql db ref config files
severussundar Mar 6, 2024
8545c01
incorporates review comments
severussundar Mar 11, 2024
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
19 changes: 19 additions & 0 deletions schemas/dab.draft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@
"enabled": {
"type": "boolean",
"description": "Allow enabling/disabling GraphQL requests for all entities."
},
"nested-mutations": {
"type": "object",
"description": "Configuration properties for nested mutation operations",
"additionalProperties": false,
"properties": {
"create":{
"type": "object",
"description": "Options for nested create operations",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "Allow enabling/disabling nested create operations for all entities.",
"default": false
}
}
}
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/Cli.Tests/ConfigGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void TestSpecialCharactersInConnectionString()
""enabled"": true,
""path"": ""/An_"",
""allow-introspection"": true
},
},
""host"": {
""cors"": {
""origins"": [],
Expand Down
84 changes: 84 additions & 0 deletions src/Cli.Tests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,90 @@ public void TestInitializingRestAndGraphQLGlobalSettings()
Assert.IsTrue(runtimeConfig.Runtime.GraphQL?.Enabled);
}

/// <summary>
/// Test to validate the usage of --graphql.nested-create.enabled option of the init command for all database types.
///
/// 1. Behavior for database types other than MsSQL:
/// - Irrespective of whether the --graphql.nested-create.enabled option is used or not, fields related to nested-create will NOT be written to the config file.
/// - As a result, after deserialization of such a config file, the Runtime.GraphQL.NestedMutationOptions is expected to be null.
/// 2. Behavior for MsSQL database type:
///
/// a. When --graphql.nested-create.enabled option is used
/// - In this case, the fields related to nested mutation and nested create operations will be written to the config file.
/// "nested-mutations": {
/// "create": {
/// "enabled": true/false
/// }
/// }
/// After deserializing such a config file, the Runtime.GraphQL.NestedMutationOptions is expected to be non-null and the value of the "enabled" field is expected to be the same as the value passed in the init command.
///
/// b. When --graphql.nested-create.enabled option is not used
/// - In this case, fields related to nested mutation and nested create operations will NOT be written to the config file.
/// - As a result, after deserialization of such a config file, the Runtime.GraphQL.NestedMutationOptions is expected to be null.
///
/// </summary>
/// <param name="isNestedCreateEnabled">Value interpreted by the CLI for '--graphql.nested-create.enabled' option of the init command.
/// When not used, CLI interprets the value for the option as CliBool.None
/// When used with true/false, CLI interprets the value as CliBool.True/CliBool.False respectively.
/// </param>
/// <param name="expectedValueForNestedCreateEnabledFlag"> Expected value for the nested create enabled flag in the config file.</param>
[DataTestMethod]
[DataRow(CliBool.True, "mssql", DatabaseType.MSSQL, DisplayName = "Init command with '--graphql.nested-create.enabled true' for MsSql database type")]
[DataRow(CliBool.False, "mssql", DatabaseType.MSSQL, DisplayName = "Init command with '--graphql.nested-create.enabled false' for MsSql database type")]
[DataRow(CliBool.None, "mssql", DatabaseType.MSSQL, DisplayName = "Init command without '--graphql.nested-create.enabled' option for MsSql database type")]
[DataRow(CliBool.True, "mysql", DatabaseType.MySQL, DisplayName = "Init command with '--graphql.nested-create.enabled true' for MySql database type")]
[DataRow(CliBool.False, "mysql", DatabaseType.MySQL, DisplayName = "Init command with '--graphql.nested-create.enabled false' for MySql database type")]
[DataRow(CliBool.None, "mysql", DatabaseType.MySQL, DisplayName = "Init command without '--graphql.nested-create.enabled' option for MySql database type")]
[DataRow(CliBool.True, "postgresql", DatabaseType.PostgreSQL, DisplayName = "Init command with '--graphql.nested-create.enabled true' for PostgreSql database type")]
[DataRow(CliBool.False, "postgresql", DatabaseType.PostgreSQL, DisplayName = "Init command with '--graphql.nested-create.enabled false' for PostgreSql database type")]
[DataRow(CliBool.None, "postgresql", DatabaseType.PostgreSQL, DisplayName = "Init command without '--graphql.nested-create.enabled' option for PostgreSql database type")]
[DataRow(CliBool.True, "dwsql", DatabaseType.DWSQL, DisplayName = "Init command with '--graphql.nested-create.enabled true' for dwsql database type")]
[DataRow(CliBool.False, "dwsql", DatabaseType.DWSQL, DisplayName = "Init command with '--graphql.nested-create.enabled false' for dwsql database type")]
[DataRow(CliBool.None, "dwsql", DatabaseType.DWSQL, DisplayName = "Init command without '--graphql.nested-create.enabled' option for dwsql database type")]
[DataRow(CliBool.True, "cosmosdb_nosql", DatabaseType.CosmosDB_NoSQL, DisplayName = "Init command with '--graphql.nested-create.enabled true' for cosmosdb_nosql database type")]
[DataRow(CliBool.False, "cosmosdb_nosql", DatabaseType.CosmosDB_NoSQL, DisplayName = "Init command with '--graphql.nested-create.enabled false' for cosmosdb_nosql database type")]
[DataRow(CliBool.None, "cosmosdb_nosql", DatabaseType.CosmosDB_NoSQL, DisplayName = "Init command without '--graphql.nested-create.enabled' option for cosmosdb_nosql database type")]
public void TestEnablingNestedCreateOperation(CliBool isNestedCreateEnabled, string dbType, DatabaseType expectedDbType)
{
List<string> args = new() { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--connection-string", SAMPLE_TEST_CONN_STRING, "--database-type", dbType };

if (string.Equals("cosmosdb_nosql", dbType, StringComparison.OrdinalIgnoreCase))
{
List<string> cosmosNoSqlArgs = new() { "--cosmosdb_nosql-database",
"graphqldb", "--cosmosdb_nosql-container", "planet", "--graphql-schema", TEST_SCHEMA_FILE};
args.AddRange(cosmosNoSqlArgs);
}

if (isNestedCreateEnabled is not CliBool.None)
{
args.Add("--graphql.nested-create.enabled");
args.Add(isNestedCreateEnabled.ToString()!);
}

Program.Execute(args.ToArray(), _cliLogger!, _fileSystem!, _runtimeConfigLoader!);

Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig(
TEST_RUNTIME_CONFIG_FILE,
out RuntimeConfig? runtimeConfig,
replaceEnvVar: true));

Assert.IsNotNull(runtimeConfig);
Assert.AreEqual(expectedDbType, runtimeConfig.DataSource.DatabaseType);
Assert.IsNotNull(runtimeConfig.Runtime);
Assert.IsNotNull(runtimeConfig.Runtime.GraphQL);
if (runtimeConfig.DataSource.DatabaseType is DatabaseType.MSSQL && isNestedCreateEnabled is not CliBool.None)
{
Assert.IsNotNull(runtimeConfig.Runtime.GraphQL.NestedMutationOptions);
Assert.IsNotNull(runtimeConfig.Runtime.GraphQL.NestedMutationOptions.NestedCreateOptions);
bool expectedValueForNestedCreateEnabled = isNestedCreateEnabled == CliBool.True;
Assert.AreEqual(expectedValueForNestedCreateEnabled, runtimeConfig.Runtime.GraphQL.NestedMutationOptions.NestedCreateOptions.Enabled);
}
else
{
Assert.IsNull(runtimeConfig.Runtime.GraphQL.NestedMutationOptions, message: "NestedMutationOptions is expected to be null because a) DB type is not MsSQL or b) Either --graphql.nested-create.enabled option was not used or no value was provided.");
}
}

/// <summary>
/// Test to verify adding a new Entity.
/// </summary>
Expand Down
83 changes: 83 additions & 0 deletions src/Cli.Tests/InitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,89 @@ public Task GraphQLPathWithoutStartingSlashWillHaveItAdded()
return ExecuteVerifyTest(options);
}

/// <summary>
/// Test to validate the contents of the config file generated when init command is used with --graphql.nested-create.enabled flag option for different database types.
///
/// 1. For database types other than MsSQL:
/// - Irrespective of whether the --graphql.nested-create.enabled option is used or not, fields related to nested-create will NOT be written to the config file.
///
/// 2. For MsSQL database type:
/// a. When --graphql.nested-create.enabled option is used
/// - In this case, the fields related to nested mutation and nested create operations will be written to the config file.
/// "nested-mutations": {
/// "create": {
/// "enabled": true/false
/// }
/// }
///
/// b. When --graphql.nested-create.enabled option is not used
/// - In this case, fields related to nested mutation and nested create operations will NOT be written to the config file.
///
/// </summary>
[DataTestMethod]
[DataRow(DatabaseType.MSSQL, CliBool.True, DisplayName = "Init command with '--graphql.nested-create.enabled true' for MsSQL database type")]
[DataRow(DatabaseType.MSSQL, CliBool.False, DisplayName = "Init command with '--graphql.nested-create.enabled false' for MsSQL database type")]
[DataRow(DatabaseType.MSSQL, CliBool.None, DisplayName = "Init command without '--graphql.nested-create.enabled' option for MsSQL database type")]
[DataRow(DatabaseType.PostgreSQL, CliBool.True, DisplayName = "Init command with '--graphql.nested-create.enabled true' for PostgreSQL database type")]
[DataRow(DatabaseType.PostgreSQL, CliBool.False, DisplayName = "Init command with '--graphql.nested-create.enabled false' for PostgreSQL database type")]
[DataRow(DatabaseType.PostgreSQL, CliBool.None, DisplayName = "Init command without '--graphql.nested-create.enabled' option for PostgreSQL database type")]
[DataRow(DatabaseType.MySQL, CliBool.True, DisplayName = "Init command with '--graphql.nested-create.enabled true' for MySQL database type")]
[DataRow(DatabaseType.MySQL, CliBool.False, DisplayName = "Init command with '--graphql.nested-create.enabled false' for MySQL database type")]
[DataRow(DatabaseType.MySQL, CliBool.None, DisplayName = "Init command without '--graphql.nested-create.enabled' option for MySQL database type")]
[DataRow(DatabaseType.CosmosDB_NoSQL, CliBool.True, DisplayName = "Init command with '--graphql.nested-create.enabled true' for CosmosDB_NoSQL database type")]
[DataRow(DatabaseType.CosmosDB_NoSQL, CliBool.False, DisplayName = "Init command with '--graphql.nested-create.enabled false' for CosmosDB_NoSQL database type")]
[DataRow(DatabaseType.CosmosDB_NoSQL, CliBool.None, DisplayName = "Init command without '--graphql.nested-create.enabled' option for CosmosDB_NoSQL database type")]
[DataRow(DatabaseType.CosmosDB_PostgreSQL, CliBool.True, DisplayName = "Init command with '--graphql.nested-create.enabled true' for CosmosDB_PostgreSQL database type")]
[DataRow(DatabaseType.CosmosDB_PostgreSQL, CliBool.False, DisplayName = "Init command with '--graphql.nested-create.enabled false' for CosmosDB_PostgreSQL database type")]
[DataRow(DatabaseType.CosmosDB_PostgreSQL, CliBool.None, DisplayName = "Init command without '--graphql.nested-create.enabled' option for CosmosDB_PostgreSQL database type")]
[DataRow(DatabaseType.DWSQL, CliBool.True, DisplayName = "Init command with '--graphql.nested-create.enabled true' for DWSQL database type")]
[DataRow(DatabaseType.DWSQL, CliBool.False, DisplayName = "Init command with '--graphql.nested-create.enabled false' for DWSQL database type")]
[DataRow(DatabaseType.DWSQL, CliBool.None, DisplayName = "Init command without '--graphql.nested-create.enabled' option for DWSQL database type")]
public Task VerifyCorrectConfigGenerationWithNestedMutationOptions(DatabaseType databaseType, CliBool isNestedCreateEnabled)
{
InitOptions options;

if (databaseType is DatabaseType.CosmosDB_NoSQL)
{
// A schema file is added since its mandatory for CosmosDB_NoSQL
((MockFileSystem)_fileSystem!).AddFile(TEST_SCHEMA_FILE, new MockFileData(""));

options = new(
databaseType: databaseType,
connectionString: "testconnectionstring",
cosmosNoSqlDatabase: "testdb",
cosmosNoSqlContainer: "testcontainer",
graphQLSchemaPath: TEST_SCHEMA_FILE,
setSessionContext: true,
hostMode: HostMode.Development,
corsOrigin: new List<string>() { "http://localhost:3000", "http://nolocalhost:80" },
authenticationProvider: EasyAuthType.StaticWebApps.ToString(),
restPath: "rest-api",
config: TEST_RUNTIME_CONFIG_FILE,
nestedCreateOperationEnabled: isNestedCreateEnabled);
}
else
{
options = new(
databaseType: databaseType,
connectionString: "testconnectionstring",
cosmosNoSqlDatabase: null,
cosmosNoSqlContainer: null,
graphQLSchemaPath: null,
setSessionContext: true,
hostMode: HostMode.Development,
corsOrigin: new List<string>() { "http://localhost:3000", "http://nolocalhost:80" },
authenticationProvider: EasyAuthType.StaticWebApps.ToString(),
restPath: "rest-api",
config: TEST_RUNTIME_CONFIG_FILE,
nestedCreateOperationEnabled: isNestedCreateEnabled);
}

VerifySettings verifySettings = new();
verifySettings.UseHashedParameters(databaseType, isNestedCreateEnabled);
return ExecuteVerifyTest(options, verifySettings);
}

private Task ExecuteVerifyTest(InitOptions options, VerifySettings? settings = null)
{
Assert.IsTrue(TryCreateRuntimeConfig(options, _runtimeConfigLoader!, _fileSystem!, out RuntimeConfig? runtimeConfig));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
DataSource: {
Options: {
container: testcontainer,
database: testdb,
schema: test-schema.gql
}
},
Runtime: {
Rest: {
Enabled: false,
Path: /api,
RequestBodyStrict: true
},
GraphQL: {
Enabled: true,
Path: /graphql,
AllowIntrospection: true
},
Host: {
Cors: {
Origins: [
http://localhost:3000,
http://nolocalhost:80
],
AllowCredentials: false
},
Authentication: {
Provider: StaticWebApps
}
}
},
Entities: []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
DataSource: {
DatabaseType: MSSQL,
Options: {
set-session-context: true
}
},
Runtime: {
Rest: {
Enabled: true,
Path: /rest-api,
RequestBodyStrict: true
},
GraphQL: {
Enabled: true,
Path: /graphql,
AllowIntrospection: true
},
Host: {
Cors: {
Origins: [
http://localhost:3000,
http://nolocalhost:80
],
AllowCredentials: false
},
Authentication: {
Provider: StaticWebApps
}
}
},
Entities: []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
DataSource: {
DatabaseType: MSSQL,
Options: {
set-session-context: true
}
},
Runtime: {
Rest: {
Enabled: true,
Path: /rest-api,
RequestBodyStrict: true
},
GraphQL: {
Enabled: true,
Path: /graphql,
AllowIntrospection: true,
NestedMutationOptions: {
NestedCreateOptions: {
Enabled: true
}
}
},
Host: {
Cors: {
Origins: [
http://localhost:3000,
http://nolocalhost:80
],
AllowCredentials: false
},
Authentication: {
Provider: StaticWebApps
}
}
},
Entities: []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
DataSource: {
Options: {
container: testcontainer,
database: testdb,
schema: test-schema.gql
}
},
Runtime: {
Rest: {
Enabled: false,
Path: /api,
RequestBodyStrict: true
},
GraphQL: {
Enabled: true,
Path: /graphql,
AllowIntrospection: true
},
Host: {
Cors: {
Origins: [
http://localhost:3000,
http://nolocalhost:80
],
AllowCredentials: false
},
Authentication: {
Provider: StaticWebApps
}
}
},
Entities: []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
DataSource: {
DatabaseType: MySQL
},
Runtime: {
Rest: {
Enabled: true,
Path: /rest-api,
RequestBodyStrict: true
},
GraphQL: {
Enabled: true,
Path: /graphql,
AllowIntrospection: true
},
Host: {
Cors: {
Origins: [
http://localhost:3000,
http://nolocalhost:80
],
AllowCredentials: false
},
Authentication: {
Provider: StaticWebApps
}
}
},
Entities: []
}
Loading