Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
ce0a6f7
Basic progress
ayush3797 Nov 28, 2023
7c47ef5
adding createMultiple mutations
ayush3797 Nov 28, 2023
6677337
nits
ayush3797 Nov 28, 2023
5f3d45a
Collecting metadata about linking entities/adding flag to represent w…
ayush3797 Nov 30, 2023
03113c7
Generating object defs for directional linking entities
ayush3797 Dec 1, 2023
5256c01
clearing up logic
ayush3797 Dec 1, 2023
8793876
Adding prefix to linking fields
ayush3797 Dec 1, 2023
bc27394
Generating array input for *:N relationship
ayush3797 Dec 3, 2023
b047c9d
making nested entity optional
ayush3797 Dec 6, 2023
c5e6b06
updating mutation name
ayush3797 Dec 15, 2023
715125c
Handling conflicting column/relationship names with linking table
ayush3797 Dec 20, 2023
e6efb65
Adding method to get plural name
ayush3797 Dec 20, 2023
6af96e3
Updating logic/renaming variables
ayush3797 Jan 2, 2024
7a90f0b
shortening loop
ayush3797 Jan 3, 2024
4b91cc2
Solving bug for M:N relationship schema gen
ayush3797 Jan 13, 2024
191e257
nits
ayush3797 Jan 13, 2024
5f002ec
update branch
ayush3797 Jan 13, 2024
887dd79
format fix
ayush3797 Jan 14, 2024
82b0c7f
Fixing failures due to tests
ayush3797 Jan 15, 2024
33fca99
fixing format
ayush3797 Jan 15, 2024
2073c48
Moving linking entity logic to sqlmetadataprovider
ayush3797 Jan 15, 2024
2c96a8b
fixing typo
ayush3797 Jan 15, 2024
fe05132
Moving linking entity logic to sqlmdpvdr
ayush3797 Jan 16, 2024
11bb3d4
fixing format
ayush3797 Jan 16, 2024
d6f6949
fixing failures
ayush3797 Jan 16, 2024
1c0ce60
Preventing serialisation/deserialization of islinkingentity property
ayush3797 Jan 17, 2024
cba8072
Fixing dwsql
ayush3797 Jan 17, 2024
162f2de
god please fix this formatting error
ayush3797 Jan 17, 2024
e9d8b8e
fixing tests
ayush3797 Jan 17, 2024
c58f3ea
Refining logic to create linking objects
ayush3797 Jan 17, 2024
613f386
refining code
ayush3797 Jan 17, 2024
6757208
refactor schema converter for clear code
ayush3797 Jan 17, 2024
9e4b732
adding/removing comments
ayush3797 Jan 17, 2024
ff3e952
Merge with main
ayush3797 Jan 29, 2024
7a503d6
Addressing review
ayush3797 Feb 1, 2024
27a45c1
addressing review
ayush3797 Feb 1, 2024
baa0bb8
adding param name
ayush3797 Feb 2, 2024
f5237fe
Logic to find names of src/target entities from linking entity name
ayush3797 Feb 2, 2024
e963d40
update comment
ayush3797 Feb 2, 2024
af60e25
updating branch
ayush3797 Feb 6, 2024
09055ab
fixing bug
ayush3797 Feb 6, 2024
3b824d6
adding summary/reusing existing methods
ayush3797 Feb 12, 2024
29c2a1a
Initial progress
ayush3797 Feb 14, 2024
422630d
initial prgress
ayush3797 Feb 14, 2024
47def99
saving progress for fk directive
ayush3797 Feb 14, 2024
783464c
Logic to add FK directive for custom relationships
ayush3797 Feb 15, 2024
9cb61d6
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
d68d311
separating naming logic for mutations
ayush3797 Feb 15, 2024
68b780c
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
be7831f
making rel fields nullable
ayush3797 Feb 15, 2024
daeae37
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
a5f3654
adding tests
ayush3797 Feb 15, 2024
b63aed6
nit
ayush3797 Feb 15, 2024
8583106
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
5089f90
Adding test summaries
ayush3797 Feb 15, 2024
97e6878
refactoring test
ayush3797 Feb 15, 2024
d345a5f
updating comment
ayush3797 Feb 15, 2024
f4743de
updating branch
ayush3797 Feb 15, 2024
4c7cb74
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
ce0c49f
Merge branch 'dev/NestedMutations' into dev/agarwalayush/schemaGenera…
ayush3797 Feb 15, 2024
ce8cc98
Adding test
ayush3797 Feb 15, 2024
7820551
Merge branch 'dev/agarwalayush/schemaGenerationTests' into dev/agarwa…
ayush3797 Feb 20, 2024
6b2f055
reverting conn string change
ayush3797 Feb 20, 2024
a9bb393
addressing review
ayush3797 Feb 22, 2024
be28782
addressing review
ayush3797 Feb 22, 2024
60ae0af
adding comment
ayush3797 Feb 22, 2024
55912f4
adding comment
ayush3797 Feb 22, 2024
effc380
addressing comments
ayush3797 Feb 27, 2024
adfcab9
updating mton function logic
ayush3797 Feb 27, 2024
9e377c3
refining logic
ayush3797 Feb 27, 2024
8db211c
addressing review
ayush3797 Feb 28, 2024
5ca4171
addressing review
ayush3797 Feb 28, 2024
a6ae8aa
Adding test asserting absence of ref field directive on non-ref columns
ayush3797 Feb 28, 2024
02c79bc
renaming set
ayush3797 Feb 29, 2024
7624675
formatting fix
ayush3797 Feb 29, 2024
559025f
formatting fix
ayush3797 Feb 29, 2024
78c8f7b
Merge branch 'dev/NestedMutations' into dev/agarwalayush/schemaGenera…
ayush3797 Feb 29, 2024
96c4a36
formatting fix
ayush3797 Feb 29, 2024
0c4fc3d
Refactoring cosmos create input generation into a different methof
ayush3797 Feb 29, 2024
fa9bcab
fixing test setup
ayush3797 Feb 29, 2024
f008c24
addressing review/adding comments
ayush3797 Mar 5, 2024
fac35d3
adding example
ayush3797 Mar 5, 2024
52670f0
rename nested-mutations/create to multiple-mutations/create
severussundar Mar 13, 2024
55a62bb
renames field in reference config file
severussundar Mar 13, 2024
b34c9f1
Addressing review
ayush3797 Mar 13, 2024
cb7d185
removing stale logic code
ayush3797 Mar 13, 2024
46caf38
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/shyamsundar…
severussundar Mar 18, 2024
7033c8e
generate multiple create ops if feature flag is enabled
severussundar Mar 19, 2024
da5c8e9
fix existing unit tests
severussundar Mar 19, 2024
73140bc
removing console log stmts
severussundar Mar 19, 2024
f2b1136
updates mutation builder tests to consider feature flag value
severussundar Mar 20, 2024
4250265
fixing unit tests, adding integration tests
severussundar Mar 20, 2024
7409c32
fixes multiple mutation builder tests, adds validation for many type …
severussundar Mar 20, 2024
c7aaf2b
add debug stmt
severussundar Mar 20, 2024
e60c64a
add cleanup step
severussundar Mar 20, 2024
6f36808
try mocking runtimeconfigprovider
severussundar Mar 21, 2024
ba610e4
merge latest changes
severussundar Mar 21, 2024
a03534c
enables multiple create feature
severussundar Mar 21, 2024
3427d93
adds a sanity create mutation tests, updates test descriptions
severussundar Mar 21, 2024
ffcb177
running all integration tests with create multiple ops disabled
severussundar Mar 21, 2024
814bc34
updates using stmts
severussundar Mar 21, 2024
e4653ed
addressing review comments
severussundar Mar 21, 2024
1148ecb
some cosmetic changes
severussundar Mar 22, 2024
f58efe8
Merge branch 'dev/NestedMutations' into dev/shyamsundarj/honor-multip…
severussundar Mar 22, 2024
584f1f3
addressing review comments
severussundar Mar 23, 2024
d421a7a
reduces code duplication by adding a helper method for multiple creat…
severussundar Mar 23, 2024
81f5aa0
renames function, variable names, adds new enum for db supporting mul…
severussundar Mar 25, 2024
4a9fd1e
fixing condition
severussundar Mar 25, 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
10 changes: 10 additions & 0 deletions src/Config/ObjectModel/MultipleCreateSupportingDatabaseType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Azure.DataApiBuilder.Config.ObjectModel
{
public enum MultipleCreateSupportingDatabaseType
{
MSSQL
}
}
18 changes: 18 additions & 0 deletions src/Config/ObjectModel/RuntimeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,22 @@ public static bool IsHotReloadable()
// always return false while hot reload is not an available feature.
return false;
}

/// <summary>
/// Helper method to check if multiple create option is supported and enabled.
///
/// Returns true when
/// 1. Multiple create operation is supported by the database type and
/// 2. Multiple create operation is enabled in the runtime config.
///
/// </summary>
public bool IsMultipleCreateOperationEnabled()
{
return Enum.GetNames(typeof(MultipleCreateSupportingDatabaseType)).Any(x => x.Equals(DataSource.DatabaseType.ToString(), StringComparison.OrdinalIgnoreCase)) &&
(Runtime is not null &&
Runtime.GraphQL is not null &&
Runtime.GraphQL.MultipleMutationOptions is not null &&
Runtime.GraphQL.MultipleMutationOptions.MultipleCreateOptions is not null &&
Runtime.GraphQL.MultipleMutationOptions.MultipleCreateOptions.Enabled);
}
}
25 changes: 18 additions & 7 deletions src/Core/Services/GraphQLSchemaCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class GraphQLSchemaCreator
private readonly RuntimeEntities _entities;
private readonly IAuthorizationResolver _authorizationResolver;
private readonly RuntimeConfigProvider _runtimeConfigProvider;
private bool _isMultipleCreateOperationEnabled;

/// <summary>
/// Initializes a new instance of the <see cref="GraphQLSchemaCreator"/> class.
Expand All @@ -60,6 +61,7 @@ public GraphQLSchemaCreator(
{
RuntimeConfig runtimeConfig = runtimeConfigProvider.GetConfig();

_isMultipleCreateOperationEnabled = runtimeConfig.IsMultipleCreateOperationEnabled();
_entities = runtimeConfig.Entities;
_queryEngineFactory = queryEngineFactory;
_mutationEngineFactory = mutationEngineFactory;
Expand Down Expand Up @@ -137,7 +139,7 @@ private ISchemaBuilder Parse(
DocumentNode queryNode = QueryBuilder.Build(root, entityToDatabaseType, _entities, inputTypes, _authorizationResolver.EntityPermissionsMap, entityToDbObjects);

// Generate the GraphQL mutations from the provided objects
DocumentNode mutationNode = MutationBuilder.Build(root, entityToDatabaseType, _entities, _authorizationResolver.EntityPermissionsMap, entityToDbObjects);
DocumentNode mutationNode = MutationBuilder.Build(root, entityToDatabaseType, _entities, _authorizationResolver.EntityPermissionsMap, entityToDbObjects, _isMultipleCreateOperationEnabled);

return (queryNode, mutationNode);
}
Expand Down Expand Up @@ -215,8 +217,7 @@ private DocumentNode GenerateSqlGraphQLObjects(RuntimeEntities entities, Diction
configEntity: entity,
entities: entities,
rolesAllowedForEntity: rolesAllowedForEntity,
rolesAllowedForFields: rolesAllowedForFields
);
rolesAllowedForFields: rolesAllowedForFields);

if (databaseObject.SourceType is not EntitySourceType.StoredProcedure)
{
Expand All @@ -234,8 +235,13 @@ private DocumentNode GenerateSqlGraphQLObjects(RuntimeEntities entities, Diction
}
}

// For all the fields in the object which hold a foreign key reference to any referenced entity, add a foreign key directive.
AddReferencingFieldDirective(entities, objectTypes);
// ReferencingFieldDirective is added to eventually mark the referencing fields in the input object types as optional. When multiple create operations are disabled
// the referencing fields should be required fields. Hence, ReferencingFieldDirective is added only when the multiple create operations are enabled.
if (_isMultipleCreateOperationEnabled)
{
// For all the fields in the object which hold a foreign key reference to any referenced entity, add a foreign key directive.
AddReferencingFieldDirective(entities, objectTypes);
}

// Pass two - Add the arguments to the many-to-* relationship fields
foreach ((string entityName, ObjectTypeDefinitionNode node) in objectTypes)
Expand All @@ -245,8 +251,13 @@ private DocumentNode GenerateSqlGraphQLObjects(RuntimeEntities entities, Diction

// Create ObjectTypeDefinitionNode for linking entities. These object definitions are not exposed in the schema
// but are used to generate the object definitions of directional linking entities for (source, target) and (target, source) entities.
Dictionary<string, ObjectTypeDefinitionNode> linkingObjectTypes = GenerateObjectDefinitionsForLinkingEntities();
GenerateSourceTargetLinkingObjectDefinitions(objectTypes, linkingObjectTypes);
// However, ObjectTypeDefinitionNode for linking entities are need only for multiple create operation. So, creating these only when multiple create operations are
// enabled.
if (_isMultipleCreateOperationEnabled)
{
Dictionary<string, ObjectTypeDefinitionNode> linkingObjectTypes = GenerateObjectDefinitionsForLinkingEntities();
GenerateSourceTargetLinkingObjectDefinitions(objectTypes, linkingObjectTypes);
}

// Return a list of all the object types to be exposed in the schema.
Dictionary<string, FieldDefinitionNode> fields = new();
Expand Down
5 changes: 4 additions & 1 deletion src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace Azure.DataApiBuilder.Core.Services
public class MsSqlMetadataProvider :
SqlMetadataProvider<SqlConnection, SqlDataAdapter, SqlCommand>
{
private RuntimeConfigProvider _runtimeConfigProvider;

public MsSqlMetadataProvider(
RuntimeConfigProvider runtimeConfigProvider,
IAbstractQueryManagerFactory queryManagerFactory,
Expand All @@ -37,6 +39,7 @@ public MsSqlMetadataProvider(
bool isValidateOnly = false)
: base(runtimeConfigProvider, queryManagerFactory, logger, dataSourceName, isValidateOnly)
{
_runtimeConfigProvider = runtimeConfigProvider;
}

public override string GetDefaultSchemaName()
Expand Down Expand Up @@ -219,7 +222,7 @@ protected override void PopulateMetadataForLinkingObject(
string linkingObject,
Dictionary<string, DatabaseObject> sourceObjects)
{
if (!GraphQLUtils.DoesRelationalDBSupportMultipleCreate(GetDatabaseType()))
if (!_runtimeConfigProvider.GetConfig().IsMultipleCreateOperationEnabled())
{
// Currently we have this same class instantiated for both MsSql and DwSql.
// This is a refactor we need to take care of in future.
Expand Down
24 changes: 15 additions & 9 deletions src/Core/Services/MetadataProviders/SqlMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,16 +755,22 @@ private void ProcessRelationships(
referencedColumns: relationship.TargetFields,
relationshipData);

// When a linking object is encountered for a database table, we will create a linking entity for the object.
// Subsequently, we will also populate the Database object for the linking entity. This is used to infer
// metadata about linking object needed to create GQL schema for multiple insertions.
if (entity.Source.Type is EntitySourceType.Table)
RuntimeConfig runtimeConfig = _runtimeConfigProvider.GetConfig();

// Populating metadata for linking object is only required when multiple create operation is enabled and those database types that support multiple create operation.
if (runtimeConfig.IsMultipleCreateOperationEnabled())
{
PopulateMetadataForLinkingObject(
entityName: entityName,
targetEntityName: targetEntityName,
linkingObject: relationship.LinkingObject,
sourceObjects: sourceObjects);
// When a linking object is encountered for a database table, we will create a linking entity for the object.
// Subsequently, we will also populate the Database object for the linking entity. This is used to infer
// metadata about linking object needed to create GQL schema for multiple insertions.
if (entity.Source.Type is EntitySourceType.Table)
{
PopulateMetadataForLinkingObject(
entityName: entityName,
targetEntityName: targetEntityName,
linkingObject: relationship.LinkingObject,
sourceObjects: sourceObjects);
}
}
}
else if (relationship.Cardinality == Cardinality.One)
Expand Down
10 changes: 0 additions & 10 deletions src/Service.GraphQLBuilder/GraphQLUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public static class GraphQLUtils
// Delimiter used to separate linking entity prefix/source entity name/target entity name, in the name of a linking entity.
private const string ENTITY_NAME_DELIMITER = "$";

public static HashSet<DatabaseType> RELATIONAL_DBS_SUPPORTING_MULTIPLE_CREATE = new() { DatabaseType.MSSQL };

public static HashSet<DatabaseType> RELATIONAL_DBS = new() { DatabaseType.MSSQL, DatabaseType.MySQL,
DatabaseType.DWSQL, DatabaseType.PostgreSQL, DatabaseType.CosmosDB_PostgreSQL };

Expand Down Expand Up @@ -72,14 +70,6 @@ public static bool IsBuiltInType(ITypeNode typeNode)
return builtInTypes.Contains(name);
}

/// <summary>
/// Helper method to evaluate whether DAB supports multiple create for a particular database type.
/// </summary>
public static bool DoesRelationalDBSupportMultipleCreate(DatabaseType databaseType)
{
return RELATIONAL_DBS_SUPPORTING_MULTIPLE_CREATE.Contains(databaseType);
}

/// <summary>
/// Helper method to evaluate whether database type represents a NoSQL database.
/// </summary>
Expand Down
Loading