Skip to content

Commit

Permalink
Added support for non-terminating errors (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Aug 31, 2018
1 parent ee40b5f commit a539208
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Core/Execution/Errors/QueryException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,35 @@ public class QueryException
public QueryException(string message)
: base(message)
{
Errors = ImmutableList<IQueryError>.Empty
.Add(new QueryError(message));
var errors = new List<IQueryError> { new QueryError(message) };
Errors = errors.AsReadOnly();
}

public QueryException(IQueryError error)
{
if (error == null)
{
Errors = ImmutableList<IQueryError>.Empty;
Errors = Array.Empty<IQueryError>();
}
else
{
Errors = ImmutableList<IQueryError>.Empty.Add(error);
var errors = new List<IQueryError> { error };
Errors = errors.AsReadOnly();
}
}

public QueryException(params IQueryError[] errors)
{
Errors = errors?.ToImmutableList()
?? ImmutableList<IQueryError>.Empty;
Errors = new List<IQueryError>(
errors ?? Array.Empty<IQueryError>())
.AsReadOnly();
}

public QueryException(IEnumerable<IQueryError> errors)
{
Errors = errors?.ToImmutableList()
?? ImmutableList<IQueryError>.Empty;
Errors = new List<IQueryError>(
errors ?? Array.Empty<IQueryError>())
.AsReadOnly();
}

protected QueryException(
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Execution/ResolverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,11 @@ public T Resolver<T>()
{
return _executionContext.GetResolver<T>();
}

public void ReportError(string errorMessage)
=> ReportError(new FieldError(errorMessage, FieldSelection));

public void ReportError(IQueryError error)
=> _executionContext.ReportError(error);
}
}
11 changes: 11 additions & 0 deletions src/Types/Resolvers/IResolverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,16 @@ public interface IResolverContext
/// Returns a resolver object containing one or more resolvers.
/// </returns>
T Resolver<T>();

/// <summary>
/// Report a non-terminating resolver error to the execution enhgine.
/// The error will be displayed in the errorsection with a reference to
/// the field selection that is associated with the current
/// resolver context.
/// </summary>
/// <param name="errorMessage">
/// The error message.
/// </param>
void ReportError(string errorMessage);
}
}

0 comments on commit a539208

Please sign in to comment.