forked from ChilliCream/graphql-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba7cbc0
commit 1fc2617
Showing
45 changed files
with
1,637 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,3 +290,5 @@ __pycache__/ | |
lcov.info | ||
coverage.json | ||
.DS_Store | ||
|
||
BenchmarkDotNet.Artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
"program": "${workspaceFolder}/src/Benchmark.Tests/bin/Debug/netcoreapp2.1/Benchmark.Tests.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
"console": "internalConsole", | ||
"stopAtEntry": false, | ||
"internalConsoleOptions": "openOnSessionStart" | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dotnet build src -c release | ||
dotnet "src/Benchmark.Tests/bin/Release/netcoreapp2.1/Benchmark.Tests.dll" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dotnet build src -c release | ||
sudo dotnet "src/Benchmark.Tests/bin/Release/netcoreapp2.1/Benchmark.Tests.dll" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<RootNamespace>HotChocolate.Benchmark.Tests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.10.13" /> | ||
<PackageReference Include="Moq" Version="4.8.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Core\Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Resources\IntrospectionQuery.graphql" /> | ||
<None Remove="Resources\KitchenSinkQuery.graphql" /> | ||
<None Remove="Resources\KitchenSinkSchema.graphql" /> | ||
<None Remove="Resources\SimpleQuery.graphql" /> | ||
<None Remove="Resources\SimpleSchema.graphql" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Resources\IntrospectionQuery.graphql" /> | ||
<EmbeddedResource Include="Resources\KitchenSinkQuery.graphql" /> | ||
<EmbeddedResource Include="Resources\KitchenSinkSchema.graphql" /> | ||
<EmbeddedResource Include="Resources\SimpleQuery.graphql" /> | ||
<EmbeddedResource Include="Resources\SimpleSchema.graphql" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public class CharacterRepository | ||
{ | ||
private Dictionary<string, ICharacter> _characters; | ||
private Dictionary<string, Starship> _starships; | ||
|
||
public CharacterRepository() | ||
{ | ||
_characters = CreateCharacters().ToDictionary(t => t.Id); | ||
_starships = CreateStarships().ToDictionary(t => t.Id); | ||
} | ||
|
||
public ICharacter GetHero(Episode episode) | ||
{ | ||
if (episode == Episode.Empire) | ||
{ | ||
return _characters["1000"]; | ||
} | ||
return _characters["2001"]; | ||
} | ||
|
||
public ICharacter GetCharacter(string id) | ||
{ | ||
if (_characters.TryGetValue(id, out ICharacter c)) | ||
{ | ||
return c; | ||
} | ||
return null; | ||
} | ||
|
||
public Human GetHuman(string id) | ||
{ | ||
if (_characters.TryGetValue(id, out ICharacter c) | ||
&& c is Human h) | ||
{ | ||
return h; | ||
} | ||
return null; | ||
} | ||
|
||
public Droid GetDroid(string id) | ||
{ | ||
if (_characters.TryGetValue(id, out ICharacter c) | ||
&& c is Droid d) | ||
{ | ||
return d; | ||
} | ||
return null; | ||
} | ||
|
||
public IEnumerable<object> Search(string text) | ||
{ | ||
foreach(ICharacter character in _characters.Values | ||
.Where(t => t.Name.Contains(text))) | ||
{ | ||
yield return character; | ||
} | ||
|
||
foreach(Starship starship in _starships.Values | ||
.Where(t => t.Name.Contains(text))) | ||
{ | ||
yield return starship; | ||
} | ||
} | ||
|
||
private static IEnumerable<ICharacter> CreateCharacters() | ||
{ | ||
yield return new Human | ||
{ | ||
Id = "1000", | ||
Name = "Luke Skywalker", | ||
Friends = new[] { "1002", "1003", "2000", "2001" }, | ||
AppearsIn = new[] { Episode.NewHope, Episode.Empire, Episode.Jedi }, | ||
HomePlanet = "Tatooine" | ||
}; | ||
|
||
yield return new Human | ||
{ | ||
Id = "1001", | ||
Name = "Darth Vader", | ||
Friends = new[] { "1004" }, | ||
AppearsIn = new[] { Episode.NewHope, Episode.Empire, Episode.Jedi }, | ||
HomePlanet = "Tatooine" | ||
}; | ||
|
||
yield return new Human | ||
{ | ||
Id = "1002", | ||
Name = "Han Solo", | ||
Friends = new[] { "1000", "1003", "2001" }, | ||
AppearsIn = new[] { Episode.NewHope, Episode.Empire, Episode.Jedi } | ||
}; | ||
|
||
yield return new Human | ||
{ | ||
Id = "1003", | ||
Name = "Leia Organa", | ||
Friends = new[] { "1000", "1002", "2000", "2001" }, | ||
AppearsIn = new[] { Episode.NewHope, Episode.Empire, Episode.Jedi }, | ||
HomePlanet = "Alderaan" | ||
}; | ||
|
||
yield return new Human | ||
{ | ||
Id = "1004", | ||
Name = "Wilhuff Tarkin", | ||
Friends = new[] { "1001" }, | ||
AppearsIn = new[] { Episode.NewHope } | ||
}; | ||
|
||
yield return new Droid | ||
{ | ||
Id = "2000", | ||
Name = "C-3PO", | ||
Friends = new[] { "1000", "1002", "1003", "2001" }, | ||
AppearsIn = new[] { Episode.NewHope, Episode.Empire, Episode.Jedi }, | ||
PrimaryFunction = "Protocol" | ||
}; | ||
|
||
yield return new Droid | ||
{ | ||
Id = "2001", | ||
Name = "R2-D2", | ||
Friends = new[] { "1000", "1002", "1003" }, | ||
AppearsIn = new[] { Episode.NewHope, Episode.Empire, Episode.Jedi }, | ||
PrimaryFunction = "Astromech" | ||
}; | ||
} | ||
|
||
private static IEnumerable<Starship> CreateStarships() | ||
{ | ||
yield return new Starship | ||
{ | ||
Id = "3000", | ||
Name = "TIE Advanced x1", | ||
Length = 9.2 | ||
}; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using HotChocolate.Resolvers; | ||
using HotChocolate.Types; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public class CharacterType | ||
: InterfaceType | ||
{ | ||
protected override void Configure(IInterfaceTypeDescriptor descriptor) | ||
{ | ||
descriptor.Name("Character"); | ||
descriptor.Field("id").Type<NonNullType<StringType>>(); | ||
descriptor.Field("name").Type<StringType>(); | ||
descriptor.Field("friends").Type<ListType<CharacterType>>(); | ||
descriptor.Field("appearsIn").Type<ListType<EpisodeType>>(); | ||
descriptor.Field("height").Type<FloatType>() | ||
.Argument("unit", a => a.Type<EnumType<Unit>>()); | ||
} | ||
|
||
public static IEnumerable<ICharacter> GetCharacter( | ||
IResolverContext context) | ||
{ | ||
ICharacter character = context.Parent<ICharacter>(); | ||
CharacterRepository repository = context.Service<CharacterRepository>(); | ||
foreach (string friendId in character.Friends) | ||
{ | ||
ICharacter friend = repository.GetCharacter(friendId); | ||
if (friend != null) | ||
{ | ||
yield return friend; | ||
} | ||
} | ||
} | ||
|
||
public static double GetHeight( | ||
IResolverContext context) | ||
{ | ||
double height = context.Parent<ICharacter>().Height; | ||
if (context.Argument<Unit?>("unit") == Unit.Foot) | ||
{ | ||
return height * 3.28084d; | ||
} | ||
return height; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public class Droid | ||
: ICharacter | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public IReadOnlyList<string> Friends { get; set; } | ||
|
||
public IReadOnlyList<Episode> AppearsIn { get; set; } | ||
|
||
public string PrimaryFunction { get; set; } | ||
|
||
public double Height { get; } = 1.72d; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using HotChocolate.Types; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public class DroidType | ||
: ObjectType<Droid> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<Droid> descriptor) | ||
{ | ||
descriptor.Interface<CharacterType>(); | ||
descriptor.Field(t => t.Friends) | ||
.Type<ListType<CharacterType>>() | ||
.Resolver(c => CharacterType.GetCharacter(c)); | ||
descriptor.Field(t => t.Height) | ||
.Argument("unit", a => a.Type<EnumType<Unit>>()) | ||
.Resolver(c => CharacterType.GetHeight(c)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public enum Episode | ||
{ | ||
NewHope, | ||
Empire, | ||
Jedi | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using HotChocolate.Types; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public class EpisodeType | ||
: EnumType<Episode> | ||
{ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public class Human | ||
: ICharacter | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public IReadOnlyList<string> Friends { get; set; } | ||
|
||
public IReadOnlyList<Episode> AppearsIn { get; set; } | ||
|
||
public string HomePlanet { get; set; } | ||
|
||
public double Height { get; } = 1.72d; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using HotChocolate.Types; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public class HumanType | ||
: ObjectType<Human> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<Human> descriptor) | ||
{ | ||
descriptor.Interface<CharacterType>(); | ||
descriptor.Field(t => t.Friends) | ||
.Type<ListType<CharacterType>>() | ||
.Resolver(c => CharacterType.GetCharacter(c)); | ||
descriptor.Field(t => t.Height) | ||
.Argument("unit", a => a.Type<EnumType<Unit>>()) | ||
.Resolver(c => CharacterType.GetHeight(c)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace HotChocolate.Benchmark.Tests.Execution | ||
{ | ||
public interface ICharacter | ||
{ | ||
string Id { get; } | ||
string Name { get; } | ||
IReadOnlyList<string> Friends { get; } | ||
IReadOnlyList<Episode> AppearsIn { get; } | ||
double Height { get; } | ||
} | ||
|
||
} |
Oops, something went wrong.