|
| 1 | +using System.Globalization; |
| 2 | +using System.Text; |
1 | 3 | using HotChocolate.Properties; |
2 | 4 | using HotChocolate.Types; |
3 | 5 | using HotChocolate.Types.Descriptors; |
@@ -238,22 +240,46 @@ private void CollectErrors() |
238 | 240 |
|
239 | 241 | if (_errors.Count == 0 && _typeRegistrar.Unresolved.Count > 0) |
240 | 242 | { |
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)) |
242 | 249 | { |
243 | 250 | var types = _typeRegistry.Types.Where( |
244 | 251 | t => t.Dependencies.Select(d => d.Type) |
245 | 252 | .Any(r => r.Equals(unresolvedReference))).ToList(); |
246 | 253 |
|
| 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 | + |
247 | 270 | var builder = |
248 | 271 | SchemaErrorBuilder.New() |
249 | | - .SetMessage( |
250 | | - TypeResources.TypeRegistrar_TypesInconsistent, |
251 | | - unresolvedReference) |
| 272 | + .SetMessage(message.ToString()) |
252 | 273 | .SetExtension( |
253 | 274 | TypeErrorFields.Reference, |
254 | 275 | unresolvedReference) |
255 | 276 | .SetCode(ErrorCodes.Schema.UnresolvedTypes); |
256 | 277 |
|
| 278 | + if (path.HasValue) |
| 279 | + { |
| 280 | + builder.SetExtension(TypeErrorFields.Path, path.Value.Expanded); |
| 281 | + } |
| 282 | + |
257 | 283 | if (types.Count == 1) |
258 | 284 | { |
259 | 285 | builder.SetTypeSystemObject(types[0].Type); |
|
0 commit comments