Skip to content

Commit

Permalink
Diagnostics (ChilliCream#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Oct 23, 2018
1 parent 7f3b74a commit d51b71a
Show file tree
Hide file tree
Showing 74 changed files with 873 additions and 462 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,15 @@ Moreover, we are working on the following parts that are not defined in the spec

We are currently working on the following features that are proposed for the next GraphQL specification.

- [ ] [Limit directive uniqueness to explicitly marked directives](https://github.com/facebook/graphql/pull/472) (#291 in development - 0.5.3)
- [ ] [Add rules for how circular references in Input Objects are handled](https://github.com/facebook/graphql/pull/445)
- [ ] [Add description to Schema](https://github.com/facebook/graphql/pull/466)
- [ ] ["Directive order is significant" section](https://github.com/facebook/graphql/pull/470)
- [ ] [Limit directive uniqueness to explicitly marked directives](https://github.com/facebook/graphql/pull/472) (#291 in development - 0.7.0)
- [ ] [Add rules for how circular references in Input Objects are handled](https://github.com/facebook/graphql/pull/445) (in development - 0.10.0)
- [ ] [Add description to Schema](https://github.com/facebook/graphql/pull/466) (in development - 0.9.0)
- [ ] ["Directive order is significant" section](https://github.com/facebook/graphql/pull/470) (in development - 0.7.0)

### Additional Scalar Types

- [x] DateTime
- [x] Date
- [x] Time
- [x] URL
- [x] UUID
- [x] Decimal
Expand All @@ -273,9 +272,8 @@ We are currently working on the following features that are proposed for the nex

### Additional Directives

- [ ] Export
- [ ] Defer
- [ ] Stream
- [ ] Schema Stitching (in development - 0.8.0)
- [ ] HTTP Directives (in development - 0.8.0)
- [x] Custom Schema Directives
- [x] Custom Query Directives

Expand All @@ -292,15 +290,16 @@ We are currently working on the following features that are proposed for the nex
## Supported Frameworks

- [ ] ASP.NET Classic

- [ ] _Get_ (in development - 0.5.3)
- [ ] _Post_ (in development - 0.5.3)
- [ ] _WebSockets_ (in development - 0.5.5)
- [ ] _Get_ (in development - 0.7.0)
- [ ] _Post_ (in development - 0.7.0)
- [ ] _WebSockets_ (in development - 0.8.0)
- [ ] Schema Builder (in development - 1.0.0)

- [x] ASP.NET Core
- [x] Get
- [x] Post
- [ ] _WebSockets_ (in development - 0.5.4)
- [x] WebSockets
- [ ] Schema Builder (in development - 0.11.0)

## Documentation

Expand Down
2 changes: 2 additions & 0 deletions src/Core.Tests/Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<PackageReference Include="coveralls.io" Version="1.4.2" />
<PackageReference Include="OpenCover" Version="4.6.519" />
<PackageReference Include="Moq" Version="4.8.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.1.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

Expand Down
140 changes: 140 additions & 0 deletions src/Core.Tests/Execution/DiagnosticTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using Microsoft.Extensions.DiagnosticAdapter;
using Xunit;

namespace HotChocolate.Execution
{
public class DiagnosticTests
{
[Fact]
public async Task ResolverEvents()
{
// arrange
var listener = new TestDiagnosticListener();
using (DiagnosticListener.AllListeners.Subscribe(
new DiagnosticObserver(listener)))
{
ISchema schema = CreateSchema();

// act
await schema.ExecuteAsync("{ foo }");

// assert
Assert.True(listener.ResolveFieldStart);
Assert.True(listener.ResolveFieldStop);
Assert.Equal("foo", listener.FieldSelection.Name.Value);
Assert.InRange(listener.Duration,
TimeSpan.FromMilliseconds(50),
TimeSpan.FromMilliseconds(2000));
}
}

[Fact]
public async Task QueryEvents()
{
// arrange
var listener = new TestDiagnosticListener();
using (DiagnosticListener.AllListeners.Subscribe(
new DiagnosticObserver(listener)))
{
ISchema schema = CreateSchema();

// act
await schema.ExecuteAsync("{ foo }");

// assert
Assert.True(listener.QueryStart);
Assert.True(listener.QueryStop);
}
}

private ISchema CreateSchema()
{
return Schema.Create(
"type Query { foo: String }",
c => c.BindResolver(() =>
{
Thread.Sleep(50);
return "bar";
}).To("Query", "foo"));
}

private class TestDiagnosticListener
{
public bool ResolveFieldStart { get; private set; }

public bool ResolveFieldStop { get; private set; }

public TimeSpan Duration { get; private set; }

public FieldNode FieldSelection { get; private set; }

public bool QueryStart { get; private set; }

public bool QueryStop { get; private set; }


[DiagnosticName("HotChocolate.Execution.Resolver.Start")]
public virtual void OnResolveFieldStart()
{
ResolveFieldStart = true;
}

[DiagnosticName("HotChocolate.Execution.Resolver.Stop")]
public virtual void OnResolveFieldStop(IResolverContext context)
{
ResolveFieldStop = true;
FieldSelection = context.FieldSelection;
Duration = Activity.Current.Duration;
}

[DiagnosticName("HotChocolate.Execution.Query.Start")]
public virtual void OnQueryStart()
{
QueryStart = true;
}

[DiagnosticName("HotChocolate.Execution.Query.Stop")]
public virtual void OnQueryStop(IResolverContext context)
{
QueryStop = true;
}
}

private class DiagnosticObserver
: IObserver<DiagnosticListener>
{
private readonly TestDiagnosticListener _listener;

public DiagnosticObserver(TestDiagnosticListener listener)
{
_listener = listener;
}

public void OnCompleted()
{
}

public void OnError(Exception error)
{
}

public void OnNext(DiagnosticListener value)
{
if (value.Name == "HotChocolate.Execution")
{
value.SubscribeWithAdapter(_listener, s =>
{
return true;
});
}
}
}
}
}
1 change: 1 addition & 0 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<ItemGroup>
<PackageReference Include="GreenDonut" Version="1.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit d51b71a

Please sign in to comment.