Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e850ead
Adding validation to disallow multiple relationships between same sou…
ayush3797 Feb 9, 2024
4142fd9
Merge branch 'main' into dev/NestedMutations
severussundar Feb 15, 2024
adcdeab
reverting exception throwing on multiple relationships between same e…
ayush3797 Feb 16, 2024
8e35c5b
Merge branch 'main' into dev/NestedMutations
severussundar Feb 23, 2024
9e441c7
Merge branch 'main' into dev/NestedMutations
severussundar Mar 6, 2024
04fbfae
Merge branch 'main' into dev/NestedMutations
severussundar Mar 11, 2024
f7bc95d
Feature Flag for Nested Mutations: CLI changes (#1983)
severussundar Mar 12, 2024
db967d5
Merge branch 'main' into dev/NestedMutations
severussundar Mar 13, 2024
b1d5aca
Rename nested-mutations and nested-create to multiple-mutations and m…
severussundar Mar 20, 2024
12acb29
Merge branch 'main' into dev/NestedMutations
ayush3797 Mar 21, 2024
32e6fe9
Merge branch 'dev/NestedMutations' of https://github.com/Azure/data-a…
ayush3797 Mar 21, 2024
e2f9418
Multiple-create: Schema generation (#1902)
ayush3797 Mar 21, 2024
033a82b
Merge branch 'main' into dev/NestedMutations
ayush3797 Mar 21, 2024
9233c41
Multiple-create: Authorization (#1943)
ayush3797 Mar 21, 2024
9a90ca1
Enable or Disable Multiple Create operation based on feature flag val…
severussundar Mar 26, 2024
d08001c
merge latest changes from main
severussundar Mar 26, 2024
75b06c0
adds logic to throw exp when source is null; got missed during merge …
severussundar Mar 26, 2024
9a54f5d
Merge branch 'main' into dev/NestedMutations
severussundar Mar 27, 2024
d03b3e7
Merge branch 'main' into dev/NestedMutations
severussundar Mar 28, 2024
95ffc0b
Merge branch 'main' into dev/NestedMutations
severussundar Mar 29, 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
4 changes: 4 additions & 0 deletions config-generators/mssql-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add stocks_price --config "dab-config.MsSql.json" --source stocks_price --permis
update stocks_price --config "dab-config.MsSql.json" --permissions "anonymous:read"
update stocks_price --config "dab-config.MsSql.json" --permissions "TestNestedFilterFieldIsNull_ColumnForbidden:read" --fields.exclude "price"
update stocks_price --config "dab-config.MsSql.json" --permissions "TestNestedFilterFieldIsNull_EntityReadForbidden:create"
update stocks_price --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields_on_create:create,read,update,delete"
add Tree --config "dab-config.MsSql.json" --source trees --permissions "anonymous:create,read,update,delete"
add Shrub --config "dab-config.MsSql.json" --source trees --permissions "anonymous:create,read,update,delete" --rest plants
add Fungus --config "dab-config.MsSql.json" --source fungi --permissions "anonymous:create,read,update,delete" --graphql "fungus:fungi"
Expand Down Expand Up @@ -65,6 +66,8 @@ update Publisher --config "dab-config.MsSql.json" --permissions "database_policy
update Publisher --config "dab-config.MsSql.json" --permissions "database_policy_tester:update" --policy-database "@item.id ne 1234"
update Publisher --config "dab-config.MsSql.json" --permissions "database_policy_tester:create" --policy-database "@item.name ne 'New publisher'"
update Stock --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete"
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields_on_create:read,update,delete"
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields_on_create:create" --fields.exclude "piecesAvailable"
update Stock --config "dab-config.MsSql.json" --rest commodities --graphql true --relationship stocks_price --target.entity stocks_price --cardinality one
update Book --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete"
update Book --config "dab-config.MsSql.json" --relationship publishers --target.entity Publisher --cardinality one
Expand Down Expand Up @@ -112,6 +115,7 @@ update WebsiteUser --config "dab-config.MsSql.json" --permissions "authenticated
update Revenue --config "dab-config.MsSql.json" --permissions "database_policy_tester:create" --policy-database "@item.revenue gt 1000"
update Comic --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship myseries --target.entity series --cardinality one
update series --config "dab-config.MsSql.json" --relationship comics --target.entity Comic --cardinality many
update stocks_price --config "dab-config.MsSql.json" --relationship Stock --target.entity Stock --cardinality one
update Broker --config "dab-config.MsSql.json" --permissions "authenticated:create,update,read,delete" --graphql false
update Tree --config "dab-config.MsSql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Shrub --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
Expand Down
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."
},
"multiple-mutations": {
"type": "object",
"description": "Configuration properties for multiple mutation operations",
"additionalProperties": false,
"properties": {
"create":{
"type": "object",
"description": "Options for multiple create operations",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "Allow enabling/disabling multiple 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.multiple-create.enabled option of the init command for all database types.
///
/// 1. Behavior for database types other than MsSQL:
/// - Irrespective of whether the --graphql.multiple-create.enabled option is used or not, fields related to multiple-create will NOT be written to the config file.
/// - As a result, after deserialization of such a config file, the Runtime.GraphQL.MultipleMutationOptions is expected to be null.
/// 2. Behavior for MsSQL database type:
///
/// a. When --graphql.multiple-create.enabled option is used
/// - In this case, the fields related to multiple mutation and multiple create operations will be written to the config file.
/// "multiple-mutations": {
/// "create": {
/// "enabled": true/false
/// }
/// }
/// After deserializing such a config file, the Runtime.GraphQL.MultipleMutationOptions 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.multiple-create.enabled option is not used
/// - In this case, fields related to multiple mutation and multiple create operations will NOT be written to the config file.
/// - As a result, after deserialization of such a config file, the Runtime.GraphQL.MultipleMutationOptions is expected to be null.
///
/// </summary>
/// <param name="isMultipleCreateEnabled">Value interpreted by the CLI for '--graphql.multiple-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="expectedValueForMultipleCreateEnabledFlag"> Expected value for the multiple create enabled flag in the config file.</param>
[DataTestMethod]
[DataRow(CliBool.True, "mssql", DatabaseType.MSSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for MsSql database type")]
[DataRow(CliBool.False, "mssql", DatabaseType.MSSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for MsSql database type")]
[DataRow(CliBool.None, "mssql", DatabaseType.MSSQL, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for MsSql database type")]
[DataRow(CliBool.True, "mysql", DatabaseType.MySQL, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for MySql database type")]
[DataRow(CliBool.False, "mysql", DatabaseType.MySQL, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for MySql database type")]
[DataRow(CliBool.None, "mysql", DatabaseType.MySQL, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for MySql database type")]
[DataRow(CliBool.True, "postgresql", DatabaseType.PostgreSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for PostgreSql database type")]
[DataRow(CliBool.False, "postgresql", DatabaseType.PostgreSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for PostgreSql database type")]
[DataRow(CliBool.None, "postgresql", DatabaseType.PostgreSQL, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for PostgreSql database type")]
[DataRow(CliBool.True, "dwsql", DatabaseType.DWSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for dwsql database type")]
[DataRow(CliBool.False, "dwsql", DatabaseType.DWSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for dwsql database type")]
[DataRow(CliBool.None, "dwsql", DatabaseType.DWSQL, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for dwsql database type")]
[DataRow(CliBool.True, "cosmosdb_nosql", DatabaseType.CosmosDB_NoSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for cosmosdb_nosql database type")]
[DataRow(CliBool.False, "cosmosdb_nosql", DatabaseType.CosmosDB_NoSQL, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for cosmosdb_nosql database type")]
[DataRow(CliBool.None, "cosmosdb_nosql", DatabaseType.CosmosDB_NoSQL, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for cosmosdb_nosql database type")]
public void TestEnablingMultipleCreateOperation(CliBool isMultipleCreateEnabled, 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 (isMultipleCreateEnabled is not CliBool.None)
{
args.Add("--graphql.multiple-create.enabled");
args.Add(isMultipleCreateEnabled.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 && isMultipleCreateEnabled is not CliBool.None)
{
Assert.IsNotNull(runtimeConfig.Runtime.GraphQL.MultipleMutationOptions);
Assert.IsNotNull(runtimeConfig.Runtime.GraphQL.MultipleMutationOptions.MultipleCreateOptions);
bool expectedValueForMultipleCreateEnabled = isMultipleCreateEnabled == CliBool.True;
Assert.AreEqual(expectedValueForMultipleCreateEnabled, runtimeConfig.Runtime.GraphQL.MultipleMutationOptions.MultipleCreateOptions.Enabled);
}
else
{
Assert.IsNull(runtimeConfig.Runtime.GraphQL.MultipleMutationOptions, message: "MultipleMutationOptions is expected to be null because a) DB type is not MsSQL or b) Either --graphql.multiple-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.multiple-create.enabled flag option for different database types.
///
/// 1. For database types other than MsSQL:
/// - Irrespective of whether the --graphql.multiple-create.enabled option is used or not, fields related to multiple-create will NOT be written to the config file.
///
/// 2. For MsSQL database type:
/// a. When --graphql.multiple-create.enabled option is used
/// - In this case, the fields related to multiple mutation and multiple create operations will be written to the config file.
/// "multiple-mutations": {
/// "create": {
/// "enabled": true/false
/// }
/// }
///
/// b. When --graphql.multiple-create.enabled option is not used
/// - In this case, fields related to multiple mutation and multiple create operations will NOT be written to the config file.
///
/// </summary>
[DataTestMethod]
[DataRow(DatabaseType.MSSQL, CliBool.True, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for MsSQL database type")]
[DataRow(DatabaseType.MSSQL, CliBool.False, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for MsSQL database type")]
[DataRow(DatabaseType.MSSQL, CliBool.None, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for MsSQL database type")]
[DataRow(DatabaseType.PostgreSQL, CliBool.True, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for PostgreSQL database type")]
[DataRow(DatabaseType.PostgreSQL, CliBool.False, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for PostgreSQL database type")]
[DataRow(DatabaseType.PostgreSQL, CliBool.None, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for PostgreSQL database type")]
[DataRow(DatabaseType.MySQL, CliBool.True, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for MySQL database type")]
[DataRow(DatabaseType.MySQL, CliBool.False, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for MySQL database type")]
[DataRow(DatabaseType.MySQL, CliBool.None, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for MySQL database type")]
[DataRow(DatabaseType.CosmosDB_NoSQL, CliBool.True, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for CosmosDB_NoSQL database type")]
[DataRow(DatabaseType.CosmosDB_NoSQL, CliBool.False, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for CosmosDB_NoSQL database type")]
[DataRow(DatabaseType.CosmosDB_NoSQL, CliBool.None, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for CosmosDB_NoSQL database type")]
[DataRow(DatabaseType.CosmosDB_PostgreSQL, CliBool.True, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for CosmosDB_PostgreSQL database type")]
[DataRow(DatabaseType.CosmosDB_PostgreSQL, CliBool.False, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for CosmosDB_PostgreSQL database type")]
[DataRow(DatabaseType.CosmosDB_PostgreSQL, CliBool.None, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for CosmosDB_PostgreSQL database type")]
[DataRow(DatabaseType.DWSQL, CliBool.True, DisplayName = "Init command with '--graphql.multiple-create.enabled true' for DWSQL database type")]
[DataRow(DatabaseType.DWSQL, CliBool.False, DisplayName = "Init command with '--graphql.multiple-create.enabled false' for DWSQL database type")]
[DataRow(DatabaseType.DWSQL, CliBool.None, DisplayName = "Init command without '--graphql.multiple-create.enabled' option for DWSQL database type")]
public Task VerifyCorrectConfigGenerationWithMultipleMutationOptions(DatabaseType databaseType, CliBool isMultipleCreateEnabled)
{
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,
multipleCreateOperationEnabled: isMultipleCreateEnabled);
}
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,
multipleCreateOperationEnabled: isMultipleCreateEnabled);
}

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

private Task ExecuteVerifyTest(InitOptions options, VerifySettings? settings = null)
{
Assert.IsTrue(TryCreateRuntimeConfig(options, _runtimeConfigLoader!, _fileSystem!, out RuntimeConfig? runtimeConfig));
Expand Down
2 changes: 2 additions & 0 deletions src/Cli.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static void Init()
VerifierSettings.IgnoreMember<RuntimeOptions>(options => options.IsCachingEnabled);
// Ignore the entity IsCachingEnabled as that's unimportant from a test standpoint.
VerifierSettings.IgnoreMember<Entity>(entity => entity.IsCachingEnabled);
// Ignore the entity IsLinkingEntity as that's unimportant from a test standpoint.
VerifierSettings.IgnoreMember<Entity>(entity => entity.IsLinkingEntity);
// Ignore the UserProvidedTtlOptions. They aren't serialized to our config file, enforced by EntityCacheOptionsConverter.
VerifierSettings.IgnoreMember<EntityCacheOptions>(cacheOptions => cacheOptions.UserProvidedTtlOptions);
// Ignore the IsRequestBodyStrict as that's unimportant from a test standpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
DataSource: {
DatabaseType: DWSQL,
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: []
}
Loading