Skip to content

Commit 271cbf4

Browse files
michaelstaibsouvikghosh04RubenCerna2079
authored
Hot Chocolate 16 Upgrade (#2822)
This PR will create the base for the MCP server integration that is coming with Hot Chocolate 16. - upgrades packages - upgrades type interceptors - upgrades executor hooks #2789 --------- Co-authored-by: souvikghosh04 <[email protected]> Co-authored-by: RubenCerna2079 <[email protected]>
1 parent 36c270b commit 271cbf4

21 files changed

Lines changed: 166 additions & 150 deletions

src/Core/Models/GraphQLFilterParsers.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public GQLFilterParser(RuntimeConfigProvider runtimeConfigProvider, IMetadataPro
4343
/// Parse a predicate for a *FilterInput input type
4444
/// </summary>
4545
/// <param name="ctx">The GraphQL context, used to get the query variables</param>
46-
/// <param name="filterArgumentSchema">An IInputField object which describes the schema of the filter argument</param>
46+
/// <param name="filterArgumentSchema">An IInputValueDefinition object which describes the schema of the filter argument</param>
4747
/// <param name="fields">The fields in the *FilterInput being processed</param>
4848
/// <param name="queryStructure">The query structure for the entity being filtered providing
4949
/// the source alias of the underlying *FilterInput being processed,
5050
/// source definition of the table/view of the underlying *FilterInput being processed,
5151
/// and the function that parametrizes literals before they are written in string predicate operands.</param>
5252
public Predicate Parse(
5353
IMiddlewareContext ctx,
54-
IInputField filterArgumentSchema,
54+
IInputValueDefinition filterArgumentSchema,
5555
List<ObjectFieldNode> fields,
5656
BaseQueryStructure queryStructure)
5757
{
@@ -285,7 +285,7 @@ public Predicate Parse(
285285
/// <exception cref="DataApiBuilderException">
286286
private void HandleNestedFilterForCosmos(
287287
IMiddlewareContext ctx,
288-
IInputField filterField,
288+
IInputValueDefinition filterField,
289289
List<ObjectFieldNode> subfields,
290290
string columnName,
291291
string entityType,
@@ -466,7 +466,7 @@ public HttpContext GetHttpContextFromMiddlewareContext(IMiddlewareContext ctx)
466466
/// the fields.
467467
/// </summary>
468468
/// <param name="ctx">The GraphQL context, used to get the query variables</param>
469-
/// <param name="argumentSchema">An IInputField object which describes the schema of the scalar input argument (e.g. IntFilterInput)</param>
469+
/// <param name="argumentSchema">An IInputValueDefinition object which describes the schema of the scalar input argument (e.g. IntFilterInput)</param>
470470
/// <param name="fieldName">The name of the field</param>
471471
/// <param name="fields">The subfields of the scalar field</param>
472472
/// <param name="schemaName">The db schema name to which the table belongs</param>
@@ -476,7 +476,7 @@ public HttpContext GetHttpContextFromMiddlewareContext(IMiddlewareContext ctx)
476476
/// <param name="isListType">Flag to give a hint about the node type. It is only applicable for CosmosDB</param>
477477
private static Predicate ParseScalarType(
478478
IMiddlewareContext ctx,
479-
IInputField argumentSchema,
479+
IInputValueDefinition argumentSchema,
480480
string fieldName,
481481
List<ObjectFieldNode> fields,
482482
string schemaName,
@@ -498,8 +498,8 @@ private static Predicate ParseScalarType(
498498
/// If and/or is passed as empty, a predicate representing 1 != 1 is returned
499499
/// </returns>
500500
/// <param name="ctx">The GraphQL context, used to get the query variables</param>
501-
/// <param name="argumentSchema">An IInputField object which describes the and/or filter input argument</param>
502-
/// <param name="filterArgumentSchema">An IInputField object which describes the base filter input argument (e.g. BookFilterInput)
501+
/// <param name="argumentSchema">An IInputValueDefinition object which describes the and/or filter input argument</param>
502+
/// <param name="filterArgumentSchema">An IInputValueDefinition object which describes the base filter input argument (e.g. BookFilterInput)
503503
/// to which the and/or belongs </param>
504504
/// <param name="fields">The subfields of the and/or field</param>
505505
/// <param name="schemaName">The db schema name to which the table belongs</param>
@@ -510,8 +510,8 @@ private static Predicate ParseScalarType(
510510
/// <param name="processLiterals">Parametrizes literals before they are written in string predicate operands</param>
511511
private Predicate ParseAndOr(
512512
IMiddlewareContext ctx,
513-
IInputField argumentSchema,
514-
IInputField filterArgumentSchema,
513+
IInputValueDefinition argumentSchema,
514+
IInputValueDefinition filterArgumentSchema,
515515
List<IValueNode> fields,
516516
BaseQueryStructure baseQuery,
517517
PredicateOperation op)
@@ -600,14 +600,14 @@ public static class FieldFilterParser
600600
/// Parse a scalar field into a predicate
601601
/// </summary>
602602
/// <param name="ctx">The GraphQL context, used to get the query variables</param>
603-
/// <param name="argumentSchema">An IInputField object which describes the schema of the scalar input argument (e.g. IntFilterInput)</param>
603+
/// <param name="argumentSchema">An IInputValueDefinition object which describes the schema of the scalar input argument (e.g. IntFilterInput)</param>
604604
/// <param name="column">The table column targeted by the field</param>
605605
/// <param name="fields">The subfields of the scalar field</param>
606606
/// <param name="processLiterals">Parametrizes literals before they are written in string predicate operands</param>
607607
/// <param name="isListType">Flag which gives a hint about the node type in the given schema. only for CosmosDB it can be of list type. Refer <a href=https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/array-contains>here</a>.</param>
608608
public static Predicate Parse(
609609
IMiddlewareContext ctx,
610-
IInputField argumentSchema,
610+
IInputValueDefinition argumentSchema,
611611
Column column,
612612
List<ObjectFieldNode> fields,
613613
Func<object, string?, string> processLiterals,

src/Core/Resolvers/BaseQueryStructure.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public virtual SourceDefinition GetUnderlyingSourceDefinition()
198198
/// <summary>
199199
/// Extracts the *Connection.items schema field from the *Connection schema field
200200
/// </summary>
201-
internal static IObjectField ExtractItemsSchemaField(IObjectField connectionSchemaField)
201+
internal static ObjectField ExtractItemsSchemaField(ObjectField connectionSchemaField)
202202
{
203203
return connectionSchemaField.Type.NamedType<ObjectType>().Fields[QueryBuilder.PAGINATION_FIELD_NAME];
204204
}

src/Core/Resolvers/CosmosQueryEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ public Task<IActionResult> ExecuteAsync(StoredProcedureRequestContext context, s
241241
}
242242

243243
/// <inheritdoc />
244-
public JsonElement ResolveObject(JsonElement element, IObjectField fieldSchema, ref IMetadata metadata)
244+
public JsonElement ResolveObject(JsonElement element, ObjectField fieldSchema, ref IMetadata metadata)
245245
{
246246
return element;
247247
}
248248

249249
/// <inheritdoc />
250250
/// metadata is not used in this method, but it is required by the interface.
251-
public object ResolveList(JsonElement array, IObjectField fieldSchema, ref IMetadata metadata)
251+
public object ResolveList(JsonElement array, ObjectField fieldSchema, ref IMetadata metadata)
252252
{
253253
IType listType = fieldSchema.Type;
254254
// Is the List type nullable? [...]! vs [...]

src/Core/Resolvers/IQueryEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public interface IQueryEngine
5858
/// <summary>
5959
/// Resolves a jsonElement representing an inner object based on the field's schema and metadata
6060
/// </summary>
61-
public JsonElement ResolveObject(JsonElement element, IObjectField fieldSchema, ref IMetadata metadata);
61+
public JsonElement ResolveObject(JsonElement element, ObjectField fieldSchema, ref IMetadata metadata);
6262

6363
/// <summary>
6464
/// Resolves a jsonElement representing a list type based on the field's schema and metadata
6565
/// </summary>
66-
public object ResolveList(JsonElement array, IObjectField fieldSchema, ref IMetadata? metadata);
66+
public object ResolveList(JsonElement array, ObjectField fieldSchema, ref IMetadata? metadata);
6767
}
6868
}

src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ internal static List<string> GetSubArgumentNamesFromGQLMutArguments
514514

515515
if (mutationParameters.TryGetValue(fieldName, out object? item))
516516
{
517-
IObjectField fieldSchema = context.Selection.Field;
518-
IInputField itemsArgumentSchema = fieldSchema.Arguments[fieldName];
517+
ObjectField fieldSchema = context.Selection.Field;
518+
IInputValueDefinition itemsArgumentSchema = fieldSchema.Arguments[fieldName];
519519
InputObjectType itemsArgumentObject = ExecutionHelper.InputObjectTypeFromIInputField(itemsArgumentSchema);
520520

521521
// An inline argument was set

src/Core/Resolvers/Sql Query Structures/SqlQueryStructure.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public SqlQueryStructure(
172172
_ctx = ctx;
173173
IsMultipleCreateOperation = isMultipleCreateOperation;
174174

175-
IObjectField schemaField = _ctx.Selection.Field;
175+
ObjectField schemaField = _ctx.Selection.Field;
176176
FieldNode? queryField = _ctx.Selection.SyntaxNode;
177177

178178
IOutputType outputType = schemaField.Type;
@@ -388,7 +388,7 @@ private SqlQueryStructure(
388388
IDictionary<string, object?> queryParams,
389389
ISqlMetadataProvider sqlMetadataProvider,
390390
IAuthorizationResolver authorizationResolver,
391-
IObjectField schemaField,
391+
ObjectField schemaField,
392392
FieldNode? queryField,
393393
IncrementingInteger counter,
394394
RuntimeConfigProvider runtimeConfigProvider,
@@ -408,7 +408,7 @@ private SqlQueryStructure(
408408

409409
// extract the query argument schemas before switching schemaField to point to *Connetion.items
410410
// since the pagination arguments are not placed on the items, but on the pagination query
411-
IFieldCollection<IInputField> queryArgumentSchemas = schemaField.Arguments;
411+
ArgumentCollection queryArgumentSchemas = schemaField.Arguments;
412412

413413
PaginationMetadata.IsPaginated = QueryBuilder.IsPaginationType(_underlyingFieldType);
414414

@@ -796,7 +796,7 @@ private void AddGraphQLFields(IReadOnlyList<ISelectionNode> selections, RuntimeC
796796
}
797797
else
798798
{
799-
IObjectField? subschemaField = _underlyingFieldType.Fields[fieldName];
799+
ObjectField? subschemaField = _underlyingFieldType.Fields[fieldName];
800800

801801
if (_ctx == null)
802802
{
@@ -986,14 +986,14 @@ private void ProcessAggregations(FieldNode aggregationsField, IMiddlewareContext
986986
}
987987

988988
// Retrieve the schema field from the GraphQL context
989-
IObjectField schemaField = ctx.Selection.Field;
989+
ObjectField schemaField = ctx.Selection.Field;
990990

991991
// Get the 'group by' field from the schema's entity type
992-
IObjectField groupByField = schemaField.Type.NamedType<ObjectType>()
992+
ObjectField groupByField = schemaField.Type.NamedType<ObjectType>()
993993
.Fields[QueryBuilder.GROUP_BY_FIELD_NAME];
994994

995995
// Get the 'aggregations' field from the 'group by' entity type
996-
IObjectField aggregationsObjectField = groupByField.Type.NamedType<ObjectType>()
996+
ObjectField aggregationsObjectField = groupByField.Type.NamedType<ObjectType>()
997997
.Fields[QueryBuilder.GROUP_BY_AGGREGATE_FIELD_NAME];
998998

999999
// Iterate through each selection in the aggregation field
@@ -1064,7 +1064,7 @@ private void ProcessAggregations(FieldNode aggregationsField, IMiddlewareContext
10641064
List<ObjectFieldNode> filterFields = (List<ObjectFieldNode>)havingArg.Value.Value!;
10651065

10661066
// Retrieve the corresponding aggregation operation field from the schema
1067-
IObjectField operationObjectField = aggregationsObjectField.Type.NamedType<ObjectType>()
1067+
ObjectField operationObjectField = aggregationsObjectField.Type.NamedType<ObjectType>()
10681068
.Fields[operation.ToString()];
10691069

10701070
// Parse the filtering conditions and apply them to the aggregation
@@ -1105,7 +1105,7 @@ private void ProcessAggregations(FieldNode aggregationsField, IMiddlewareContext
11051105
/// so we find their backing column names before creating the orderBy list.
11061106
/// All the remaining primary key columns are also added to ensure there are no tie breaks.
11071107
/// </summary>
1108-
private List<OrderByColumn> ProcessGqlOrderByArg(List<ObjectFieldNode> orderByFields, IInputField orderByArgumentSchema, bool isGroupByQuery = false)
1108+
private List<OrderByColumn> ProcessGqlOrderByArg(List<ObjectFieldNode> orderByFields, IInputValueDefinition orderByArgumentSchema, bool isGroupByQuery = false)
11091109
{
11101110
if (_ctx is null)
11111111
{

src/Core/Resolvers/SqlMutationEngine.cs

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public SqlMutationEngine(
106106
mutationOperation is EntityActionOperation.Create)
107107
{
108108
// Multiple create mutation request is validated to ensure that the request is valid semantically.
109-
IInputField schemaForArgument = context.Selection.Field.Arguments[inputArgumentName];
109+
IInputValueDefinition schemaForArgument = context.Selection.Field.Arguments[inputArgumentName];
110110
MultipleMutationEntityInputValidationContext multipleMutationEntityInputValidationContext = new(
111111
entityName: entityName,
112112
parentEntityName: string.Empty,
@@ -1689,8 +1689,8 @@ private static void PopulateCurrentAndLinkingEntityParams(
16891689
{
16901690
if (mutationParameters.TryGetValue(rootFieldName, out object? inputParameters))
16911691
{
1692-
IObjectField fieldSchema = context.Selection.Field;
1693-
IInputField itemsArgumentSchema = fieldSchema.Arguments[rootFieldName];
1692+
ObjectField fieldSchema = context.Selection.Field;
1693+
IInputValueDefinition itemsArgumentSchema = fieldSchema.Arguments[rootFieldName];
16941694
InputObjectType inputObjectType = ExecutionHelper.InputObjectTypeFromIInputField(itemsArgumentSchema);
16951695
return GQLMultipleCreateArgumentToDictParamsHelper(context, inputObjectType, inputParameters);
16961696
}
@@ -1871,7 +1871,7 @@ private static void PopulateCurrentAndLinkingEntityParams(
18711871
/// <exception cref="DataApiBuilderException"></exception>
18721872
private static InputObjectType GetInputObjectTypeForAField(string fieldName, FieldCollection<InputField> fields)
18731873
{
1874-
if (fields.TryGetField(fieldName, out IInputField? field))
1874+
if (fields.TryGetField(fieldName, out InputField? field))
18751875
{
18761876
return ExecutionHelper.InputObjectTypeFromIInputField(field);
18771877
}
@@ -1886,7 +1886,7 @@ private static InputObjectType GetInputObjectTypeForAField(string fieldName, Fie
18861886
/// </summary>
18871887
/// <param name="entityName">The name of the entity.</param>
18881888
/// <param name="parameters">The parameters for the DELETE operation.</param>
1889-
/// <param name="sqlMetadataProvider">Metadataprovider for db on which to perform operation.</param>
1889+
/// <param name="sqlMetadataProvider">Metadata provider for db on which to perform operation.</param>
18901890
/// <returns>A dictionary of properties of the Db Data Reader like RecordsAffected, HasRows.</returns>
18911891
private async Task<Dictionary<string, object>?>
18921892
PerformDeleteOperation(
@@ -2127,7 +2127,7 @@ private void AuthorizeEntityAndFieldsForMutation(
21272127
IDictionary<string, object?> parametersDictionary
21282128
)
21292129
{
2130-
if (context.Selection.Field.Arguments.TryGetField(inputArgumentName, out IInputField? schemaForArgument))
2130+
if (context.Selection.Field.Arguments.TryGetField(inputArgumentName, out Argument? schemaForArgument))
21312131
{
21322132
// Dictionary to store all the entities and their corresponding exposed column names referenced in the mutation.
21332133
Dictionary<string, HashSet<string>> entityToExposedColumns = new();
@@ -2173,42 +2173,53 @@ private void AuthorizeEntityAndFieldsForMutation(
21732173
/// <param name="entityToExposedColumns">Dictionary to store all the entities and their corresponding exposed column names referenced in the mutation.</param>
21742174
/// <param name="schema">Schema for the input field.</param>
21752175
/// <param name="entityName">Name of the entity.</param>
2176-
/// <param name="context">Middleware Context.</param>
2176+
/// <param name="context">Middleware context.</param>
21772177
/// <param name="parameters">Value for the input field.</param>
2178-
/// <example> 1. mutation {
2179-
/// createbook(
2180-
/// item: {
2181-
/// title: "book #1",
2182-
/// reviews: [{ content: "Good book." }, { content: "Great book." }],
2183-
/// publishers: { name: "Macmillan publishers" },
2184-
/// authors: [{ birthdate: "1997-09-03", name: "Red house authors", royal_percentage: 4.6 }]
2185-
/// })
2186-
/// {
2187-
/// id
2188-
/// }
2189-
/// 2. mutation {
2190-
/// createbooks(
2191-
/// items: [{
2192-
/// title: "book #1",
2193-
/// reviews: [{ content: "Good book." }, { content: "Great book." }],
2194-
/// publishers: { name: "Macmillan publishers" },
2195-
/// authors: [{ birthdate: "1997-09-03", name: "Red house authors", royal_percentage: 4.9 }]
2196-
/// },
2197-
/// {
2198-
/// title: "book #2",
2199-
/// reviews: [{ content: "Awesome book." }, { content: "Average book." }],
2200-
/// publishers: { name: "Pearson Education" },
2201-
/// authors: [{ birthdate: "1990-11-04", name: "Penguin Random House", royal_percentage: 8.2 }]
2202-
/// }])
2203-
/// {
2204-
/// items{
2205-
/// id
2206-
/// title
2207-
/// }
2208-
/// }</example>
2178+
/// <example>
2179+
/// Example 1 - Single item creation:
2180+
/// <code>
2181+
/// mutation {
2182+
/// createbook(
2183+
/// item: {
2184+
/// title: "book #1",
2185+
/// reviews: [{ content: "Good book." }, { content: "Great book." }],
2186+
/// publishers: { name: "Macmillan publishers" },
2187+
/// authors: [{ birthdate: "1997-09-03", name: "Red house authors", royal_percentage: 4.6 }]
2188+
/// })
2189+
/// {
2190+
/// id
2191+
/// }
2192+
/// }
2193+
/// </code>
2194+
///
2195+
/// Example 2 - Multiple items creation:
2196+
/// <code>
2197+
/// mutation {
2198+
/// createbooks(
2199+
/// items: [{
2200+
/// title: "book #1",
2201+
/// reviews: [{ content: "Good book." }, { content: "Great book." }],
2202+
/// publishers: { name: "Macmillan publishers" },
2203+
/// authors: [{ birthdate: "1997-09-03", name: "Red house authors", royal_percentage: 4.9 }]
2204+
/// },
2205+
/// {
2206+
/// title: "book #2",
2207+
/// reviews: [{ content: "Awesome book." }, { content: "Average book." }],
2208+
/// publishers: { name: "Pearson Education" },
2209+
/// authors: [{ birthdate: "1990-11-04", name: "Penguin Random House", royal_percentage: 8.2 }]
2210+
/// }])
2211+
/// {
2212+
/// items {
2213+
/// id
2214+
/// title
2215+
/// }
2216+
/// }
2217+
/// }
2218+
/// </code>
2219+
/// </example>
22092220
private void PopulateMutationEntityAndFieldsToAuthorize(
22102221
Dictionary<string, HashSet<string>> entityToExposedColumns,
2211-
IInputField schema,
2222+
IInputValueDefinition schema,
22122223
string entityName,
22132224
IMiddlewareContext context,
22142225
object parameters)

0 commit comments

Comments
 (0)