Skip to content

Commit b0e0d70

Browse files
committed
Update some comments and clean up some code
1 parent 43e8d82 commit b0e0d70

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

src/Core/Services/GraphQLSchemaCreator.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ private DocumentNode GenerateSqlGraphQLObjects(RuntimeEntities entities, Diction
295295
Dictionary<string, IEnumerable<string>> rolesAllowedForFields = new();
296296
SourceDefinition sourceDefinition = sqlMetadataProvider.GetSourceDefinition(entityName);
297297
bool isStoredProcedure = entity.Source.Type is EntitySourceType.StoredProcedure;
298+
EntityActionOperation operation = isStoredProcedure ? EntityActionOperation.Execute : EntityActionOperation.Read;
298299
foreach (string column in sourceDefinition.Columns.Keys)
299300
{
300-
EntityActionOperation operation = isStoredProcedure ? EntityActionOperation.Execute : EntityActionOperation.Read;
301301
IEnumerable<string> roles = _authorizationResolver.GetRolesForField(entityName, field: column, operation: operation);
302302
if (!rolesAllowedForFields.TryAdd(key: column, value: roles))
303303
{
@@ -309,7 +309,6 @@ private DocumentNode GenerateSqlGraphQLObjects(RuntimeEntities entities, Diction
309309
}
310310
}
311311

312-
// The roles allowed for Fields are the roles allowed to READ the fields, so any role that has a read definition for the field.
313312
// Only add objectTypeDefinition for GraphQL if it has a role definition defined for access.
314313
if (rolesAllowedForEntity.Any())
315314
{
@@ -397,23 +396,18 @@ private DocumentNode GenerateSqlGraphQLObjects(RuntimeEntities entities, Diction
397396
GenerateSourceTargetLinkingObjectDefinitions(objectTypes, linkingObjectTypes);
398397
}
399398

400-
// Return a list of all the object types to be exposed in the schema.
401-
Dictionary<string, FieldDefinitionNode> fields = new();
402-
403-
// Add the DBOperationResult type to the schema
404399
NameNode nameNode = new(value: GraphQLUtils.DB_OPERATION_RESULT_TYPE);
405-
FieldDefinitionNode field = GetDbOperationResultField();
406-
407-
fields.TryAdd(GraphQLUtils.DB_OPERATION_RESULT_FIELD_NAME, field);
408400

401+
// Add the DBOperationResult type to the schema
409402
objectTypes.Add(GraphQLUtils.DB_OPERATION_RESULT_TYPE, new ObjectTypeDefinitionNode(
410403
location: null,
411404
name: nameNode,
412405
description: null,
413406
new List<DirectiveNode>(),
414407
new List<NamedTypeNode>(),
415-
fields.Values.ToImmutableList()));
408+
ImmutableList.Create(GetDbOperationResultField())));
416409

410+
// Return a list of all the object types to be exposed in the schema.
417411
List<IDefinitionNode> nodes = new(objectTypes.Values);
418412
nodes.AddRange(enumTypes.Values);
419413
return new DocumentNode(nodes);
@@ -748,7 +742,7 @@ private static FieldDefinitionNode GetDbOperationResultField()
748742
DocumentNode cosmosResult = GenerateCosmosGraphQLObjects(cosmosDataSourceNames, inputObjects);
749743
DocumentNode sqlResult = GenerateSqlGraphQLObjects(sql, inputObjects);
750744
// Create Root node with definitions from both cosmos and sql.
751-
DocumentNode root = new(cosmosResult.Definitions.Concat(sqlResult.Definitions).ToImmutableList());
745+
DocumentNode root = cosmosResult.WithDefinitions(cosmosResult.Definitions.Concat(sqlResult.Definitions).ToImmutableList());
752746

753747
// Merge the inputobjectType definitions from cosmos and sql onto the root.
754748
return (root.WithDefinitions(root.Definitions.Concat(inputObjects.Values).ToImmutableList()), inputObjects);

src/Service.GraphQLBuilder/GraphQLTypes/SupportedTypes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Azure.DataApiBuilder.Service.GraphQLBuilder.GraphQLTypes
66
/// <summary>
77
/// Only used to group the supported type names under a class with a relevant name.
88
/// The type names mentioned here are Hotchocolate scalar built in types.
9-
/// The corresponding SQL type name may be different for e.g. UUID maps to Guid as the SQL type.
9+
/// The corresponding SQL type name may be different for e.g. UUID maps to Guid as the .NET type.
1010
/// </summary>
1111
public static class SupportedHotChocolateTypes
1212
{
@@ -32,7 +32,6 @@ public static class SupportedHotChocolateTypes
3232
// new name so the generated schema does not depend on a deprecated scalar.
3333
public const string BYTEARRAY_TYPE = "Base64String";
3434
public const string DATETIME_TYPE = "DateTime";
35-
public const string DATETIMEOFFSET_TYPE = "DateTimeOffset";
3635
public const string LOCALTIME_TYPE = "LocalTime";
3736
public const string TIME_TYPE = "Time";
3837
}
@@ -46,6 +45,7 @@ public static class SupportedDateTimeTypes
4645
public const string DATE_TYPE = "date";
4746
public const string SMALLDATETIME_TYPE = "smalldatetime";
4847
public const string DATETIME2_TYPE = "datetime2";
48+
public const string DATETIMEOFFSET_TYPE = "DateTimeOffset";
4949
}
5050

5151
/// <summary>

src/Service.GraphQLBuilder/Sql/SchemaConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public enum AggregationType
3939
/// <param name="configEntity">Runtime config information for the table.</param>
4040
/// <param name="entities">Key/Value Collection mapping entity name to the entity object,
4141
/// currently used to lookup relationship metadata.</param>
42-
/// <param name="rolesAllowedForEntity">Roles to add to authorize directive at the object level (applies to query/read ops).</param>
43-
/// <param name="rolesAllowedForFields">Roles to add to authorize directive at the field level (applies to mutations).</param>
42+
/// <param name="rolesAllowedForEntity">Roles to add to authorize directive at the object level.</param>
43+
/// <param name="rolesAllowedForFields">Roles to add to authorize directive at the field level.</param>
4444
/// <returns>A GraphQL object type to be provided to a Hot Chocolate GraphQL document.</returns>
4545
public static ObjectTypeDefinitionNode GenerateObjectTypeDefinitionForDatabaseObject(
4646
string entityName,
@@ -179,7 +179,7 @@ private static ObjectTypeDefinitionNode CreateObjectTypeDefinitionForTableOrView
179179
List<DirectiveNode> directives = new();
180180
if (sourceDefinition.PrimaryKey.Contains(columnName))
181181
{
182-
directives.Add(new DirectiveNode(PrimaryKeyDirectiveType.DirectiveName, new ArgumentNode("databaseType", column.SystemType.Name)));
182+
directives.Add(new DirectiveNode(PrimaryKeyDirectiveType.DirectiveName));
183183
}
184184

185185
if (column.IsReadOnly)

0 commit comments

Comments
 (0)