Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue #629 #630

Merged
merged 3 commits into from Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Fixed

- Custom diagnostic observer registration issue [#629](https://github.com/ChilliCream/hotchocolate/issues/629).

## [0.8.0] - 2019-03-03

### Added
Expand Down
1 change: 0 additions & 1 deletion src/Core/Abstractions.Tests/PathTests.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using ChilliCream.Testing;
using Snapshooter.Xunit;
using Xunit;

Expand Down
1 change: 0 additions & 1 deletion src/Core/Abstractions/Execution/IQueryRequestBuilder.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using HotChocolate.Execution;

namespace HotChocolate.Execution
{
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Abstractions/Execution/OrderedDictionary.cs
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;

namespace HotChocolate.Execution
Expand Down
4 changes: 1 addition & 3 deletions src/Core/Abstractions/IErrorFilter.cs
@@ -1,6 +1,4 @@
using System;

namespace HotChocolate
namespace HotChocolate
{
/// <summary>
/// An error filter can handle and rewrite errors that occured
Expand Down
1 change: 0 additions & 1 deletion src/Core/Abstractions/Path.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;

namespace HotChocolate
{
Expand Down
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>HotChocolate.Core.Diagnostics.Tests</AssemblyName>
<AssemblyName>HotChocolate.Core.Diagnostics.ApolloTracing.Tests</AssemblyName>
<RootNamespace>HotChocolate</RootNamespace>
<IsPackable>false</IsPackable>

Expand Down
@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>HotChocolate.Core.Diagnostics.CustomObserver.Tests</AssemblyName>
<RootNamespace>HotChocolate</RootNamespace>
<IsPackable>false</IsPackable>

</PropertyGroup>

<PropertyGroup>
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0" />
<PackageReference Include="coverlet.msbuild" Version="2.5.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.1.0" />
<PackageReference Include="ChilliCream.Testing.Utilities" Version="0.2.0" />
<PackageReference Include="Snapshooter.Xunit" Version="0.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.0-beta.1.build3958" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="__snapshots__\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="__resources__\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
@@ -0,0 +1,104 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Execution.Instrumentation;
using Microsoft.Extensions.DiagnosticAdapter;
using Xunit;

namespace HotChocolate
{
public class DiagnosticsEventsTests
{
[Fact]
public async Task VerifyCustomDignosticObserverIsWorkingProper()
{
// arrange
var events = new List<string>();
Schema schema = CreateSchema();
IQueryExecutor executor = QueryExecutionBuilder.New()
.UseDefaultPipeline()
.AddDiagnosticObserver(new CustomDiagnosticsObserver(events))
.Build(schema);
var request = new QueryRequest("{ a }");

// act
IExecutionResult result = await executor.ExecuteAsync(request);

// assert
Assert.Empty(result.Extensions);
Assert.Collection(events,
i => Assert.Equal("foo", i),
i => Assert.Equal("bar", i));
}

private Schema CreateSchema()
{
return Schema.Create(@"
type Query {
a: String
b(a: String!): String
x: String
y: String
xasync: String
yasync: String
}
", c =>
{
c.BindResolver(() => "hello world a")
.To("Query", "a");
c.BindResolver(
ctx => "hello world " + ctx.Argument<string>("a"))
.To("Query", "b");
c.BindResolver(
() => ResolverResult<string>
.CreateValue("hello world x"))
.To("Query", "x");
c.BindResolver(
() => ResolverResult<string>
.CreateError("hello world y"))
.To("Query", "y");
c.BindResolver(
async () => await Task.FromResult(
ResolverResult<string>
.CreateValue("hello world xasync")))
.To("Query", "xasync");
c.BindResolver(
async () => await Task.FromResult(
ResolverResult<string>
.CreateError("hello world yasync")))
.To("Query", "yasync");
});
}

private class CustomDiagnosticsObserver
: IDiagnosticObserver
{
private readonly List<string> _events;

public CustomDiagnosticsObserver(List<string> events)
{
_events = events;
}

[DiagnosticName("HotChocolate.Execution.Query")]
public void QueryExecute()
{
// Required for enabling Query events.
}

[DiagnosticName("HotChocolate.Execution.Query.Start")]
public void BeginQueryExecute(IQueryContext context)
{
_events.Add("foo");
}

[DiagnosticName("HotChocolate.Execution.Query.Stop")]
public void EndQueryExecute(
IQueryContext context,
IExecutionResult result)
{
_events.Add("bar");
}
}
}
}