From d9074bee9e2ef0614b43f69969098a648e6c36c6 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 00:09:51 +0000 Subject: [PATCH 01/22] #19 get graphql working via the extension method --- .../Queries/BookQuery.cs | 18 ++ .../Repositories/BookRepository.cs | 11 + .../Repositories/IBookRepository.cs | 5 + .../DataAccess.Example.Web.csproj | 2 + .../DataAccess.Repository.HotChocolate.csproj | 6 +- .../QueryExtensions.cs | 2 +- .../readme.md | 218 +++++++++--------- 7 files changed, 148 insertions(+), 114 deletions(-) diff --git a/Example/DataAccess.Example.Data/Queries/BookQuery.cs b/Example/DataAccess.Example.Data/Queries/BookQuery.cs index 3dc4f83..8e92a6e 100644 --- a/Example/DataAccess.Example.Data/Queries/BookQuery.cs +++ b/Example/DataAccess.Example.Data/Queries/BookQuery.cs @@ -3,6 +3,7 @@ using HotChocolate; using HotChocolate.Types; using HotChocolate.Resolvers; +using HotChocolate.Types.Pagination; namespace DataAccess.Example.Data.Queries; @@ -15,4 +16,21 @@ public class BookQuery { return await repository.GetBookForGraphQuery(context, token); } + + [UseProjection] + [UseFiltering] + [UseSorting] + public async Task?> GetBooks([Service] IBookRepository repository, IResolverContext context, CancellationToken token) + { + return await repository.GetBooksForGraphQuery(context, token); + } + + [UsePaging(IncludeTotalCount = true)] + [UseProjection] + [UseFiltering] + [UseSorting] + public async Task> GetPagedBooks([Service] IBookRepository repository, IResolverContext context, CancellationToken token) + { + return await repository.GetPagedBooksForGraphQuery(context, token); + } } \ No newline at end of file diff --git a/Example/DataAccess.Example.Data/Repositories/BookRepository.cs b/Example/DataAccess.Example.Data/Repositories/BookRepository.cs index 69878ce..cc1a908 100644 --- a/Example/DataAccess.Example.Data/Repositories/BookRepository.cs +++ b/Example/DataAccess.Example.Data/Repositories/BookRepository.cs @@ -3,6 +3,7 @@ using DataAccess.Repository; using DataAccess.Repository.HotChocolate; using HotChocolate.Resolvers; +using HotChocolate.Types.Pagination; namespace DataAccess.Example.Data.Repositories; @@ -62,4 +63,14 @@ public async Task RemoveBook(Guid bookId, CancellationToken token) { return await _bookRepo.GetQueryItem(context, token); } + + public async Task?> GetBooksForGraphQuery(IResolverContext context, CancellationToken token) + { + return await _bookRepo.GetQueryItems(context, token); + } + + public async Task> GetPagedBooksForGraphQuery(IResolverContext context, CancellationToken token) + { + return await _bookRepo.GetPagedQueryItems(context, token); + } } \ No newline at end of file diff --git a/Example/DataAccess.Example.Data/Repositories/IBookRepository.cs b/Example/DataAccess.Example.Data/Repositories/IBookRepository.cs index de5ce4b..38cbc0b 100644 --- a/Example/DataAccess.Example.Data/Repositories/IBookRepository.cs +++ b/Example/DataAccess.Example.Data/Repositories/IBookRepository.cs @@ -1,5 +1,6 @@ using DataAccess.Example.Data.Entities; using HotChocolate.Resolvers; +using HotChocolate.Types.Pagination; namespace DataAccess.Example.Data.Repositories; @@ -16,4 +17,8 @@ public interface IBookRepository Task RemoveBook(Guid bookId, CancellationToken token); Task GetBookForGraphQuery(IResolverContext context, CancellationToken token); + + Task?> GetBooksForGraphQuery(IResolverContext context, CancellationToken token); + + Task> GetPagedBooksForGraphQuery(IResolverContext context, CancellationToken token); } \ No newline at end of file diff --git a/Example/DataAccess.Example.Web/DataAccess.Example.Web.csproj b/Example/DataAccess.Example.Web/DataAccess.Example.Web.csproj index 4dfc130..0e08188 100644 --- a/Example/DataAccess.Example.Web/DataAccess.Example.Web.csproj +++ b/Example/DataAccess.Example.Web/DataAccess.Example.Web.csproj @@ -11,6 +11,8 @@ + + diff --git a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj index cc1e0ac..b05a90d 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj +++ b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj @@ -7,13 +7,11 @@ + - - - - + diff --git a/Extensions/DataAccess.Repository.HotChocolate/QueryExtensions.cs b/Extensions/DataAccess.Repository.HotChocolate/QueryExtensions.cs index 812ad60..62671e8 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/QueryExtensions.cs +++ b/Extensions/DataAccess.Repository.HotChocolate/QueryExtensions.cs @@ -68,8 +68,8 @@ public static async Task> GetPagedQueryItems(this I IResolverContext context, CancellationToken token) where TEntity : class { return await repository.DbSet - .AsQueryable() .AsNoTracking() + .AsQueryable() .Filter(context) .Project(context) .Sort(context) diff --git a/Extensions/DataAccess.Repository.HotChocolate/readme.md b/Extensions/DataAccess.Repository.HotChocolate/readme.md index 0194b20..4b49eb2 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/readme.md +++ b/Extensions/DataAccess.Repository.HotChocolate/readme.md @@ -1,116 +1,116 @@ -# HotChocolate Extension -## Introduction -This extension provides GraphQL query functionality via the [HotChocolate Library](https://chillicream.com/docs/hotchocolate/v13) +# HotChocolate Extension +## Introduction +This extension provides GraphQL query functionality via the [HotChocolate Library](https://chillicream.com/docs/hotchocolate/v13) -## Installation -1. You'll need to install and set up the core data access NuGet package (see instructions [here](https://github.com/Ian-Webster/DataAccess#usage)) -2. Add the following NuGet packages to your IoC project; - 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) - 2. [HotChocolate.AspNetCore](https://www.nuget.org/packages/HotChocolate.AspNetCore/13.7.0?_src=template) - 3. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) -3. Add the following NuGet packages to your Repository project; - 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) - 2. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) - 3. TBC- this extension -4. Modify your IoC services to add and configure HotChocolate; - ```csharp - // set up HotChocolate - builder.Services.AddGraphQLServer() - .AddQueryType(q => q.Name("Query")) - .AddProjections() - .AddFiltering() - .AddSorting(); - ``` - 5.Modify your middleware configuration to include `app.MapGraphQL();` - 6. We'll revisit your IoC configuration later to add queries. +## Installation +1. You'll need to install and set up the core data access NuGet package (see instructions [here](https://github.com/Ian-Webster/DataAccess#usage)) +2. Add the following NuGet packages to your IoC project; + 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) + 2. [HotChocolate.AspNetCore](https://www.nuget.org/packages/HotChocolate.AspNetCore/13.7.0?_src=template) + 3. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) +3. Add the following NuGet packages to your Repository project; + 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) + 2. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) + 3. TBC- this extension +4. Modify your IoC services to add and configure HotChocolate; + ```csharp + // set up HotChocolate + builder.Services.AddGraphQLServer() + .AddQueryType(q => q.Name("Query")) + .AddProjections() + .AddFiltering() + .AddSorting(); + ``` + 5.Modify your middleware configuration to include `app.MapGraphQL();` + 6. We'll revisit your IoC configuration later to add queries. -## Building queries -Queries in GraphQL are like a stand-in for controller endpoints in REST, they provide a public API into your data, you can read more here https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/queries +## Building queries +Queries in GraphQL are like a stand-in for controller endpoints in REST, they provide a public API into your data, you can read more here https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/queries -HotChocolate can query your DBContext directly should you wish, however it does also provide a number of IQueryable extension methods and a query context class that allow you to use your own services and repository methods to perform the data operations. +HotChocolate can query your DBContext directly should you wish, however it does also provide a number of IQueryable extension methods and a query context class that allow you to use your own services and repository methods to perform the data operations. -The purpose of this extension library to obfuscate the complexities involved in modifying repository methods to support the HotChocolate extensions by providing a number of extension methods in the QueryExtensions; -* GetQueryItem - returns a single entity, supports filtering and projection -* GetQueryItems - returns a collection of entities, supports filtering, projection and sorting -* GetPagedQueryItems - returns a [Connection](https://chillicream.com/docs/hotchocolate/v13/fetching-data/pagination/#connections) object provided by the HotChocolate library, supports filtering, projection, sorting and pagination +The purpose of this extension library to obfuscate the complexities involved in modifying repository methods to support the HotChocolate extensions by providing a number of extension methods in the QueryExtensions; +* GetQueryItem - returns a single entity, supports filtering and projection +* GetQueryItems - returns a collection of entities, supports filtering, projection and sorting +* GetPagedQueryItems - returns a [Connection](https://chillicream.com/docs/hotchocolate/v13/fetching-data/pagination/#connections) object provided by the HotChocolate library, supports filtering, projection, sorting and pagination -Usage for this extension is as follows; -1. Modify your repository to accept IResolverContext and to call the extension, as an example this is how to get a single book entity for GraphQL; - ```csharp - // interface - using HotChocolate.Resolvers; // namespace for IResolverContext - namespace DataAccess.Example.Data.Repositories; - - public interface IBookRepository - { - Task GetBookForGraphQuery(IResolverContext context, CancellationToken token); - } +Usage for this extension is as follows; +1. Modify your repository to accept IResolverContext and to call the extension, as an example this is how to get a single book entity for GraphQL; + ```csharp + // interface + using HotChocolate.Resolvers; // namespace for IResolverContext + namespace DataAccess.Example.Data.Repositories; + + public interface IBookRepository + { + Task GetBookForGraphQuery(IResolverContext context, CancellationToken token); + } - // implementation - using DataAccess.Repository.HotChocolate; // namespace for this extension - using HotChocolate.Resolvers; // namespace for IResolverContext - - namespace DataAccess.Example.Data.Repositories; - - public class BookRepository: IBookRepository - { - private readonly IRepository _bookRepo; - - public BookRepository(RepositoryFactory repositoryFactory) - { - _bookRepo = repositoryFactory.GetRepositoryByType(); - } - - public async Task GetBookForGraphQuery(IResolverContext context, CancellationToken token) - { - return await _bookRepo.GetQueryItem(context, token); - } - } - ``` -2. Create a query class here is the book query; - ```csharp - using HotChocolate; - using HotChocolate.Types; - using HotChocolate.Resolvers; - - namespace DataAccess.Example.Data.Queries; - - [ExtendObjectType("Query")] - public class BookQuery - { - [UseProjection] // enable projecton for this query - [UseFiltering] // enable filtering for this query - // [Service] is an attribute hint provided by the HotChocolate library - // telling the code to use DI to retrieve the IBookRepository dependency - // IResolverContext and CancellationToken objects are provide as part of the - // GraphQL context - public async Task GetBook([Service] IBookRepository repository, IResolverContext context, CancellationToken token) - { - return await repository.GetBookForGraphQuery(context, token); - } - } - ``` -3. Modify the HotChocolate IoC configuration you added earlier to include your query; - ```csharp - // set up HotChocolate - builder.Services.AddGraphQLServer() - .AddQueryType(q => q.Name("Query")) - .AddTypeExtension() // adding the book query type - .AddProjections() - .AddFiltering() - .AddSorting(); - ``` -4. Run the API project as normal, you should be able to visit /graphql and see the [Banana Cake Pop](https://chillicream.com/products/bananacakepop/) UX -5. Run a query through the UX, as an example this will return the book "Fight Club" from the example project; - ```json - { - book (where: {bookId: {eq: "2c4a20f5-3fc8-4694-9c03-cb444bf416dc"}}) - { - bookId, - name - } - } - ``` + // implementation + using DataAccess.Repository.HotChocolate; // namespace for this extension + using HotChocolate.Resolvers; // namespace for IResolverContext + + namespace DataAccess.Example.Data.Repositories; + + public class BookRepository: IBookRepository + { + private readonly IRepository _bookRepo; + + public BookRepository(RepositoryFactory repositoryFactory) + { + _bookRepo = repositoryFactory.GetRepositoryByType(); + } + + public async Task GetBookForGraphQuery(IResolverContext context, CancellationToken token) + { + return await _bookRepo.GetQueryItem(context, token); + } + } + ``` +2. Create a query class here is the book query; + ```csharp + using HotChocolate; + using HotChocolate.Types; + using HotChocolate.Resolvers; + + namespace DataAccess.Example.Data.Queries; + + [ExtendObjectType("Query")] + public class BookQuery + { + [UseProjection] // enable projecton for this query + [UseFiltering] // enable filtering for this query + // [Service] is an attribute hint provided by the HotChocolate library + // telling the code to use DI to retrieve the IBookRepository dependency + // IResolverContext and CancellationToken objects are provide as part of the + // GraphQL context + public async Task GetBook([Service] IBookRepository repository, IResolverContext context, CancellationToken token) + { + return await repository.GetBookForGraphQuery(context, token); + } + } + ``` +3. Modify the HotChocolate IoC configuration you added earlier to include your query; + ```csharp + // set up HotChocolate + builder.Services.AddGraphQLServer() + .AddQueryType(q => q.Name("Query")) + .AddTypeExtension() // adding the book query type + .AddProjections() + .AddFiltering() + .AddSorting(); + ``` +4. Run the API project as normal, you should be able to visit /graphql and see the [Banana Cake Pop](https://chillicream.com/products/bananacakepop/) UX +5. Run a query through the UX, as an example this will return the book "Fight Club" from the example project; + ```json + { + book (where: {bookId: {eq: "2c4a20f5-3fc8-4694-9c03-cb444bf416dc"}}) + { + bookId, + name + } + } + ``` -## Version history -* 0.1.0 - Initial project creation, getting everything figured out and running locally +## Version history +* 0.1.0 - Initial project creation, getting everything figured out and running locally From e4dabe593a96bc2bfe46626d0ca5518628af7e19 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 00:14:01 +0000 Subject: [PATCH 02/22] #19 add local nuget repo to branch build action --- .github/workflows/branch.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml index 2ae4ebf..a78107a 100644 --- a/.github/workflows/branch.yml +++ b/.github/workflows/branch.yml @@ -19,6 +19,14 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: 7.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + # Resource NuGet dependencies + - name: Restore dependencies + run: dotnet restore # Build project - name: Build From 7f75221c5474b8cc44c95250c5b7ec2f8c4cb13a Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 21:30:35 +0000 Subject: [PATCH 03/22] #19 set up NuGet for extension + new build yaml --- .github/workflows/build.yml | 40 ++++ .../DataAccess.Repository.csproj | 2 +- .../DataAccess.Repository.HotChocolate.csproj | 7 + .../readme.md | 219 +++++++++--------- 4 files changed, 158 insertions(+), 110 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..6b01847 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,40 @@ +name: Build Action + +on: + push: + paths: + - 'DataAccess/DataAccess.Repository/**' + - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' + +jobs: + + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + project: ['DataAccess.Repository', 'DataAccess.Repository.HotChocolate'] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + # Resource NuGet dependencies + - name: Restore dependencies + run: dotnet restore 'DataAccess/${{ matrix.project }}' + + # Build project + - name: Build + run: dotnet build --configuration Release 'DataAccess/${{ matrix.project }}' + diff --git a/DataAccess.Repository/DataAccess.Repository.csproj b/DataAccess.Repository/DataAccess.Repository.csproj index 43e7526..a3de38b 100644 --- a/DataAccess.Repository/DataAccess.Repository.csproj +++ b/DataAccess.Repository/DataAccess.Repository.csproj @@ -9,7 +9,7 @@ A simple base repository to be used in other projects requiring data access https://github.com/Ian-Webster/DataAccess https://github.com/Ian-Webster/DataAccess - 2.0.0-wip + 2.0.1 diff --git a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj index b05a90d..9d2a8c9 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj +++ b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj @@ -4,6 +4,13 @@ net8.0 enable enable + True + DataAccess.HotChocolate + Extension to the DataAccess package adding GraphQL functionality via the HotChocolate library + https://github.com/Ian-Webster/DataAccess/Extensions/DataAccess.Repository.HotChocolate + https://github.com/Ian-Webster/DataAccess + 0.1.0 + diff --git a/Extensions/DataAccess.Repository.HotChocolate/readme.md b/Extensions/DataAccess.Repository.HotChocolate/readme.md index 4b49eb2..9995479 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/readme.md +++ b/Extensions/DataAccess.Repository.HotChocolate/readme.md @@ -1,116 +1,117 @@ -# HotChocolate Extension -## Introduction -This extension provides GraphQL query functionality via the [HotChocolate Library](https://chillicream.com/docs/hotchocolate/v13) +# HotChocolate Extension +## Introduction +This extension provides GraphQL query functionality via the [HotChocolate Library](https://chillicream.com/docs/hotchocolate/v13) -## Installation -1. You'll need to install and set up the core data access NuGet package (see instructions [here](https://github.com/Ian-Webster/DataAccess#usage)) -2. Add the following NuGet packages to your IoC project; - 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) - 2. [HotChocolate.AspNetCore](https://www.nuget.org/packages/HotChocolate.AspNetCore/13.7.0?_src=template) - 3. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) -3. Add the following NuGet packages to your Repository project; - 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) - 2. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) - 3. TBC- this extension -4. Modify your IoC services to add and configure HotChocolate; - ```csharp - // set up HotChocolate - builder.Services.AddGraphQLServer() - .AddQueryType(q => q.Name("Query")) - .AddProjections() - .AddFiltering() - .AddSorting(); - ``` - 5.Modify your middleware configuration to include `app.MapGraphQL();` - 6. We'll revisit your IoC configuration later to add queries. +## Installation +1. You'll need to install and set up the core data access NuGet package (see instructions [here](https://github.com/Ian-Webster/DataAccess#usage)) +2. Add the following NuGet packages to your IoC project; + 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) + 2. [HotChocolate.AspNetCore](https://www.nuget.org/packages/HotChocolate.AspNetCore/13.7.0?_src=template) + 3. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) +3. Add the following NuGet packages to your Repository project; + 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) + 2. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) + 3. TBC- this extension +4. Modify your IoC services to add and configure HotChocolate; + ```csharp + // set up HotChocolate + builder.Services.AddGraphQLServer() + .AddQueryType(q => q.Name("Query")) + .AddProjections() + .AddFiltering() + .AddSorting(); + ``` + 5.Modify your middleware configuration to include `app.MapGraphQL();` + 6. We'll revisit your IoC configuration later to add queries. -## Building queries -Queries in GraphQL are like a stand-in for controller endpoints in REST, they provide a public API into your data, you can read more here https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/queries +## Building queries +Queries in GraphQL are like a stand-in for controller endpoints in REST, they provide a public API into your data, you can read more here https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/queries -HotChocolate can query your DBContext directly should you wish, however it does also provide a number of IQueryable extension methods and a query context class that allow you to use your own services and repository methods to perform the data operations. +HotChocolate can query your DBContext directly should you wish, however it does also provide a number of IQueryable extension methods and a query context class that allow you to use your own services and repository methods to perform the data operations. -The purpose of this extension library to obfuscate the complexities involved in modifying repository methods to support the HotChocolate extensions by providing a number of extension methods in the QueryExtensions; -* GetQueryItem - returns a single entity, supports filtering and projection -* GetQueryItems - returns a collection of entities, supports filtering, projection and sorting -* GetPagedQueryItems - returns a [Connection](https://chillicream.com/docs/hotchocolate/v13/fetching-data/pagination/#connections) object provided by the HotChocolate library, supports filtering, projection, sorting and pagination +The purpose of this extension library to obfuscate the complexities involved in modifying repository methods to support the HotChocolate extensions by providing a number of extension methods in the QueryExtensions; +* GetQueryItem - returns a single entity, supports filtering and projection +* GetQueryItems - returns a collection of entities, supports filtering, projection and sorting +* GetPagedQueryItems - returns a [Connection](https://chillicream.com/docs/hotchocolate/v13/fetching-data/pagination/#connections) object provided by the HotChocolate library, supports filtering, projection, sorting and pagination -Usage for this extension is as follows; -1. Modify your repository to accept IResolverContext and to call the extension, as an example this is how to get a single book entity for GraphQL; - ```csharp - // interface - using HotChocolate.Resolvers; // namespace for IResolverContext - namespace DataAccess.Example.Data.Repositories; - - public interface IBookRepository - { - Task GetBookForGraphQuery(IResolverContext context, CancellationToken token); - } +Usage for this extension is as follows; +1. Modify your repository to accept IResolverContext and to call the extension, as an example this is how to get a single book entity for GraphQL; + ```csharp + // interface + using HotChocolate.Resolvers; // namespace for IResolverContext + namespace DataAccess.Example.Data.Repositories; + + public interface IBookRepository + { + Task GetBookForGraphQuery(IResolverContext context, CancellationToken token); + } - // implementation - using DataAccess.Repository.HotChocolate; // namespace for this extension - using HotChocolate.Resolvers; // namespace for IResolverContext - - namespace DataAccess.Example.Data.Repositories; - - public class BookRepository: IBookRepository - { - private readonly IRepository _bookRepo; - - public BookRepository(RepositoryFactory repositoryFactory) - { - _bookRepo = repositoryFactory.GetRepositoryByType(); - } - - public async Task GetBookForGraphQuery(IResolverContext context, CancellationToken token) - { - return await _bookRepo.GetQueryItem(context, token); - } - } - ``` -2. Create a query class here is the book query; - ```csharp - using HotChocolate; - using HotChocolate.Types; - using HotChocolate.Resolvers; - - namespace DataAccess.Example.Data.Queries; - - [ExtendObjectType("Query")] - public class BookQuery - { - [UseProjection] // enable projecton for this query - [UseFiltering] // enable filtering for this query - // [Service] is an attribute hint provided by the HotChocolate library - // telling the code to use DI to retrieve the IBookRepository dependency - // IResolverContext and CancellationToken objects are provide as part of the - // GraphQL context - public async Task GetBook([Service] IBookRepository repository, IResolverContext context, CancellationToken token) - { - return await repository.GetBookForGraphQuery(context, token); - } - } - ``` -3. Modify the HotChocolate IoC configuration you added earlier to include your query; - ```csharp - // set up HotChocolate - builder.Services.AddGraphQLServer() - .AddQueryType(q => q.Name("Query")) - .AddTypeExtension() // adding the book query type - .AddProjections() - .AddFiltering() - .AddSorting(); - ``` -4. Run the API project as normal, you should be able to visit /graphql and see the [Banana Cake Pop](https://chillicream.com/products/bananacakepop/) UX -5. Run a query through the UX, as an example this will return the book "Fight Club" from the example project; - ```json - { - book (where: {bookId: {eq: "2c4a20f5-3fc8-4694-9c03-cb444bf416dc"}}) - { - bookId, - name - } - } - ``` + // implementation + using DataAccess.Repository.HotChocolate; // namespace for this extension + using HotChocolate.Resolvers; // namespace for IResolverContext + + namespace DataAccess.Example.Data.Repositories; + + public class BookRepository: IBookRepository + { + private readonly IRepository _bookRepo; + + public BookRepository(RepositoryFactory repositoryFactory) + { + _bookRepo = repositoryFactory.GetRepositoryByType(); + } + + public async Task GetBookForGraphQuery(IResolverContext context, CancellationToken token) + { + return await _bookRepo.GetQueryItem(context, token); + } + } + ``` +2. Create a query class here is the book query; + ```csharp + using HotChocolate; + using HotChocolate.Types; + using HotChocolate.Resolvers; + + namespace DataAccess.Example.Data.Queries; + + [ExtendObjectType("Query")] + public class BookQuery + { + [UseProjection] // enable projecton for this query + [UseFiltering] // enable filtering for this query + // [Service] is an attribute hint provided by the HotChocolate library + // telling the code to use DI to retrieve the IBookRepository dependency + // IResolverContext and CancellationToken objects are provide as part of the + // GraphQL context + public async Task GetBook([Service] IBookRepository repository, IResolverContext context, CancellationToken token) + { + return await repository.GetBookForGraphQuery(context, token); + } + } + ``` +3. Modify the HotChocolate IoC configuration you added earlier to include your query; + ```csharp + // set up HotChocolate + builder.Services.AddGraphQLServer() + .AddQueryType(q => q.Name("Query")) + .AddTypeExtension() // adding the book query type + .AddProjections() + .AddFiltering() + .AddSorting(); + ``` +4. Run the API project as normal, you should be able to visit /graphql and see the [Banana Cake Pop](https://chillicream.com/products/bananacakepop/) UX +5. Run a query through the UX, as an example this will return the book "Fight Club" from the example project; + ```json + { + book (where: {bookId: {eq: "2c4a20f5-3fc8-4694-9c03-cb444bf416dc"}}) + { + bookId, + name + } + } + ``` -## Version history -* 0.1.0 - Initial project creation, getting everything figured out and running locally +## Version history +* 1.0.0 - Initial release +* 0.1.0 - Initial project creation, getting everything figured out and running locally From c71b34a6873ee8dfc60191db084e3cde9b301aed Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 21:33:09 +0000 Subject: [PATCH 04/22] #19 disable old branch action yaml --- .github/workflows/{branch.yml => branch.yml.bak} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{branch.yml => branch.yml.bak} (100%) diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml.bak similarity index 100% rename from .github/workflows/branch.yml rename to .github/workflows/branch.yml.bak From ae1ce84e6d07b7828e80c562df7be187e51145ba Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 21:38:43 +0000 Subject: [PATCH 05/22] #19 test yaml --- .github/workflows/build.yml | 39 ++++++------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b01847..f6cfbc1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,36 +5,9 @@ on: paths: - 'DataAccess/DataAccess.Repository/**' - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' - -jobs: - - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - project: ['DataAccess.Repository', 'DataAccess.Repository.HotChocolate'] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - # Install the .NET Core workload - - name: Install .NET Core - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x - - # Set up local NuGet repo - - name: Setup GitHub NuGet - run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" - - # Resource NuGet dependencies - - name: Restore dependencies - run: dotnet restore 'DataAccess/${{ matrix.project }}' - - # Build project - - name: Build - run: dotnet build --configuration Release 'DataAccess/${{ matrix.project }}' - + jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Debug + run: echo "Hello, debugging!" \ No newline at end of file From 0a7dcdf4e0b4f7a7347237f2d632eff562d5054b Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 21:39:38 +0000 Subject: [PATCH 06/22] #19 restore back new yaml --- .github/workflows/build.yml | 38 +++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f6cfbc1..4054ab7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,9 +5,35 @@ on: paths: - 'DataAccess/DataAccess.Repository/**' - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' - jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Debug - run: echo "Hello, debugging!" \ No newline at end of file + +jobs: + + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + project: ['DataAccess.Repository', 'DataAccess.Repository.HotChocolate'] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + # Resource NuGet dependencies + - name: Restore dependencies + run: dotnet restore 'DataAccess/${{ matrix.project }}' + + # Build project + - name: Build + run: dotnet build --configuration Release 'DataAccess/${{ matrix.project }}' \ No newline at end of file From d3d193331baba6fa3172bb118b314da367e53cf5 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 21:44:50 +0000 Subject: [PATCH 07/22] #19 yaml testing --- .github/workflows/build.yml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4054ab7..a7791a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,6 @@ -name: Build Action +name: Build actions -on: - push: - paths: - - 'DataAccess/DataAccess.Repository/**' - - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' +on: push jobs: @@ -12,19 +8,17 @@ jobs: runs-on: ubuntu-latest - strategy: - matrix: - project: ['DataAccess.Repository', 'DataAccess.Repository.HotChocolate'] - steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 # Install the .NET Core workload - name: Install .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x + dotnet-version: 7.0.x # Set up local NuGet repo - name: Setup GitHub NuGet @@ -32,8 +26,13 @@ jobs: # Resource NuGet dependencies - name: Restore dependencies - run: dotnet restore 'DataAccess/${{ matrix.project }}' + run: dotnet restore # Build project - name: Build - run: dotnet build --configuration Release 'DataAccess/${{ matrix.project }}' \ No newline at end of file + run: dotnet build --configuration Release + + # Execute all unit tests in the solution + - name: Execute unit tests + run: dotnet test + From 98a87bf4130e5f697558384be794fa0afeadb666 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 21:47:53 +0000 Subject: [PATCH 08/22] #19 add paths --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a7791a9..fbd855e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,10 @@ name: Build actions -on: push +on: + push: + paths: + - 'DataAccess/DataAccess.Repository/**' + - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' jobs: From 43545ab6a6c12bec9dc6cf20be73dd87d12663fc Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 21:49:11 +0000 Subject: [PATCH 09/22] #19 different paths --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbd855e..ef359a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,8 +3,8 @@ name: Build actions on: push: paths: - - 'DataAccess/DataAccess.Repository/**' - - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' + - 'DataAccess.Repository/**' + - 'Extensions/DataAccess.Repository.HotChocolate/**' jobs: From 61db46f1f5c01cf5c5c51ee30671729d6a46f4fc Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 22:04:23 +0000 Subject: [PATCH 10/22] #19 revert yaml + bump version --- .github/workflows/build.yml | 23 ++++++++----------- .../DataAccess.Repository.HotChocolate.csproj | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef359a9..4054ab7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,10 @@ -name: Build actions +name: Build Action on: push: paths: - - 'DataAccess.Repository/**' - - 'Extensions/DataAccess.Repository.HotChocolate/**' + - 'DataAccess/DataAccess.Repository/**' + - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' jobs: @@ -12,17 +12,19 @@ jobs: runs-on: ubuntu-latest + strategy: + matrix: + project: ['DataAccess.Repository', 'DataAccess.Repository.HotChocolate'] + steps: - name: Checkout uses: actions/checkout@v3 - with: - fetch-depth: 0 # Install the .NET Core workload - name: Install .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x # Set up local NuGet repo - name: Setup GitHub NuGet @@ -30,13 +32,8 @@ jobs: # Resource NuGet dependencies - name: Restore dependencies - run: dotnet restore + run: dotnet restore 'DataAccess/${{ matrix.project }}' # Build project - name: Build - run: dotnet build --configuration Release - - # Execute all unit tests in the solution - - name: Execute unit tests - run: dotnet test - + run: dotnet build --configuration Release 'DataAccess/${{ matrix.project }}' \ No newline at end of file diff --git a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj index 9d2a8c9..0c5ace1 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj +++ b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj @@ -9,7 +9,7 @@ Extension to the DataAccess package adding GraphQL functionality via the HotChocolate library https://github.com/Ian-Webster/DataAccess/Extensions/DataAccess.Repository.HotChocolate https://github.com/Ian-Webster/DataAccess - 0.1.0 + 0.2.0 From 3960e059ff53f5050b06615f35eab69a34071f90 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 22:07:44 +0000 Subject: [PATCH 11/22] #19 debug yaml --- .github/workflows/build.yml | 47 ++++++++++--------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4054ab7..8bd20e4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,39 +1,16 @@ -name: Build Action - on: push: paths: - - 'DataAccess/DataAccess.Repository/**' - - 'DataAccess/Extensions/DataAccess.Repository.HotChocolate/**' - + - 'DataAccess.Repository/**' + - 'Extensions/DataAccess.Repository.HotChocolate/**' jobs: - - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - project: ['DataAccess.Repository', 'DataAccess.Repository.HotChocolate'] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - # Install the .NET Core workload - - name: Install .NET Core - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x - - # Set up local NuGet repo - - name: Setup GitHub NuGet - run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" - - # Resource NuGet dependencies - - name: Restore dependencies - run: dotnet restore 'DataAccess/${{ matrix.project }}' - - # Build project - - name: Build - run: dotnet build --configuration Release 'DataAccess/${{ matrix.project }}' \ No newline at end of file + debug: + runs-on: ubuntu-latest + steps: + - name: Debug Paths + run: | + echo "Files in repository:" + ls -R + echo "Changed files in this push:" + git diff --name-only ${{ github.event.before }} ${{ github.sha }} + \ No newline at end of file From 11aad7c6e03515a81cd72860ebdb167a913ca0e6 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 22:20:28 +0000 Subject: [PATCH 12/22] #19 more path stuff --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8bd20e4..6a67943 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,8 +1,8 @@ on: push: paths: - - 'DataAccess.Repository/**' - - 'Extensions/DataAccess.Repository.HotChocolate/**' + - 'DataAccess.Repository/' + - 'Extensions/DataAccess.Repository.HotChocolate/' jobs: debug: runs-on: ubuntu-latest From f842716638228c26cd038b6d2a8b7d6d47b9fbc1 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 22:51:55 +0000 Subject: [PATCH 13/22] #19 another go at making the yaml work --- .github/workflows/build.yml | 52 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a67943..103de5a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,16 +1,38 @@ -on: - push: - paths: - - 'DataAccess.Repository/' - - 'Extensions/DataAccess.Repository.HotChocolate/' +name: Branch actions + +on: push + jobs: - debug: - runs-on: ubuntu-latest - steps: - - name: Debug Paths - run: | - echo "Files in repository:" - ls -R - echo "Changed files in this push:" - git diff --name-only ${{ github.event.before }} ${{ github.sha }} - \ No newline at end of file + + build_DataAccess: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + # Resource NuGet dependencies + - name: Restore dependencies + run: dotnet restore 'DataAccess.Repository' + + # Build project + - name: Build + run: dotnet build --configuration Release 'DataAccess.Repository' + + # Execute all unit tests in the solution + - name: Execute unit tests + run: dotnet test + From 42ebbc5de082e0ef66098922977322ca33759067 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 22:56:22 +0000 Subject: [PATCH 14/22] #19 add HotChocolate to the yaml --- .github/workflows/build.yml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 103de5a..7684463 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,7 +32,30 @@ jobs: - name: Build run: dotnet build --configuration Release 'DataAccess.Repository' - # Execute all unit tests in the solution - - name: Execute unit tests - run: dotnet test + build_HotChococlateExtension: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + # Resource NuGet dependencies + - name: Restore dependencies + run: dotnet restore 'Extensions/DataAccess.Repository.HotChocolate' + + # Build project + - name: Build + run: dotnet build --configuration Release 'Extensions/DataAccess.Repository.HotChocolate' \ No newline at end of file From a87916796c02b6caaae7bcf635a4989e5e1b08d8 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 23:12:49 +0000 Subject: [PATCH 15/22] #19 conditional build code --- .github/workflows/build.yml | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7684463..2d2c85a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,13 +24,15 @@ jobs: - name: Setup GitHub NuGet run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" - # Resource NuGet dependencies - - name: Restore dependencies - run: dotnet restore 'DataAccess.Repository' - - # Build project - - name: Build - run: dotnet build --configuration Release 'DataAccess.Repository' + - name: Check for Changes in Repository Project + run: | + if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'DataAccess.Repository/') ]]; then + echo "Changes detected in DataAccess.Repository project. Restoring packages and running build..." + dotnet restore 'DataAccess.Repository' + dotnet build --configuration Release 'DataAccess.Repository' + else + echo "No changes in DataAccess.Repository project. Skipping build." + fi build_HotChococlateExtension: @@ -52,10 +54,12 @@ jobs: - name: Setup GitHub NuGet run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" - # Resource NuGet dependencies - - name: Restore dependencies - run: dotnet restore 'Extensions/DataAccess.Repository.HotChocolate' - - # Build project - - name: Build - run: dotnet build --configuration Release 'Extensions/DataAccess.Repository.HotChocolate' \ No newline at end of file + - name: Check for Changes in HotChocolate Project + run: | + if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'Extensions/DataAccess.Repository.HotChocolate/') ]]; then + echo "Changes detected in Extensions/DataAccess.Repository.HotChocolate project. Restoring packages and running build..." + dotnet restore 'xtensions/DataAccess.Repository.HotChocolate' + dotnet build --configuration Release 'Extensions/DataAccess.Repository.HotChocolate' + else + echo "No changes in Extensions/DataAccess.Repository.HotChocolate project. Skipping build." + fi \ No newline at end of file From e6e7f86d7a9b3309650e2446da79b76258e55323 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 23:14:14 +0000 Subject: [PATCH 16/22] #19 version bump to trigger conditional build --- .../DataAccess.Repository.HotChocolate.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj index 0c5ace1..e933f0d 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj +++ b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj @@ -9,7 +9,7 @@ Extension to the DataAccess package adding GraphQL functionality via the HotChocolate library https://github.com/Ian-Webster/DataAccess/Extensions/DataAccess.Repository.HotChocolate https://github.com/Ian-Webster/DataAccess - 0.2.0 + 0.3.0 From 226f60ffc905ee00e05bb73ca891059395d7a6cd Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 23:15:54 +0000 Subject: [PATCH 17/22] #19 yaml fix + another version bump --- .github/workflows/build.yml | 2 +- .../DataAccess.Repository.HotChocolate.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2d2c85a..b18a6f6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,7 +58,7 @@ jobs: run: | if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'Extensions/DataAccess.Repository.HotChocolate/') ]]; then echo "Changes detected in Extensions/DataAccess.Repository.HotChocolate project. Restoring packages and running build..." - dotnet restore 'xtensions/DataAccess.Repository.HotChocolate' + dotnet restore 'Extensions/DataAccess.Repository.HotChocolate' dotnet build --configuration Release 'Extensions/DataAccess.Repository.HotChocolate' else echo "No changes in Extensions/DataAccess.Repository.HotChocolate project. Skipping build." diff --git a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj index e933f0d..e9b40c1 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj +++ b/Extensions/DataAccess.Repository.HotChocolate/DataAccess.Repository.HotChocolate.csproj @@ -9,7 +9,7 @@ Extension to the DataAccess package adding GraphQL functionality via the HotChocolate library https://github.com/Ian-Webster/DataAccess/Extensions/DataAccess.Repository.HotChocolate https://github.com/Ian-Webster/DataAccess - 0.3.0 + 0.3.1 From 3652ec6613e1f401077ea2e2a84ed0dd5a53fd37 Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 23:23:36 +0000 Subject: [PATCH 18/22] #19 version bump read me changes + test.yml --- .github/workflows/test.yml | 36 +++ .../DataAccess.Repository.csproj | 2 +- .../readme.md | 2 +- README.md | 248 +++++++++--------- 4 files changed, 162 insertions(+), 126 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..715561f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Branch actions + +on: push + +jobs: + + test_DataAccess: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + - name: Check for Changes in Repository Project + run: | + if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'DataAccess.Repository/') ]]; then + echo "Changes detected in DataAccess.Repository project. Restoring packages, running build and testing..." + dotnet restore 'DataAccess.Repository' + dotnet build --configuration Release 'DataAccess.Repository' + dotnet test DataAccess.Repository' + else + echo "No changes in DataAccess.Repository project. Skipping build." + fi \ No newline at end of file diff --git a/DataAccess.Repository/DataAccess.Repository.csproj b/DataAccess.Repository/DataAccess.Repository.csproj index a3de38b..fc90e49 100644 --- a/DataAccess.Repository/DataAccess.Repository.csproj +++ b/DataAccess.Repository/DataAccess.Repository.csproj @@ -9,7 +9,7 @@ A simple base repository to be used in other projects requiring data access https://github.com/Ian-Webster/DataAccess https://github.com/Ian-Webster/DataAccess - 2.0.1 + 2.0.2 diff --git a/Extensions/DataAccess.Repository.HotChocolate/readme.md b/Extensions/DataAccess.Repository.HotChocolate/readme.md index 9995479..17079ff 100644 --- a/Extensions/DataAccess.Repository.HotChocolate/readme.md +++ b/Extensions/DataAccess.Repository.HotChocolate/readme.md @@ -11,7 +11,7 @@ This extension provides GraphQL query functionality via the [HotChocolate Librar 3. Add the following NuGet packages to your Repository project; 1. [HotChocolate](https://www.nuget.org/packages/HotChocolate/13.7.0?_src=template) 2. [HotChocolate.Data](https://www.nuget.org/packages/HotChocolate.Data/13.7.0?_src=template) - 3. TBC- this extension + 3. [DataAccess.Repository](https://github.com/Ian-Webster/DataAccess/pkgs/nuget/DataAccess.Repository) 4. Modify your IoC services to add and configure HotChocolate; ```csharp // set up HotChocolate diff --git a/README.md b/README.md index c254857..67d2339 100644 --- a/README.md +++ b/README.md @@ -1,124 +1,124 @@ -# DataAccess - -## Introduction - -A simple data access base repository that can be used in other projects - -## Usage - -Full example project can be found here https://github.com/Ian-Webster/sandbox/tree/main/nuget-samples/DataAccess.Sample - -### Install NuGet packages - -Install the following NuGet packges into your project -1. [DataAccess.Repository](https://github.com/Ian-Webster/DataAccess/pkgs/nuget/DataAccess.Repository) -2. [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/7.0.0) -3. [Microsoft.EntityFrameworkCore.Relational](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Relational/7.0.0) -4. Your choice of EF core database targeting package (for example https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer) - -### Create entites and entity type configurations - -1. Create your database entity classes, as an example a movie entity; - ```csharp - public class Movie - { - public Guid MovieId { get; set; } - public string Name { get; set; } - } - ``` -2. Create your entity type configuration classes, as an example an entity type configuration for the movie entity; - ```csharp - public class MovieEntityTypeConfiguration: IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.HasKey(pk => pk.MovieId); - builder.ToTable(nameof(Movie), SchemaNames.Public); - } - } - ``` - -### Create a database context class - -You will need to create a database context class that inherits from [DbContext](https://learn.microsoft.com/en-us/dotnet/api/system.data.entity.dbcontext?view=entity-framework-6.2.0) - -As an example here is the database context class for the Movie database; - -```csharp -public class MovieContext: DbContext // inherit from DbContext -{ - // inject DbContextOptions and base to the base class - public MovieContext(DbContextOptions options): base(options) - { - } - - // override OnModelCreating so we can apply our entity type configurations - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - // get the the assembly your EntityTypeConfigurations are in - // in this case they are in the same assembly as this context class - var assembly = Assembly.GetAssembly(typeof(MovieContext)); - if (assembly == null) - { - throw new Exception($"Failed to get assembly for {nameof(MovieContext)}"); - } - modelBuilder.ApplyConfigurationsFromAssembly(assembly); - } -} -``` - -### Create repository classes - -As an example the repository class for the movie entity; - -```csharp -using DataAccess.Repository; -using DataAccess.Sample.Data.DatabaseContexts; -using DataAccess.Sample.Domain.Entities; - -public class MovieRepository: IMovieRepository -{ - private readonly IRepository _movieRepository; - // inject RepositoryFactory for creating IRepository instances - public MovieRepository(RepositoryFactory repositoryFactory) - { - // create an instance of IRepository for our entity (Movie) - _movieRepository = repositoryFactory.GetRepositoryByType(); - } - - public async Task GetMovieById(Guid movieId, CancellationToken token) - { - // perform a database read for the Movie entity - return await _movieRepository.FirstOrDefault(m => m.MovieId == movieId, token); - } -} -``` - -### Configure IoC - -In your IoC bootstrapping you need to; -1. Add your database context, as an example here is the set up for the MovieContext connecting to a postgres database; - ```csharp - builder.Services.AddDbContext(options => - { - options.UseNpgsql(builder.Configuration.GetConnectionString("PostgresConnection")); - }); - ``` -2. Set up your services; - ```csharp - // add RepositoryFactory (this will be needed by your repository class) - builder.Services.AddScoped>(); - // add your repositories - builder.Services.AddScoped(); - ``` - - -## Version history - -- 2.0.0 - work in progress commit to support the DataAccess.Repository.HotChocolate package -- 1.0.4 - added usage instructions to readme file -- 1.0.3 - updated main readme file -- 1.0.2 - changes to main build action to attempt to fix NuGet publishing issue -- 1.0.1 - testing NuGet publish on merge to main post pull request -- 1.0.0 - initial test publication of the NuGet package +# DataAccess + +## Introduction + +A simple data access base repository that can be used in other projects + +## Usage + +Full example project can be found here https://github.com/Ian-Webster/sandbox/tree/main/nuget-samples/DataAccess.Sample + +### Install NuGet packages + +Install the following NuGet packges into your project +1. [DataAccess.Repository](https://github.com/Ian-Webster/DataAccess/pkgs/nuget/DataAccess.Repository) +2. [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/7.0.0) +3. [Microsoft.EntityFrameworkCore.Relational](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Relational/7.0.0) +4. Your choice of EF core database targeting package (for example https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer) + +### Create entites and entity type configurations + +1. Create your database entity classes, as an example a movie entity; + ```csharp + public class Movie + { + public Guid MovieId { get; set; } + public string Name { get; set; } + } + ``` +2. Create your entity type configuration classes, as an example an entity type configuration for the movie entity; + ```csharp + public class MovieEntityTypeConfiguration: IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(pk => pk.MovieId); + builder.ToTable(nameof(Movie), SchemaNames.Public); + } + } + ``` + +### Create a database context class + +You will need to create a database context class that inherits from [DbContext](https://learn.microsoft.com/en-us/dotnet/api/system.data.entity.dbcontext?view=entity-framework-6.2.0) + +As an example here is the database context class for the Movie database; + +```csharp +public class MovieContext: DbContext // inherit from DbContext +{ + // inject DbContextOptions and base to the base class + public MovieContext(DbContextOptions options): base(options) + { + } + + // override OnModelCreating so we can apply our entity type configurations + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + // get the the assembly your EntityTypeConfigurations are in + // in this case they are in the same assembly as this context class + var assembly = Assembly.GetAssembly(typeof(MovieContext)); + if (assembly == null) + { + throw new Exception($"Failed to get assembly for {nameof(MovieContext)}"); + } + modelBuilder.ApplyConfigurationsFromAssembly(assembly); + } +} +``` + +### Create repository classes + +As an example the repository class for the movie entity; + +```csharp +using DataAccess.Repository; +using DataAccess.Sample.Data.DatabaseContexts; +using DataAccess.Sample.Domain.Entities; + +public class MovieRepository: IMovieRepository +{ + private readonly IRepository _movieRepository; + // inject RepositoryFactory for creating IRepository instances + public MovieRepository(RepositoryFactory repositoryFactory) + { + // create an instance of IRepository for our entity (Movie) + _movieRepository = repositoryFactory.GetRepositoryByType(); + } + + public async Task GetMovieById(Guid movieId, CancellationToken token) + { + // perform a database read for the Movie entity + return await _movieRepository.FirstOrDefault(m => m.MovieId == movieId, token); + } +} +``` + +### Configure IoC + +In your IoC bootstrapping you need to; +1. Add your database context, as an example here is the set up for the MovieContext connecting to a postgres database; + ```csharp + builder.Services.AddDbContext(options => + { + options.UseNpgsql(builder.Configuration.GetConnectionString("PostgresConnection")); + }); + ``` +2. Set up your services; + ```csharp + // add RepositoryFactory (this will be needed by your repository class) + builder.Services.AddScoped>(); + // add your repositories + builder.Services.AddScoped(); + ``` + + +## Version history + +- 2.0.0 - work in progress commit to support the DataAccess.Repository.HotChocolate package +- 1.0.4 - added usage instructions to readme file +- 1.0.3 - updated main readme file +- 1.0.2 - changes to main build action to attempt to fix NuGet publishing issue +- 1.0.1 - testing NuGet publish on merge to main post pull request +- 1.0.0 - initial test publication of the NuGet package From 421f3eaa4a66c119ced0a9413f1100cddad83dbe Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 23:26:15 +0000 Subject: [PATCH 19/22] #19 yml fixes + version bump --- .github/workflows/build.yml | 2 +- .github/workflows/test.yml | 4 ++-- DataAccess.Repository/DataAccess.Repository.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b18a6f6..9ec795d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Branch actions +name: Build actions on: push diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 715561f..6e21801 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Branch actions +name: Test DataAccess.Repository action on: push @@ -30,7 +30,7 @@ jobs: echo "Changes detected in DataAccess.Repository project. Restoring packages, running build and testing..." dotnet restore 'DataAccess.Repository' dotnet build --configuration Release 'DataAccess.Repository' - dotnet test DataAccess.Repository' + dotnet test 'DataAccess.Repository' else echo "No changes in DataAccess.Repository project. Skipping build." fi \ No newline at end of file diff --git a/DataAccess.Repository/DataAccess.Repository.csproj b/DataAccess.Repository/DataAccess.Repository.csproj index fc90e49..4a8f946 100644 --- a/DataAccess.Repository/DataAccess.Repository.csproj +++ b/DataAccess.Repository/DataAccess.Repository.csproj @@ -9,7 +9,7 @@ A simple base repository to be used in other projects requiring data access https://github.com/Ian-Webster/DataAccess https://github.com/Ian-Webster/DataAccess - 2.0.2 + 2.0.3 From 37874bb999cdee76e16050b7adf79ebafbb46c1c Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 23:32:55 +0000 Subject: [PATCH 20/22] #19 test.yml fix + version bump --- .github/workflows/test.yml | 4 ++-- DataAccess.Repository/DataAccess.Repository.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e21801..0645dab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: echo "Changes detected in DataAccess.Repository project. Restoring packages, running build and testing..." dotnet restore 'DataAccess.Repository' dotnet build --configuration Release 'DataAccess.Repository' - dotnet test 'DataAccess.Repository' + dotnet test 'DataAccess.Repository.Tests' else echo "No changes in DataAccess.Repository project. Skipping build." - fi \ No newline at end of file + fi \ No newline at end of file diff --git a/DataAccess.Repository/DataAccess.Repository.csproj b/DataAccess.Repository/DataAccess.Repository.csproj index 4a8f946..d33a684 100644 --- a/DataAccess.Repository/DataAccess.Repository.csproj +++ b/DataAccess.Repository/DataAccess.Repository.csproj @@ -9,7 +9,7 @@ A simple base repository to be used in other projects requiring data access https://github.com/Ian-Webster/DataAccess https://github.com/Ian-Webster/DataAccess - 2.0.3 + 2.0.4 From 5b92bf7b08da1b8d521b4c25da510420d977a88d Mon Sep 17 00:00:00 2001 From: Webster Date: Wed, 6 Dec 2023 23:38:14 +0000 Subject: [PATCH 21/22] #19 yml change + minor test change modifications to test yml to check for changes to the test project or the data access repository project --- .github/workflows/test.yml | 2 +- DataAccess.Repository.Tests/Tests/Add.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0645dab..8d5cb17 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: - name: Check for Changes in Repository Project run: | - if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'DataAccess.Repository/') ]]; then + if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'DataAccess.Repository/' 'DataAccess.Repository.Tests/') ]]; then echo "Changes detected in DataAccess.Repository project. Restoring packages, running build and testing..." dotnet restore 'DataAccess.Repository' dotnet build --configuration Release 'DataAccess.Repository' diff --git a/DataAccess.Repository.Tests/Tests/Add.cs b/DataAccess.Repository.Tests/Tests/Add.cs index f68d070..bba4151 100644 --- a/DataAccess.Repository.Tests/Tests/Add.cs +++ b/DataAccess.Repository.Tests/Tests/Add.cs @@ -1,6 +1,5 @@ using DataAccess.Repository.Tests.Shared.Entities; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NUnit.Framework; namespace DataAccess.Repository.Tests.Tests; From 4bf7626346a39af5deb8d50ed5f9346c34246974 Mon Sep 17 00:00:00 2001 From: Webster Date: Thu, 7 Dec 2023 00:06:44 +0000 Subject: [PATCH 22/22] #19 package yaml version bumps --- .github/workflows/build.yml | 9 ++- .github/workflows/{main.yml => main.yml.back} | 0 .github/workflows/package.yml | 72 +++++++++++++++++++ .github/workflows/test.yml | 13 ++-- .../DataAccess.Repository.csproj | 2 +- 5 files changed, 89 insertions(+), 7 deletions(-) rename .github/workflows/{main.yml => main.yml.back} (100%) create mode 100644 .github/workflows/package.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9ec795d..690b842 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,11 @@ -name: Build actions +name: Branch - build branch actions -on: push +on: + push: + branches: + - '*' + - '!main' + - '!trunk' jobs: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml.back similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/main.yml.back diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml new file mode 100644 index 0000000..5ecf81b --- /dev/null +++ b/.github/workflows/package.yml @@ -0,0 +1,72 @@ +name: Trunk - build and package actions + +on: + push: + branches: + - main + - trunk + +jobs: + + build_and_pack_DataAccess: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + - name: Check for Changes in Repository Project + run: | + if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'DataAccess.Repository/') ]]; then + echo "Changes detected in DataAccess.Repository project. Restoring packages and running build..." + dotnet restore 'DataAccess.Repository' + dotnet build --configuration Release 'DataAccess.Repository' + dotnet test 'DataAccess.Repository.Tests' + dotnet nuget push "DataAccess.Repository/bin/Release/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate + else + echo "No changes in DataAccess.Repository project. Skipping build and packing" + fi + + build_and_pack_HotChococlateExtension: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Set up local NuGet repo + - name: Setup GitHub NuGet + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Ian-Webster/index.json" + + - name: Check for Changes in HotChocolate Project + run: | + if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'Extensions/DataAccess.Repository.HotChocolate/') ]]; then + echo "Changes detected in Extensions/DataAccess.Repository.HotChocolate project. Restoring packages and running build..." + dotnet restore 'Extensions/DataAccess.Repository.HotChocolate' + dotnet build --configuration Release 'Extensions/DataAccess.Repository.HotChocolate' + dotnet nuget push "DataAccess.Repository/bin/Release/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate + else + echo "No changes in Extensions/DataAccess.Repository.HotChocolate project. Skipping build and packing" + fi \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d5cb17..b49cda7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,11 @@ -name: Test DataAccess.Repository action +name: Branch - test DataAccess.Repository action -on: push +on: + push: + branches: + - '*' + - '!main' + - '!trunk' jobs: @@ -27,10 +32,10 @@ jobs: - name: Check for Changes in Repository Project run: | if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 'DataAccess.Repository/' 'DataAccess.Repository.Tests/') ]]; then - echo "Changes detected in DataAccess.Repository project. Restoring packages, running build and testing..." + echo "Changes detected. Restoring packages, running build and testing..." dotnet restore 'DataAccess.Repository' dotnet build --configuration Release 'DataAccess.Repository' dotnet test 'DataAccess.Repository.Tests' else - echo "No changes in DataAccess.Repository project. Skipping build." + echo "No changes. Skipping build and tests" fi \ No newline at end of file diff --git a/DataAccess.Repository/DataAccess.Repository.csproj b/DataAccess.Repository/DataAccess.Repository.csproj index d33a684..28ff22a 100644 --- a/DataAccess.Repository/DataAccess.Repository.csproj +++ b/DataAccess.Repository/DataAccess.Repository.csproj @@ -9,7 +9,7 @@ A simple base repository to be used in other projects requiring data access https://github.com/Ian-Webster/DataAccess https://github.com/Ian-Webster/DataAccess - 2.0.4 + 2.0.5