Skip to content

Commit

Permalink
Include path in field context
Browse files Browse the repository at this point in the history
  • Loading branch information
tlil committed Aug 16, 2017
1 parent a431239 commit d7f05f0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public Task<Dictionary<string, object>> ExecuteFieldsAsync(ExecutionContext cont
public async Task<ResolveFieldResult<object>> ResolveFieldAsync(ExecutionContext context, IObjectGraphType parentType, object source, Fields fields, IEnumerable<string> path)
{
context.CancellationToken.ThrowIfCancellationRequested();
var fieldPath = path?.ToList() ?? new List<string>();

var resolveResult = new ResolveFieldResult<object>
{
Expand Down Expand Up @@ -306,6 +307,7 @@ public async Task<ResolveFieldResult<object>> ResolveFieldAsync(ExecutionContext
resolveContext.CancellationToken = context.CancellationToken;
resolveContext.Metrics = context.Metrics;
resolveContext.Errors = context.Errors;
resolveContext.Path.AddRange(fieldPath);

var resolver = fieldDefinition.Resolver ?? new NameFieldResolver();
var result = resolver.Resolve(resolveContext);
Expand All @@ -319,7 +321,7 @@ public async Task<ResolveFieldResult<object>> ResolveFieldAsync(ExecutionContext
var exception = aggregateException.InnerExceptions.Count == 1
? aggregateException.InnerException
: aggregateException;
return GenerateError(resolveResult, field, context, exception, path);
return GenerateError(resolveResult, field, context, exception, fieldPath);
}
await task.ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public async Task<object> Resolve(ResolveFieldContext context, FieldMiddlewareDe
{
{"typeName", context.ParentType.Name},
{"fieldName", context.FieldName},
{"path", context.Path},
{"arguments", context.Arguments},

};
Expand Down
2 changes: 2 additions & 0 deletions deps/graphql-dotnet/src/GraphQL/Types/ResolveFieldContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class ResolveFieldContext<TSource>

public ExecutionErrors Errors { get; set; }

public List<string> Path { get; private set; } = new List<string>();

public ResolveFieldContext() { }

public ResolveFieldContext(ResolveFieldContext context)
Expand Down
2 changes: 2 additions & 0 deletions src/GraphQL.Conventions/Adapters/ResolutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void SetArgument(string name, object value)

public CancellationToken CancellationToken => FieldContext.CancellationToken;

public IEnumerable<string> Path => FieldContext.Path;

public ResolveFieldContext FieldContext { get; private set; }
}
}
3 changes: 3 additions & 0 deletions src/GraphQL.Conventions/Execution/IResolutionContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading;
using GraphQL.Conventions.Types.Descriptors;
using GraphQL.Types;
Expand All @@ -24,6 +25,8 @@ public interface IResolutionContext

CancellationToken CancellationToken { get; }

IEnumerable<string> Path { get; }

ResolveFieldContext FieldContext { get; }
}
}

0 comments on commit d7f05f0

Please sign in to comment.