Skip to content

Commit

Permalink
Add test to demonstrate issue graphql-dotnet#268
Browse files Browse the repository at this point in the history
  • Loading branch information
floge07 committed Jan 7, 2025
1 parent f823574 commit e38bcf0
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/GraphQL.Conventions.Tests/Execution/SchemaExecutionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using GraphQL.Conventions;
using GraphQL.NewtonsoftJson;
using Tests.Templates;
using Tests.Templates.Extensions;
Expand Down Expand Up @@ -29,5 +31,72 @@ private class QueryTypeWithDecimal
{
public decimal Test => 10;
}

[Test]
public async Task Test_NonNull_Validation()
{
string query = @"
query {
test {
children {
field(problematic: [""1"", ""2""])
}
}
}
";

var engine = GraphQLEngine.New();

engine.WithQuery<NonNullTests.QueryType>();

var executor = engine
.NewExecutor()
.WithQueryString(query);

var result1 = await executor.ExecuteAsync();
System.Diagnostics.Debug.WriteLine(new GraphQLSerializer(indent: true).Serialize(result1));


var schema = Schema<NonNullTests>();
schema.ShouldHaveQueries(1);
schema.ShouldHaveMutations(0);
schema.Query.ShouldHaveFieldWithName("test");

var result2 = await schema.ExecuteAsync((e) => e.Query = query);
System.Diagnostics.Debug.WriteLine(result2);
ResultHelpers.AssertNoErrorsInResult(result2);
}

public class NonNullTests
{
public QueryType Query { get; }

public class QueryType
{
public NonNull<DataType> test()
{
return new DataType()
{
children = new List<NonNull<DataType>> {
new DataType(),
new DataType()
}
};
}

public class DataType
{
public NonNull<List<NonNull<DataType>>> children { get; set; }

public List<NonNull<string>> field(NonNull<List<string>> problematic)
{
return new List<NonNull<string>> {
new NonNull<string>("ab"),
new NonNull<string>("cd")
};
}
}
}
}
}
}

0 comments on commit e38bcf0

Please sign in to comment.