Skip to content

Commit 63d758b

Browse files
authored
Merge pull request graphql-dotnet#439 from graphql-dotnet/issuefixes
2.0 Issue Fixes
2 parents e40db5d + 661bc31 commit 63d758b

File tree

13 files changed

+210
-66
lines changed

13 files changed

+210
-66
lines changed

src/GraphQL.Tests/Errors/ErrorLocationTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,40 @@ public async Task should_show_location_when_exception_thrown_with_async_field(st
4949
location.Column.ShouldBe(column);
5050
}
5151

52+
[Fact]
53+
public async Task should_include_path()
54+
{
55+
var result = await Executer.ExecuteAsync(_ =>
56+
{
57+
_.Schema = Schema;
58+
_.Query = @"{ testSub { one two } }";
59+
});
60+
61+
result.Errors.Count.ShouldBe(1);
62+
var error = result.Errors.First();
63+
error.Path.ShouldBe(new[] {"testSub", "two"});
64+
}
65+
66+
[Fact]
67+
public async Task should_include_path_with_list_index()
68+
{
69+
var result = await Executer.ExecuteAsync(_ =>
70+
{
71+
_.Schema = Schema;
72+
_.Query = @"{ testSubList { one two } }";
73+
});
74+
75+
result.Errors.Count.ShouldBe(1);
76+
var error = result.Errors.First();
77+
error.Path.ShouldBe(new[] {"testSubList", "0", "two"});
78+
}
79+
5280
[Fact]
5381
public void async_field_with_errors()
5482
{
5583
var error = new ExecutionError("Error trying to resolve testasync.");
5684
error.AddLocation(1, 3);
85+
error.Path = new[] {"testasync"};
5786

5887
var errors = new ExecutionErrors {error};
5988

@@ -79,6 +108,34 @@ public TestQuery()
79108
FieldAsync<StringGraphType>(
80109
"testasync",
81110
resolve: async _ => throw new Exception("wat"));
111+
112+
Field<TestSubObject>()
113+
.Name("testSub")
114+
.Resolve(_ => new {One = "One", Two = "Two"});
115+
116+
Field<ListGraphType<TestSubObject>>()
117+
.Name("testSubList")
118+
.Resolve(_ => new[] {new Thing {One = "One", Two = "Two"}});
119+
}
120+
}
121+
122+
public class Thing
123+
{
124+
public string One { get; set; }
125+
public string Two { get; set; }
126+
}
127+
128+
public class TestSubObject : ObjectGraphType
129+
{
130+
public TestSubObject()
131+
{
132+
Name = "Sub";
133+
Field<StringGraphType>()
134+
.Name("one");
135+
136+
Field<StringGraphType>()
137+
.Name("two")
138+
.Resolve(_ => throw new Exception("wat"));
82139
}
83140
}
84141

src/GraphQL.Tests/Execution/RegisteredInstanceTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public void build_nested_type_with_list()
7979
query: root
8080
}
8181
82+
# The `Date` scalar type represents a timestamp provided in UTC. `Date` expects
83+
# timestamps to be formatted in accordance with the
84+
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
85+
scalar Date
86+
87+
scalar Decimal
88+
8289
type NestedObjType {
8390
intField: Int
8491
}
@@ -96,6 +103,13 @@ public void build_nested_type_with_non_null()
96103
query: root
97104
}
98105
106+
# The `Date` scalar type represents a timestamp provided in UTC. `Date` expects
107+
# timestamps to be formatted in accordance with the
108+
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
109+
scalar Date
110+
111+
scalar Decimal
112+
99113
type NestedObjType {
100114
intField: Int
101115
}
@@ -113,6 +127,13 @@ public void build_nested_type_with_base()
113127
query: root
114128
}
115129
130+
# The `Date` scalar type represents a timestamp provided in UTC. `Date` expects
131+
# timestamps to be formatted in accordance with the
132+
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
133+
scalar Date
134+
135+
scalar Decimal
136+
116137
type NestedObjType {
117138
intField: Int
118139
}

src/GraphQL.Tests/Subscription/SubscriptionTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reactive.Linq;
@@ -112,7 +112,9 @@ public async Task OnError()
112112
message.ShouldNotBeNull();
113113
message.ShouldBeOfType<ExecutionResult>();
114114
message.Data.ShouldBeNull();
115-
message.Errors.ShouldContain(error => error.InnerException.Message == "test");
115+
var error = message.Errors.Single();
116+
error.InnerException.Message.ShouldBe("test");
117+
error.Path.ShouldBe(new[] {"messageAdded"});
116118
}
117119
}
118120
}

src/GraphQL.Tests/Utilities/SchemaPrinterTests.cs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ namespace GraphQL.Tests.Utilities
1212
{
1313
public class SchemaPrinterTests
1414
{
15+
private const string built_in_scalars = @"
16+
# The `Date` scalar type represents a timestamp provided in UTC. `Date` expects
17+
# timestamps to be formatted in accordance with the
18+
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
19+
scalar Date
20+
21+
scalar Decimal
22+
";
23+
1524
private string printSingleFieldSchema<T>(
1625
IEnumerable<QueryArgument> arguments = null)
1726
where T : GraphType
@@ -26,13 +35,12 @@ private string printSingleFieldSchema<T>(
2635

2736
var schema = new Schema
2837
{
29-
Query = root,
30-
// FieldNameConverter = new PascalCaseFieldNameConverter()
38+
Query = root
3139
};
3240

3341
var result = print(schema);
3442

35-
// ensure schema isn't disposed
43+
// ensure schema isn't disposed before test finishes
3644
if (schema.Query.Name == "")
3745
{
3846
}
@@ -46,9 +54,10 @@ private string print(ISchema schema)
4654
return Environment.NewLine + printer.Print();
4755
}
4856

49-
private void AssertEqual(string result, string expected)
57+
private void AssertEqual(string result, string expected, bool excludeScalars = false)
5058
{
51-
result.Replace("\r", "").ShouldBe(expected.Replace("\r", ""));
59+
var exp = excludeScalars ? expected : built_in_scalars + expected;
60+
result.Replace("\r", "").ShouldBe(exp.Replace("\r", ""));
5261
}
5362

5463
[Fact]
@@ -64,7 +73,7 @@ directive @skip(
6473
if: Boolean!
6574
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT";
6675

67-
AssertEqual(result, expected);
76+
AssertEqual(result, expected, excludeScalars: true);
6877
}
6978

7079
[Fact]
@@ -289,14 +298,21 @@ type Bar implements Foo {
289298
str: String
290299
}
291300
301+
# The `Date` scalar type represents a timestamp provided in UTC. `Date` expects
302+
# timestamps to be formatted in accordance with the
303+
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
304+
scalar Date
305+
306+
scalar Decimal
307+
292308
interface Foo {
293309
str: String
294310
}
295311
296312
type Root {
297313
bar: Bar
298314
}
299-
");
315+
", excludeScalars: true);
300316
}
301317

302318
[Fact]
@@ -316,14 +332,21 @@ interface Baaz {
316332
str: String
317333
}
318334
335+
# The `Date` scalar type represents a timestamp provided in UTC. `Date` expects
336+
# timestamps to be formatted in accordance with the
337+
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
338+
scalar Date
339+
340+
scalar Decimal
341+
319342
interface Foo {
320343
str: String
321344
}
322345
323346
type Query {
324347
bar: Bar
325348
}
326-
");
349+
", excludeScalars: true);
327350
}
328351

329352
[Fact]
@@ -340,6 +363,13 @@ type Bar implements Foo {
340363
str: String
341364
}
342365
366+
# The `Date` scalar type represents a timestamp provided in UTC. `Date` expects
367+
# timestamps to be formatted in accordance with the
368+
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
369+
scalar Date
370+
371+
scalar Decimal
372+
343373
interface Foo {
344374
str: String
345375
}
@@ -352,7 +382,7 @@ type Query {
352382
}
353383
354384
union SingleUnion = Foo
355-
");
385+
", excludeScalars: true);
356386
}
357387

358388
[Fact]
@@ -561,7 +591,7 @@ enum __TypeKind {
561591
}
562592
";
563593

564-
AssertEqual(result, expected);
594+
AssertEqual(result, expected, excludeScalars: true);
565595
}
566596

567597
public class FooType : ObjectGraphType

src/GraphQL/EnumerableExtensions.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -28,6 +28,19 @@ public static Task<object[]> MapAsync(this IEnumerable items, Func<object, Task<
2828
return Task.WhenAll(tasks);
2929
}
3030

31+
public static async Task<object[]> MapAsync(this IEnumerable enumerable, Func<int, object, Task<object>> mapFunction)
32+
{
33+
return await enumerable
34+
.Cast<object>()
35+
.Select((item, index) => Tuple.Create(index, item))
36+
.MapAsync(async tuple =>
37+
{
38+
var data = (Tuple<int, object>)tuple;
39+
return await mapFunction(data.Item1, data.Item2).ConfigureAwait(false);
40+
})
41+
.ConfigureAwait(false);
42+
}
43+
3144
public static void Apply<T>(this IEnumerable<T> items, Action<T> action)
3245
{
3346
foreach (var item in items)

0 commit comments

Comments
 (0)