Skip to content

Commit

Permalink
landmarkhw#17 - allow customization of selection set in context.Next()
Browse files Browse the repository at this point in the history
  • Loading branch information
dougrday committed May 18, 2018
1 parent 702377d commit 550d7a8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Dapper.GraphQL/Contexts/EntityMapContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public TEntityType Start<TEntityType>()
/// <param name="fieldNames">The names of one or more GraphQL fields associated with the item.</param>
/// <param name="entityMapper">An optional entity mapper. This is used to map complex objects from Dapper mapping results.</param>
/// <returns>The mapped item.</returns>
public TItemType Next<TItemType>(IEnumerable<string> fieldNames, IEntityMapper<TItemType> entityMapper = null)
public TItemType Next<TItemType>(
IEnumerable<string> fieldNames,
IEntityMapper<TItemType> entityMapper = null,
Func<IHaveSelectionSet, IHaveSelectionSet> selectionSetSelector = null)
where TItemType : class
{
if (fieldNames == null)
Expand Down Expand Up @@ -111,10 +114,21 @@ public TItemType Next<TItemType>(IEnumerable<string> fieldNames, IEntityMapper<T

if (entityMapper != null)
{
// Determine where the next entity mapper will get its selection set from
IHaveSelectionSet selectionSet = null;
if (selectionSetSelector == null)
{
selectionSet = selectionSetSelector(SelectionSet);
}
else
{
selectionSet = CurrentSelectionSet[keys.First()];
}

var nextContext = new EntityMapContext
{
Items = Items.Skip(MappedCount),
SelectionSet = CurrentSelectionSet[keys.First()],
SelectionSet = selectionSet,
SplitOn = SplitOn.Skip(MappedCount),
};
using (nextContext)
Expand Down

0 comments on commit 550d7a8

Please sign in to comment.