Skip to content

Commit 0aad85b

Browse files
committed
Improve Schema Error Details
1 parent 548b5f2 commit 0aad85b

6 files changed

Lines changed: 614 additions & 5 deletions

File tree

src/HotChocolate/Core/src/Types/Configuration/TypeDiscoverer.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Globalization;
2+
using System.Text;
13
using HotChocolate.Properties;
24
using HotChocolate.Types;
35
using HotChocolate.Types.Descriptors;
@@ -238,22 +240,46 @@ private void CollectErrors()
238240

239241
if (_errors.Count == 0 && _typeRegistrar.Unresolved.Count > 0)
240242
{
241-
foreach (var unresolvedReference in _typeRegistrar.Unresolved)
243+
var message = new StringBuilder();
244+
245+
// the unresolved references are stored in an unordered set, so we order
246+
// them deterministically to keep the produced error sequence stable.
247+
foreach (var unresolvedReference in
248+
_typeRegistrar.Unresolved.OrderBy(r => r.ToString(), StringComparer.Ordinal))
242249
{
243250
var types = _typeRegistry.Types.Where(
244251
t => t.Dependencies.Select(d => d.Type)
245252
.Any(r => r.Equals(unresolvedReference))).ToList();
246253

254+
var path = TypeInferencePathBuilder.Build(_typeRegistry, unresolvedReference);
255+
256+
message.Clear();
257+
258+
message.AppendFormat(
259+
CultureInfo.InvariantCulture,
260+
TypeResources.TypeRegistrar_TypesInconsistent,
261+
unresolvedReference);
262+
263+
if (path.HasValue)
264+
{
265+
message.Append(Environment.NewLine);
266+
message.Append(Environment.NewLine);
267+
message.Append(path.Value.Short);
268+
}
269+
247270
var builder =
248271
SchemaErrorBuilder.New()
249-
.SetMessage(
250-
TypeResources.TypeRegistrar_TypesInconsistent,
251-
unresolvedReference)
272+
.SetMessage(message.ToString())
252273
.SetExtension(
253274
TypeErrorFields.Reference,
254275
unresolvedReference)
255276
.SetCode(ErrorCodes.Schema.UnresolvedTypes);
256277

278+
if (path.HasValue)
279+
{
280+
builder.SetExtension(TypeErrorFields.Path, path.Value.Expanded);
281+
}
282+
257283
if (types.Count == 1)
258284
{
259285
builder.SetTypeSystemObject(types[0].Type);

0 commit comments

Comments
 (0)