Skip to content

Commit

Permalink
Merge pull request #15 from cajuncoding/feature/factor_out_repodb_pag…
Browse files Browse the repository at this point in the history
…ing_extensions_for_non_graphql_use

Feature/factor out repodb paging extensions for non graphql use
  • Loading branch information
cajuncoding authored May 17, 2024
2 parents 95ae67d + ad572fc commit 3a263e5
Show file tree
Hide file tree
Showing 83 changed files with 2,753 additions and 1,016 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
# run: |
# echo Add other actions to build,
# echo test, and deploy your project.
- name: "Publish NuGet: RepoDb.SqlServer.PagingOperations"
uses: alirezanet/publish-nuget@v3.0.4
with:
# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: RepoDb.SqlServer.PagingOperations/RepoDb.SqlServer.PagingOperations.csproj
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
- name: "Publish NuGet: GraphQL.ResolverProcessingExtensions"
uses: alirezanet/publish-nuget@v3.0.4
with:
Expand Down
3 changes: 2 additions & 1 deletion GraphQL.RepoDb.SqlServer/GraphQL.RepoDb.SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="RepoDb.SqlServer" Version="1.1.4" />
<PackageReference Include="RepoDb.SqlServer" Version="1.1.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GraphQL.ResolverProcessingExtensions\GraphQL.ResolverProcessingExtensions.csproj" />
<ProjectReference Include="..\RepoDb.SqlServer.PagingOperations\RepoDb.SqlServer.PagingOperations.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using System.Reflection.GraphQLRepoDb.CustomExtensions;
using System.Threading.Tasks;
using HotChocolate.Data.Projections.Context;
using HotChocolate.ResolverProcessingExtensions;
using RepoDb.SqlServer.PagingOperations.Reflection;

namespace HotChocolate.RepoDb
{
Expand Down Expand Up @@ -68,18 +68,20 @@ private static Delegate GetRepoDbMapperFactoryForResolver(MethodInfo resolverMet
if (repoDbMapperParam?.ParameterType is {} paramType)
{
//In order to correctly Map the GraphQL Params Context to an Entity for RepoDb, we must know
// the have a Generic Type for the Entity therefore we require that the Resolver Param be a concrete type with Generic Parameter.
//
// the Generic Type for the Entity therefore we require that the Resolver Param be a
// concrete type with Generic Parameter.
if (paramType.IsGenericType)
{
var genericType = paramType.GenericTypeArguments.First();
return _createRepoDbMapperFactoryMethod.CreateDynamicDelegate(genericType);
}
else if (paramType == typeof(IGraphQLRepoDbMapper))
{
throw new ArgumentException($"The Resolver method signature is expecting a parameter of type [{nameof(IGraphQLRepoDbMapper)}]"
+ " however, a concrete generic type must be specified so that the correct mapping can be resolved;"
+ " use GraphQLRepoDbMapper<TEntity> instead.");
throw new ArgumentException(
$"The Resolver method signature is expecting a parameter of type [{nameof(IGraphQLRepoDbMapper)}]"
+ " however, a concrete generic type must be specified so that the correct mapping can be resolved;"
+ " use GraphQLRepoDbMapper<TEntity> instead."
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public static IRequestExecutorBuilder AddRepoDbExtensions(
{
//Dynamically detect if AddResolverProcessedResultsExtensions() has been called and if not then we call it
// to ensure our dependencies are initialized...
if (!ResolverProcessedResultsMiddlewareExtensions.IsRegistered)
if (!ResolverProcessingMiddlewareExtensions.IsRegistered)
{
builder.AddResolverProcessedResultsExtensions();
builder.AddResolverProcessingExtensions();
}

IsRegistered = true;
Expand Down
25 changes: 13 additions & 12 deletions GraphQL.RepoDb.SqlServer/GraphQLRepoDbMapper/GraphQLRepoDbMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using RepoDb;
using RepoDb.CursorPagination;
using RepoDb.Enumerations;
using RepoDb.OffsetPagination;
using HotChocolate.ResolverProcessingExtensions;
using RepoDb.PagingPrimitives.CursorPaging;
using RepoDb.PagingPrimitives.OffsetPaging;
using RepoDb.SqlServer.PagingOperations;

namespace HotChocolate.RepoDb
{
Expand All @@ -30,7 +31,7 @@ public GraphQLRepoDbMapper(IParamsContext graphQLParams)
/// NOTE: Property names and db fields names are not guaranteed to be the same.
/// </summary>
/// <returns>
/// List of Database fields mapped from all of the available GraphQL Selections mapped to the generics
/// List of Database fields mapped from all the available GraphQL Selections mapped to the generics
/// model type TEntity specified. As a fallback default, all DB Fields are returned if no Selections are available from the
/// GraphQL ParamsContext.
/// </returns>
Expand All @@ -50,7 +51,7 @@ public IEnumerable<Field> GetSelectFieldsFor<TGraphQLEntity>()
/// NOTE: Property names and db fields names are not guaranteed to be the same.
/// </summary>
/// <returns>
/// List of Database fields mapped from all of the available GraphQL Selections mapped to the generics
/// List of Database fields mapped from all the available GraphQL Selections mapped to the generics
/// model type TEntity specified. As a fallback default, all DB Fields are returned if no Selections are available from the
/// GraphQL ParamsContext.
/// </returns>
Expand All @@ -71,7 +72,7 @@ public IEnumerable<Field> GetSelectFields()
/// </summary>
/// <param name="selectionNamesFilter"></param>
/// <returns>
/// List of Database fields mapped from all of the available GraphQL Selections mapped to the generics
/// List of Database fields mapped from all the available GraphQL Selections mapped to the generics
/// model type TEntity specified. As a fallback default, all DB Fields are returned if no Selections are available from the
/// GraphQL ParamsContext.
/// </returns>
Expand All @@ -85,10 +86,10 @@ public IEnumerable<Field> GetSelectFields(IEnumerable<string> selectionNamesFilt
}
else
{
//NOTE: For GraphQL we need to lookup the actual Db field by the Model's Property Name
//NOTE: For GraphQL we need to look up the actual Db field by the Model's Property Name
// and then convert to the actual DB field name; which might also be mapped name via RepoDb attribute.
// For more info see: https://repodb.net/cacher/propertymappednamecache
//TODO: Add Caching Layer here if needed to Cached a Reverse Dictionary of mappings by Model Name!
//TODO: Add Caching Layer here if needed to cache a Reverse Dictionary of mappings by Model Name!
var mappingLookup = PropertyCache.Get<TModel>().ToLookup(p => p.PropertyInfo.Name.ToLower());

var selectFields = selectionNamesFilter
Expand All @@ -115,10 +116,10 @@ public IEnumerable<OrderField> GetSortOrderFields()
return null;

//NOTE: the RepDb PropertyCache provides mapping lookups, but only by mapped name (e.g. Database name)
// for GraphQL (Pure Code First) we need to lookup the field by the Model's Property Name
// for GraphQL (Pure Code First) we need to look up the field by the Model's Property Name
// and then convert to the mapped name. So we create a Lookup by Model Property Name!
// For more info see: https://repodb.net/cacher/propertymappednamecache
//TODO: Add Caching Layer here if needed to Cached a Reverse Dictionary of mappings by Model Name!
//TODO: Add Caching Layer here if needed to cache a Reverse Dictionary of mappings by Model Name!
var mappingLookup = PropertyCache.Get<TModel>().ToLookup(p => p.PropertyInfo.Name.ToLower());

var orderByFields = graphQLSortFields
Expand All @@ -142,7 +143,7 @@ public IEnumerable<OrderField> GetSortOrderFields()
/// Null is returned if the value is undefined and/or invalid and cannot be mapped.
/// The naming convention matches the correct usage along with the [UsePaging] HotChocolate attribute;
/// whereby the default paging method is Cursor based paging.
/// Otherwise use OffsetPagingArgs with the [UseOffsetPaging] attribute.
/// Otherwise, use OffsetPagingArgs with the [UseOffsetPaging] attribute.
/// </summary>
/// <returns></returns>

Expand All @@ -164,7 +165,7 @@ public IRepoDbCursorPagingParams GetCursorPagingParameters()
first: graphQLPagingArgs.First,
beforeCursor: graphQLPagingArgs.Before,
last: graphQLPagingArgs.Last,
isTotalCountRequested: this.GraphQLParamsContext.IsTotalCountRequested
retrieveTotalCount: this.GraphQLParamsContext.IsTotalCountRequested
);
}

Expand All @@ -181,7 +182,7 @@ public RepoDbOffsetPagingParams GetOffsetPagingParameters()
return new RepoDbOffsetPagingParams(
graphQLPagingArgs.Skip,
graphQLPagingArgs.Take,
isTotalCountRequested: this.GraphQLParamsContext.IsTotalCountRequested
retrieveTotalCount: this.GraphQLParamsContext.IsTotalCountRequested
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using HotChocolate.ResolverProcessingExtensions;
using RepoDb;
using RepoDb.CursorPagination;
using RepoDb.OffsetPagination;
using RepoDb.PagingPrimitives.CursorPaging;
using RepoDb.PagingPrimitives.OffsetPaging;

namespace HotChocolate.RepoDb;

Expand Down Expand Up @@ -30,7 +30,7 @@ public interface IGraphQLRepoDbMapper
/// NOTE: Property names and db fields names are not guaranteed to be the same.
/// </summary>
/// <returns>
/// List of Database fields mapped from all of the available GraphQL Selections mapped to the generics
/// List of Database fields mapped from all the available GraphQL Selections mapped to the generics
/// model type TEntity specified. As a fallback default, all DB Fields are returned if no Selections are available from the
/// GraphQL ParamsContext.
/// </returns>
Expand All @@ -44,7 +44,7 @@ public interface IGraphQLRepoDbMapper
/// </summary>
/// <param name="selectionNamesFilter"></param>
/// <returns>
/// List of Database fields mapped from all of the available GraphQL Selections mapped to the generics
/// List of Database fields mapped from all the available GraphQL Selections mapped to the generics
/// model type TEntity specified. As a fallback default, all DB Fields are returned if no Selections are available from the
/// GraphQL ParamsContext.
/// </returns>
Expand All @@ -64,7 +64,7 @@ public interface IGraphQLRepoDbMapper
/// Null is returned if the value is undefined and/or invalid and cannot be mapped.
/// The naming convention matches the correct usage along with the [UsePaging] HotChocolate attribute;
/// whereby the default paging method is Cursor based paging.
/// Otherwise use OffsetPagingArgs with the [UseOffsetPaging] attribute.
/// Otherwise, use OffsetPagingArgs with the [UseOffsetPaging] attribute.
/// </summary>
/// <returns></returns>
IRepoDbCursorPagingParams GetPagingParameters();
Expand Down
Loading

0 comments on commit 3a263e5

Please sign in to comment.