Skip to content

Commit 81e42c9

Browse files
authored
Fixing nit comments from previous DW mutation support prs. (#2043)
## Why make this change? Fixing nit comments from earlier pr: #1978 ## What is this change? There were some nit comments to fix while adding implementation for mutation support for DW. ## How was this tested? Existing tests should cover as this pr only handles nit fixes.
1 parent 165ba8a commit 81e42c9

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

src/Core/Services/GraphQLSchemaCreator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,12 @@ private DocumentNode GenerateSqlGraphQLObjects(RuntimeEntities entities, Diction
234234
}
235235

236236
Dictionary<string, FieldDefinitionNode> fields = new();
237+
238+
// Add the DBOperationResult type to the schema
237239
NameNode nameNode = new(value: GraphQLUtils.DB_OPERATION_RESULT_TYPE);
238240
FieldDefinitionNode field = GetDbOperationResultField();
239241

240-
fields.TryAdd("result", field);
242+
fields.TryAdd(GraphQLUtils.DB_OPERATION_RESULT_FIELD_NAME, field);
241243

242244
objectTypes.Add(GraphQLUtils.DB_OPERATION_RESULT_TYPE, new ObjectTypeDefinitionNode(
243245
location: null,
@@ -290,7 +292,7 @@ private static FieldDefinitionNode GetDbOperationResultField()
290292
{
291293
return new(
292294
location: null,
293-
name: new("result"),
295+
name: new(GraphQLUtils.DB_OPERATION_RESULT_FIELD_NAME),
294296
description: new StringValueNode("Contains result for mutation execution"),
295297
arguments: new List<InputValueDefinitionNode>(),
296298
type: new StringType().ToTypeNode(),

src/Service.GraphQLBuilder/GraphQLUtils.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static class GraphQLUtils
3030
public const string OBJECT_TYPE_QUERY = "query";
3131
public const string SYSTEM_ROLE_ANONYMOUS = "anonymous";
3232
public const string DB_OPERATION_RESULT_TYPE = "DbOperationResult";
33+
public const string DB_OPERATION_RESULT_FIELD_NAME = "result";
3334

3435
public static bool IsModelType(ObjectTypeDefinitionNode objectTypeDefinitionNode)
3536
{
@@ -319,9 +320,11 @@ public static string GetDataSourceNameFromGraphQLContext(IMiddlewareContext cont
319320
/// </summary>
320321
public static string GetEntityNameFromContext(IMiddlewareContext context)
321322
{
322-
string entityName = context.Selection.Field.Type.TypeName();
323+
IOutputType type = context.Selection.Field.Type;
324+
string graphQLTypeName = type.TypeName();
325+
string entityName = graphQLTypeName;
323326

324-
if (entityName is DB_OPERATION_RESULT_TYPE)
327+
if (graphQLTypeName is DB_OPERATION_RESULT_TYPE)
325328
{
326329
// CUD for a mutation whose result set we do not have. Get Entity name mutation field directive.
327330
if (GraphQLUtils.TryExtractGraphQLFieldModelName(context.Selection.Field.Directives, out string? modelName))
@@ -333,7 +336,6 @@ public static string GetEntityNameFromContext(IMiddlewareContext context)
333336
{
334337
// for rest of scenarios get entity name from output object type.
335338
ObjectType underlyingFieldType;
336-
IOutputType type = context.Selection.Field.Type;
337339
underlyingFieldType = GraphQLUtils.UnderlyingGraphQLEntityType(type);
338340
// Example: CustomersConnectionObject - for get all scenarios.
339341
if (QueryBuilder.IsPaginationType(underlyingFieldType))

src/Service.GraphQLBuilder/Mutations/CreateMutationBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ public static FieldDefinitionNode Build(
253253
databaseType,
254254
entities);
255255

256-
// Create authorize directive denoting allowed roles
257-
List<DirectiveNode> fieldDefinitionNodeDirectives = new() { new(ModelDirectiveType.DirectiveName, new ArgumentNode("name", dbEntityName)) };
256+
List<DirectiveNode> fieldDefinitionNodeDirectives = new() { new(ModelDirectiveType.DirectiveName, new ArgumentNode(ModelDirectiveType.ModelNameArgument, dbEntityName)) };
258257

258+
// Create authorize directive denoting allowed roles
259259
if (CreateAuthorizationDirectiveIfNecessary(
260260
rolesAllowedForMutation,
261261
out DirectiveNode? authorizeDirective))

src/Service.GraphQLBuilder/Mutations/DeleteMutationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static FieldDefinitionNode Build(
5858
}
5959

6060
// Create authorize directive denoting allowed roles
61-
List<DirectiveNode> fieldDefinitionNodeDirectives = new() { new(ModelDirectiveType.DirectiveName, new ArgumentNode("name", dbEntityName)) };
61+
List<DirectiveNode> fieldDefinitionNodeDirectives = new() { new(ModelDirectiveType.DirectiveName, new ArgumentNode(ModelDirectiveType.ModelNameArgument, dbEntityName)) };
6262

6363
if (CreateAuthorizationDirectiveIfNecessary(
6464
rolesAllowedForMutation,

src/Service.GraphQLBuilder/Mutations/UpdateMutationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public static FieldDefinitionNode Build(
239239
new List<DirectiveNode>()));
240240

241241
// Create authorize directive denoting allowed roles
242-
List<DirectiveNode> fieldDefinitionNodeDirectives = new() { new(ModelDirectiveType.DirectiveName, new ArgumentNode("name", dbEntityName)) };
242+
List<DirectiveNode> fieldDefinitionNodeDirectives = new() { new(ModelDirectiveType.DirectiveName, new ArgumentNode(ModelDirectiveType.ModelNameArgument, dbEntityName)) };
243243

244244
if (CreateAuthorizationDirectiveIfNecessary(
245245
rolesAllowedForMutation,

src/Service.Tests/GraphQLBuilder/MutationBuilderTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Azure.DataApiBuilder.Config.DatabasePrimitives;
1010
using Azure.DataApiBuilder.Config.ObjectModel;
1111
using Azure.DataApiBuilder.Service.Exceptions;
12+
using Azure.DataApiBuilder.Service.GraphQLBuilder;
1213
using Azure.DataApiBuilder.Service.GraphQLBuilder.Mutations;
1314
using Azure.DataApiBuilder.Service.Tests.GraphQLBuilder.Helpers;
1415
using HotChocolate.Language;
@@ -94,7 +95,7 @@ Dictionary<string, EntityMetadata> entityPermissionsMap
9495
FieldDefinitionNode createField =
9596
query.Fields.Where(f => f.Name.Value == $"createFoo").First();
9697
Assert.AreEqual(expected: isAuthorizeDirectiveExpected ? 1 : 0,
97-
actual: createField.Directives.Where(x => x.Name.Value is "authorize").Count());
98+
actual: createField.Directives.Where(x => x.Name.Value is GraphQLUtils.AUTHORIZE_DIRECTIVE).Count());
9899
}
99100

100101
[TestMethod]

0 commit comments

Comments
 (0)