Skip to content

Commit

Permalink
Bump to GraphQL.NET v7 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Aug 17, 2022
1 parent c4250c5 commit 3163be6
Show file tree
Hide file tree
Showing 35 changed files with 1,657 additions and 1,794 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -13,17 +13,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use .NET Core 5.0 SDK
- name: Use .NET Core 6.0 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
dotnet-version: '6.0.x'
source-url: https://nuget.pkg.github.com/Shane32/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Install dependencies
run: dotnet restore
- name: Build solution [Release]
run: dotnet build --no-restore -c Release -p:NoWarn=CS1591 -p:VersionSuffix=$GITHUB_RUN_NUMBER
run: dotnet build --no-restore -c Release -p:VersionSuffix=$GITHUB_RUN_NUMBER
- name: Pack solution [Release]
run: dotnet pack --no-restore --no-build -c Release -p:VersionSuffix=$GITHUB_RUN_NUMBER -o out
- name: Upload artifacts
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Expand Up @@ -23,17 +23,17 @@ jobs:
version="${github_ref:10}"
echo version=$version
echo "version=$version" >> $GITHUB_ENV
- name: Use .NET Core 5.0 SDK
- name: Use .NET Core 6.0 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
dotnet-version: '6.0.x'
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.NUGET_AUTH_TOKEN}}
- name: Install dependencies
run: dotnet restore
- name: Build solution [Release]
run: dotnet build --no-restore -c Release -p:NoWarn=CS1591 -p:Version=$version
run: dotnet build --no-restore -c Release -p:Version=$version
- name: Pack solution [Release]
run: dotnet pack --no-restore --no-build -c Release -p:Version=$version -o out
- name: Upload artifacts
Expand Down
18 changes: 5 additions & 13 deletions .github/workflows/test.yml
Expand Up @@ -21,27 +21,19 @@ jobs:
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Use .NET Core 2.1 LTS SDK
uses: actions/setup-dotnet@v1
- name: Use .NET Core SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: '2.1.x'
- name: Use .NET Core 3.1 LTS SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
- name: Use .NET Core 5.0 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
dotnet-version: 6.x
source-url: https://nuget.pkg.github.com/Shane32/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Install dependencies
run: dotnet restore
- name: Build solution [Release]
run: dotnet build --no-restore -c Release -p:NoWarn=CS1591
run: dotnet build --no-restore -c Release
- name: Build solution [Debug]
run: dotnet build --no-restore -p:NoWarn=CS1591
run: dotnet build --no-restore
- name: Test solution [Debug]
run: dotnet test --no-restore --no-build -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=../../${{ matrix.os }}.lcov.info
# ==== code coverage reports (ubuntu-latest only) ====
Expand Down
13 changes: 11 additions & 2 deletions Directory.Build.props
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<VersionPrefix>1.0.0-preview</VersionPrefix>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Copyright>Shane Krueger</Copyright>
<Authors>Shane Krueger</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -16,11 +16,20 @@
<ContinuousIntegrationBuild Condition="'$(Configuration)' != 'Debug'">True</ContinuousIntegrationBuild>
<DebugType>embedded</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisMode>Recommended</AnalysisMode>
<GraphQLVersion>7.0.0</GraphQLVersion>
<GraphQLAspNetCore3Version>5.0.0</GraphQLAspNetCore3Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" Condition="'$(IsPackable)' == 'true'"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" Condition="'$(IsPackable)' == 'true'"/>
<None Include="..\..\logo.64x64.png" Pack="true" PackagePath="\" Condition="'$(IsPackable)' == 'true'"/>
<None Include="..\..\README.md" Pack="true" PackagePath="\" Condition="'$(IsPackable)' == 'true'"/>
</ItemGroup>

</Project>
13 changes: 10 additions & 3 deletions GraphQL.DI.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30611.23
# Visual Studio Version 17
VisualStudioVersion = 17.3.32811.315
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shane32.GraphQL.DI", "src\GraphQL.DI\Shane32.GraphQL.DI.csproj", "{72C179A6-53BF-48BC-BFE0-BD8CA2618AF6}"
EndProject
Expand All @@ -18,7 +18,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "src\Tests\Tests.csproj", "{BA5F3790-9FE0-4A10-8528-0756334AC727}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{4AB70777-E140-49E4-8173-7809DF67A021}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "Sample\Sample.csproj", "{4AB70777-E140-49E4-8173-7809DF67A021}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{7432A0AF-9346-41D7-9DA9-D7EFEAF1A401}"
ProjectSection(SolutionItems) = preProject
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\publish.yml = .github\workflows\publish.yml
.github\workflows\test.yml = .github\workflows\test.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
32 changes: 15 additions & 17 deletions Sample/DataLoaders/PersonDataLoader.cs
@@ -1,27 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using GraphQL.DataLoader;
using Microsoft.EntityFrameworkCore;
using Sample.DbModels;

namespace Sample.DataLoaders
namespace Sample.DataLoaders;

public class PersonDataLoader : DataLoaderBase<int, Person?>
{
public class PersonDataLoader : DataLoaderBase<int, Person>
private readonly TodoDbContext _db;

public PersonDataLoader(TodoDbContext db)
{
private TodoDbContext _db;
public PersonDataLoader(TodoDbContext db) => _db = db;
_db = db;
}

protected override async Task FetchAsync(IEnumerable<DataLoaderPair<int, Person>> list, CancellationToken cancellationToken)
{
var ids = list.Select(x => x.Key);
var people = await _db.Set<Person>().Where(x => ids.Contains(x.Id)).ToDictionaryAsync(x => x.Id, cancellationToken);
foreach (var value in list) {
people.TryGetValue(value.Key, out var person);
value.SetResult(person);
}
protected override async Task FetchAsync(IEnumerable<DataLoaderPair<int, Person?>> list, CancellationToken cancellationToken)
{
var ids = list.Select(x => x.Key);
var people = await _db.Set<Person>().Where(x => ids.Contains(x.Id)).ToDictionaryAsync(x => x.Id, cancellationToken);
foreach (var value in list) {
people.TryGetValue(value.Key, out var person);
value.SetResult(person);
}
}
}
14 changes: 4 additions & 10 deletions Sample/DbModels/Person.cs
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Sample.DbModels;

namespace Sample.DbModels
public class Person
{
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
public int Id { get; set; }
public string Name { get; set; } = null!;
}
27 changes: 11 additions & 16 deletions Sample/DbModels/Todo.cs
@@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace Sample.DbModels
namespace Sample.DbModels;

public class Todo
{
public class Todo
{
public int Id { get; set; }
public string Title { get; set; }
public string Notes { get; set; }
public bool Completed { get; set; }
public DateTime? CompletionDate { get; set; }
public int? CompletedByPersonId { get; set; }
[ForeignKey("CompletedByPersonId")]
public Person CompletedBy { get; set; }
}
public int Id { get; set; }
public string Title { get; set; } = null!;
public string Notes { get; set; } = null!;
public bool Completed { get; set; }
public DateTime? CompletionDate { get; set; }
public int? CompletedByPersonId { get; set; }
[ForeignKey("CompletedByPersonId")]
public Person CompletedBy { get; set; } = null!;
}
20 changes: 7 additions & 13 deletions Sample/DoNotMapClrTypeAttribute.cs
@@ -1,16 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Sample;

namespace Sample
/// <summary>
/// Indicates that GetClrTypeMappings should
/// skip this class when scanning an assembly for CLR type mappings.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class DoNotMapClrTypeAttribute : Attribute
{
/// <summary>
/// Indicates that GetClrTypeMappings should
/// skip this class when scanning an assembly for CLR type mappings.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class DoNotMapClrTypeAttribute : Attribute
{
}
}
87 changes: 42 additions & 45 deletions Sample/GraphTypes/MutationType.cs
@@ -1,55 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GraphQL.Types;
using GraphQL;
using GraphQL.DI;
using Sample.DbModels;
using Microsoft.EntityFrameworkCore;
using GraphQL;
using System.Threading;
using Sample.DbModels;

namespace Sample.GraphTypes;

namespace Sample.GraphTypes
public class MutationType : DIObjectGraphType<Mutation> { }
public class Mutation : DIObjectGraphBase<object>
{
public class MutationType : DIObjectGraphType<Mutation> { }
public class Mutation : DIObjectGraphBase<object>
private readonly TodoDbContext _db;

public Mutation(TodoDbContext db)
{
public readonly TodoDbContext _db;
public Mutation(TodoDbContext db) => _db = db;
_db = db;
}

public async Task<Todo> AddTodoAsync([Required] string title, string notes, CancellationToken cancellationToken)
{
var todo = new Todo {
Title = title,
Notes = notes,
};
_db.Add(todo);
await _db.SaveChangesAsync(cancellationToken);
return todo;
}
public async Task<Todo> AddTodoAsync([Required] string title, string notes, CancellationToken cancellationToken)
{
var todo = new Todo {
Title = title,
Notes = notes,
};
_db.Add(todo);
await _db.SaveChangesAsync(cancellationToken);
return todo;
}

public async Task<bool> DeleteTodoAsync(int id, CancellationToken cancellationToken)
{
var todo = await _db.Set<Todo>().Where(x => x.Id == id).SingleOrDefaultAsync();
if (todo == null)
return false;
_db.Set<Todo>().Remove(todo);
await _db.SaveChangesAsync(cancellationToken);
return true;
}
public async Task<bool> DeleteTodoAsync(int id, CancellationToken cancellationToken)
{
var todo = await _db.Set<Todo>().Where(x => x.Id == id).SingleOrDefaultAsync(cancellationToken);
if (todo == null)
return false;
_db.Set<Todo>().Remove(todo);
await _db.SaveChangesAsync(cancellationToken);
return true;
}

public async Task<Todo> SetCompleteAsync(int id, int completedByPersonId, CancellationToken cancellationToken)
{
var todo = await _db.Set<Todo>().Where(x => x.Id == id).SingleOrDefaultAsync(cancellationToken);
if (todo == null)
return null;
if (todo.Completed)
throw new ExecutionError($"Task id {id} has already been completed");
todo.Completed = true;
todo.CompletedByPersonId = completedByPersonId;
todo.CompletionDate = DateTime.Now;
await _db.SaveChangesAsync(cancellationToken);
return todo;
}
public async Task<Todo?> SetCompleteAsync(int id, int completedByPersonId, CancellationToken cancellationToken)
{
var todo = await _db.Set<Todo>().Where(x => x.Id == id).SingleOrDefaultAsync(cancellationToken);
if (todo == null)
return null;
if (todo.Completed)
throw new ExecutionError($"Task id {id} has already been completed");
todo.Completed = true;
todo.CompletedByPersonId = completedByPersonId;
todo.CompletionDate = DateTime.Now;
await _db.SaveChangesAsync(cancellationToken);
return todo;
}
}
17 changes: 6 additions & 11 deletions Sample/GraphTypes/PersonType.cs
@@ -1,18 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GraphQL.Types;
using Sample.DbModels;

namespace Sample.GraphTypes
namespace Sample.GraphTypes;

public class PersonType : ObjectGraphType<Person>
{
public class PersonType : ObjectGraphType<Person>
public PersonType()
{
public PersonType()
{
Field(x => x.Id);
Field(x => x.Name);
}
Field(x => x.Id);
Field(x => x.Name);
}
}

0 comments on commit 3163be6

Please sign in to comment.