Skip to content

Commit

Permalink
Merge pull request #21 from Ian-Webster/19-add-extension-for-hotchoco…
Browse files Browse the repository at this point in the history
…late

19 Add extension for HotChocolate
  • Loading branch information
Ian-Webster authored Dec 7, 2023
2 parents fd0a791 + 4bf7626 commit 793b909
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Branch - build branch actions

on:
push:
branches:
- '*'
- '!main'
- '!trunk'

jobs:

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"

- 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:

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'
else
echo "No changes in Extensions/DataAccess.Repository.HotChocolate project. Skipping build."
fi
File renamed without changes.
72 changes: 72 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Branch - test DataAccess.Repository action

on:
push:
branches:
- '*'
- '!main'
- '!trunk'

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/' 'DataAccess.Repository.Tests/') ]]; then
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. Skipping build and tests"
fi
1 change: 0 additions & 1 deletion DataAccess.Repository.Tests/Tests/Add.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion DataAccess.Repository/DataAccess.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>A simple base repository to be used in other projects requiring data access</Description>
<PackageProjectUrl>https://github.com/Ian-Webster/DataAccess</PackageProjectUrl>
<RepositoryUrl>https://github.com/Ian-Webster/DataAccess</RepositoryUrl>
<VersionPrefix>2.0.0-wip</VersionPrefix>
<VersionPrefix>2.0.5</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>

Expand Down
18 changes: 18 additions & 0 deletions Example/DataAccess.Example.Data/Queries/BookQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HotChocolate;
using HotChocolate.Types;
using HotChocolate.Resolvers;
using HotChocolate.Types.Pagination;

namespace DataAccess.Example.Data.Queries;

Expand All @@ -15,4 +16,21 @@ public class BookQuery
{
return await repository.GetBookForGraphQuery(context, token);
}

[UseProjection]
[UseFiltering]
[UseSorting]
public async Task<IEnumerable<Book>?> GetBooks([Service] IBookRepository repository, IResolverContext context, CancellationToken token)
{
return await repository.GetBooksForGraphQuery(context, token);
}

[UsePaging(IncludeTotalCount = true)]
[UseProjection]
[UseFiltering]
[UseSorting]
public async Task<Connection<Book>> GetPagedBooks([Service] IBookRepository repository, IResolverContext context, CancellationToken token)
{
return await repository.GetPagedBooksForGraphQuery(context, token);
}
}
11 changes: 11 additions & 0 deletions Example/DataAccess.Example.Data/Repositories/BookRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using DataAccess.Repository;
using DataAccess.Repository.HotChocolate;
using HotChocolate.Resolvers;
using HotChocolate.Types.Pagination;

namespace DataAccess.Example.Data.Repositories;

Expand Down Expand Up @@ -62,4 +63,14 @@ public async Task<bool> RemoveBook(Guid bookId, CancellationToken token)
{
return await _bookRepo.GetQueryItem(context, token);
}

public async Task<IEnumerable<Book>?> GetBooksForGraphQuery(IResolverContext context, CancellationToken token)
{
return await _bookRepo.GetQueryItems(context, token);
}

public async Task<Connection<Book>> GetPagedBooksForGraphQuery(IResolverContext context, CancellationToken token)
{
return await _bookRepo.GetPagedQueryItems(context, token);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DataAccess.Example.Data.Entities;
using HotChocolate.Resolvers;
using HotChocolate.Types.Pagination;

namespace DataAccess.Example.Data.Repositories;

Expand All @@ -16,4 +17,8 @@ public interface IBookRepository
Task<bool> RemoveBook(Guid bookId, CancellationToken token);

Task<Book?> GetBookForGraphQuery(IResolverContext context, CancellationToken token);

Task<IEnumerable<Book>?> GetBooksForGraphQuery(IResolverContext context, CancellationToken token);

Task<Connection<Book>> GetPagedBooksForGraphQuery(IResolverContext context, CancellationToken token);
}
2 changes: 2 additions & 0 deletions Example/DataAccess.Example.Web/DataAccess.Example.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<PackageReference Include="HotChocolate.AspNetCore" Version="13.7.0" />
<PackageReference Include="HotChocolate.Data" Version="13.7.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>DataAccess.HotChocolate</Title>
<Description>Extension to the DataAccess package adding GraphQL functionality via the HotChocolate library</Description>
<PackageProjectUrl>https://github.com/Ian-Webster/DataAccess/Extensions/DataAccess.Repository.HotChocolate</PackageProjectUrl>
<RepositoryUrl>https://github.com/Ian-Webster/DataAccess</RepositoryUrl>
<VersionPrefix>0.3.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DataAccess.Repository" Version="2.0.0-wip" />
<PackageReference Include="HotChocolate" Version="13.7.0" />
<PackageReference Include="HotChocolate.AspNetCore" Version="13.7.0" />
<PackageReference Include="HotChocolate.Data" Version="13.7.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\DataAccess.Repository\DataAccess.Repository.csproj" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public static async Task<Connection<TEntity>> GetPagedQueryItems<TEntity>(this I
IResolverContext context, CancellationToken token) where TEntity : class
{
return await repository.DbSet
.AsQueryable()
.AsNoTracking()
.AsQueryable()
.Filter(context)
.Project(context)
.Sort(context)
Expand Down
3 changes: 2 additions & 1 deletion Extensions/DataAccess.Repository.HotChocolate/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,4 +113,5 @@ Usage for this extension is as follows;
```

## Version history
* 1.0.0 - Initial release
* 0.1.0 - Initial project creation, getting everything figured out and running locally
Loading

0 comments on commit 793b909

Please sign in to comment.