Skip to content

Commit

Permalink
Still fails but adds initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Oct 12, 2023
1 parent 433b6a1 commit 530ee49
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using CookieCrumble;
using HotChocolate.Configuration;
using HotChocolate.Execution;
using HotChocolate.Types.Descriptors;
using HotChocolate.Types.Descriptors.Definitions;
using HotChocolate.Types.Relay;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -28,7 +26,23 @@ public async Task SimpleMutation_Inferred()

schema.MatchSnapshot();
}

[Fact]
public async Task SimpleMutation_Inferred_Global_Errors()
{
var schema =
await new ServiceCollection()
.AddGraphQL()
.AddMutationType<SimpleMutation>()
.AddMutationConventions(
new MutationConventionOptions { ApplyToAllMutations = true })
.TryAddTypeInterceptor<ErrorInterceptor>()
.ModifyOptions(o => o.StrictValidation = false)
.BuildSchemaAsync();

schema.MatchSnapshot();
}

[Fact]
public async Task SimpleMutation_Inferred_Query_Field_Stays_NonNull()
{
Expand Down Expand Up @@ -1397,4 +1411,18 @@ public DoSomething2Payload DoSomething2(int? userId)
}

public record DoSomething2Payload(int? UserId);

public record SomeNewError(string Message);

public class ErrorInterceptor : TypeInterceptor
{
public override void OnBeforeCompleteMutationField(
ITypeCompletionContext completionContext,
ObjectFieldDefinition mutationField)
{
mutationField.AddErrorType(
completionContext.DescriptorContext,
typeof(SomeNewError));
}
}
}

0 comments on commit 530ee49

Please sign in to comment.