Skip to content

Commit b8123f4

Browse files
author
Samuel Abraham
committed
v9.1.0
1 parent 1d6c1db commit b8123f4

64 files changed

Lines changed: 1977 additions & 1589 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/dotnet-core.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET8
1+
name: .NET9
22

33
on:
44
push:
@@ -13,10 +13,10 @@ jobs:
1313

1414
steps:
1515
- uses: actions/checkout@v2
16-
- name: Setup .NET8
16+
- name: Setup .NET9
1717
uses: actions/setup-dotnet@v1
1818
with:
19-
dotnet-version: 8.0.x
19+
dotnet-version: 9.0.x
2020
- name: Install dependencies
2121
run: dotnet restore
2222
- name: Build

src/TypeCache.GraphQL/Extensions/GraphQLExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static void AddOrderBy(this EnumerationGraphType @this, string column, st
6969
{
7070
var asc = Sort.Ascending.ToSQL();
7171
var desc = Sort.Descending.ToSQL();
72+
7273
@this.Add(Invariant($"{column}_{asc}"), Invariant($"{column} {asc}"), Invariant($"{column} {asc}"), deprecationReason);
7374
@this.Add(Invariant($"{column}_{desc}"), Invariant($"{column} {desc}"), Invariant($"{column} {desc}"), deprecationReason);
7475
}
@@ -92,7 +93,7 @@ public static Connection<T> ToConnection<T>(this IEnumerable<T> data, uint offse
9293
};
9394
}
9495

95-
public static FieldType ToFieldType(this PropertyInfo @this, IFieldResolver resolver)
96+
public static FieldType ToFieldType(this PropertyInfo @this)
9697
{
9798
var type = @this.ToGraphQLType(false);
9899
var arguments = new QueryArguments();
@@ -124,7 +125,7 @@ public static FieldType ToFieldType(this PropertyInfo @this, IFieldResolver reso
124125
Name = @this.GraphQLName(),
125126
Description = @this.GraphQLDescription(),
126127
DeprecationReason = @this.GraphQLDeprecationReason(),
127-
Resolver = resolver
128+
Resolver = (IFieldResolver)typeof(PropertyFieldResolver<>).MakeGenericType(@this.DeclaringType!).Create([@this])!
128129
};
129130
}
130131

src/TypeCache.GraphQL/Extensions/ResolveFieldContextExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ private static void AddInputs(this IDictionary<string, object?> @this, string pa
120120
{
121121
if (value is GraphQLListValue listValue)
122122
{
123-
if (listValue.Values?.Any<GraphQLObjectValue>() is true)
124-
listValue.Values.OfType<GraphQLObjectValue>().ToArray().ForEach((objectValue, i) =>
125-
objectValue.Fields?.ForEach(field => @this[Invariant($"{path}.{i}.{field.Name}")] = field.Value.GetScalarValue()));
123+
var objectValues = listValue.Values?.OfType<GraphQLObjectValue>();
124+
if (objectValues?.Any() is true)
125+
objectValues.Index().ForEach(_ =>
126+
_.Item.Fields?.ForEach(field => @this[Invariant($"{path}.{_.Index}.{field.Name}")] = field.Value.GetScalarValue()));
126127
else if (listValue.Values?.Any() is true)
127128
@this[path] = listValue.Values.Select(_ => _.GetScalarValue()).ToArray();
128129
}

src/TypeCache.GraphQL/Extensions/SchemaExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static FieldType[] AddDatabaseSchemaQueries(this ISchema @this, IDataSour
5050
var table = dataSource.GetDatabaseSchema(SchemaCollection.MetaDataCollections);
5151
var rows = table.Rows.OfType<DataRow>();
5252

53-
return rows.Select(row => @this.AddDatabaseSchemaQuery(dataSource, row[SchemaColumn.collectionName].ToString().Enum<SchemaCollection>()!.Value)).ToArray();
53+
return rows.Select(row => @this.AddDatabaseSchemaQuery(dataSource, row[SchemaColumn.collectionName].ToString().ToEnum<SchemaCollection>()!.Value)).ToArray();
5454
}
5555

5656
/// <summary>
@@ -125,7 +125,7 @@ public static FieldType AddDatabaseSchemaQuery(this ISchema @this, IDataSource d
125125
Resolver = new DatabaseSchemaFieldResolver()
126126
});
127127
fieldType.Metadata.Add(nameof(IDataSource), dataSource);
128-
fieldType.Metadata.Add(nameof(SchemaCollection), table.TableName.Enum<SchemaCollection>());
128+
fieldType.Metadata.Add(nameof(SchemaCollection), table.TableName.ToEnum<SchemaCollection>());
129129

130130
return fieldType;
131131
}
@@ -996,8 +996,6 @@ public static FieldType AddSqlApiInsertEndpoint<T>(this ISchema @this, IDataSour
996996
var propertyName = property.GraphQLName();
997997
var propertyDeprecationReason = property.GraphQLDeprecationReason();
998998

999-
var ascending = Sort.Ascending.ToSQL();
1000-
graphOrderByEnum.Add(Invariant($"{propertyName}_{ascending}"), Invariant($"{propertyName} {ascending}"), Invariant($"{propertyName} {ascending}"), propertyDeprecationReason);
1001999
graphOrderByEnum.AddOrderBy(propertyName, propertyDeprecationReason);
10021000
}
10031001

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
global using System;
2+
global using System.Buffers.Text;
3+
global using System.Diagnostics;
4+
global using System.Diagnostics.CodeAnalysis;
5+
global using static System.FormattableString;
6+
global using static System.Runtime.CompilerServices.MethodImplOptions;
7+
global using CancellationToken = System.Threading.CancellationToken;
8+
global using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
9+
global using Task = System.Threading.Tasks.Task;
10+
global using ValueTask = System.Threading.Tasks.ValueTask;

src/TypeCache.GraphQL/Resolvers/PropertyFieldResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public sealed class PropertyFieldResolver<T>(PropertyInfo propertyInfo) : FieldR
8080
var pattern = context.GetArgument<string>("match");
8181
if (pattern.IsNotBlank())
8282
{
83-
var match = text.Regex(RegexOptions.Compiled | RegexOptions.Singleline).Match(text);
83+
var match = text.ToRegex(RegexOptions.Compiled | RegexOptions.Singleline).Match(text);
8484
if (match.Success)
8585
text = match.Value;
8686
else

src/TypeCache.GraphQL/TypeCache.GraphQL.csproj

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Nullable>enable</Nullable>
55
<RootNamespace>TypeCache.GraphQL</RootNamespace>
66
<PackageId>TypeCache.GraphQL</PackageId>
7-
<Version>9.0.2</Version>
7+
<Version>9.1.0</Version>
88
<Authors>Samuel Abraham &lt;sam987883@gmail.com&gt;</Authors>
99
<Company>Samuel Abraham &lt;sam987883@gmail.com&gt;</Company>
1010
<Title>TypeCache GraphQL</Title>
@@ -36,30 +36,7 @@ Automatic generation of SQL related endpoints.
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<PackageReference Include="GraphQL" Version="8.2.1" />
40-
</ItemGroup>
41-
42-
<ItemGroup>
43-
<Using Include="System.Diagnostics" />
44-
<Using Include="System.Diagnostics.CodeAnalysis" />
45-
<Using Include="System.FormattableString">
46-
<Static>True</Static>
47-
</Using>
48-
<Using Include="System.Runtime.CompilerServices.MethodImplAttribute">
49-
<Alias>MethodImplAttribute</Alias>
50-
</Using>
51-
<Using Include="System.Runtime.CompilerServices.MethodImplOptions">
52-
<Static>True</Static>
53-
</Using>
54-
<Using Include="System.Threading.CancellationToken">
55-
<Alias>CancellationToken</Alias>
56-
</Using>
57-
<Using Include="System.Threading.Tasks.Task">
58-
<Alias>Task</Alias>
59-
</Using>
60-
<Using Include="System.Threading.Tasks.ValueTask">
61-
<Alias>ValueTask</Alias>
62-
</Using>
39+
<PackageReference Include="GraphQL" Version="8.4.0" />
6340
</ItemGroup>
6441

6542
<ItemGroup>

src/TypeCache.GraphQL/Types/InterfaceGraphType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public InterfaceGraphType()
1919
typeof(T).GetPublicProperties()
2020
.Where(propertyInfo => propertyInfo.CanRead && !propertyInfo.GraphQLIgnore())
2121
.ToArray()
22-
.ForEach(propertyInfo => this.AddField(propertyInfo.ToFieldType(new PropertyFieldResolver<T>(propertyInfo))));
22+
.ForEach(propertyInfo => this.AddField(propertyInfo.ToFieldType()));
2323
}
2424
}

src/TypeCache.GraphQL/Types/OutputGraphType.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public OutputGraphType(string name)
3030
typeof(T).GetPublicProperties()
3131
.Where(propertyInfo => propertyInfo.CanRead && !propertyInfo.GraphQLIgnore())
3232
.ToArray()
33-
.ForEach(propertyInfo => this.AddField(propertyInfo.ToFieldType(new PropertyFieldResolver<T>(propertyInfo))));
33+
.ForEach(propertyInfo => this.AddField(propertyInfo.ToFieldType()));
3434

3535
typeof(T).GetInterfaces()
3636
.Where(_ => !_.HasElementType && !_.IsGenericType)
@@ -39,10 +39,7 @@ public OutputGraphType(string name)
3939
}
4040

4141
public FieldType AddField(PropertyInfo propertyInfo)
42-
{
43-
var fieldType = propertyInfo.ToFieldType(new PropertyFieldResolver<T>(propertyInfo));
44-
return this.AddField(fieldType);
45-
}
42+
=> this.AddField(propertyInfo.ToFieldType());
4643

4744
/// <summary>
4845
/// Adds a field that is based on the result of the <paramref name="methodInfo"/>.<br/>

src/TypeCache.GraphQL/Web/GraphQLMiddleware.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace TypeCache.GraphQL.Web;
1616
public sealed class GraphQLMiddleware(RequestDelegate next, PathString route, IConfigureSchema configureSchema)
1717
{
1818
public async Task Invoke(HttpContext httpContext
19-
, IServiceProvider provider
2019
, IDocumentExecuter executer
2120
, IDocumentExecutionListener listener
2221
, IGraphQLSerializer graphQLSerializer
@@ -36,15 +35,15 @@ public async Task Invoke(HttpContext httpContext
3635
}
3736

3837
var requestId = Guid.NewGuid();
39-
var timeProvider = provider.GetService(typeof(TimeProvider)) as TimeProvider ?? TimeProvider.System;
38+
var timeProvider = httpContext.RequestServices.GetService(typeof(TimeProvider)) as TimeProvider ?? TimeProvider.System;
4039
var requestTime = timeProvider.GetLocalNow().ToISO8601();
4140
var userContext = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
4241
{
4342
{ "RequestId", requestId },
4443
{ "RequestTime", requestTime },
4544
{ nameof(httpContext.User), httpContext.User }
4645
};
47-
var schema = new Schema(provider, [configureSchema])
46+
var schema = new Schema(httpContext.RequestServices, [configureSchema])
4847
{
4948
Description = "GraphQL schema route: " + route
5049
};
@@ -54,7 +53,7 @@ public async Task Invoke(HttpContext httpContext
5453
Variables = request.Variables is not null ? new Inputs(request.Variables!) : null,
5554
OperationName = request.OperationName,
5655
Query = request.Query,
57-
RequestServices = provider,
56+
RequestServices = httpContext.RequestServices,
5857
Schema = schema,
5958
UserContext = userContext,
6059
ValidationRules = DocumentValidator.CoreRules

0 commit comments

Comments
 (0)