Skip to content

Commit

Permalink
Add CancellationToken support in async methods
Browse files Browse the repository at this point in the history
Async methods in the GraphCursorPager and GraphCursorQueryExecute classes have been updated to support CancellationToken.
  • Loading branch information
Magnus Ahlberg committed Feb 2, 2024
1 parent fff3d17 commit ee426c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/Linq2GraphQL.Client/GraphCursorPager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ public GraphCursorPager(GraphCursorQueryExecute<T, TResult> graphCursorQueryExec
return this;
}

private async Task<TResult> ExecutePagerAsync()
private async Task<TResult> ExecutePagerAsync(CancellationToken cancellationToken = default)
{
var baseType = await query.ExecuteBaseAsync();
var baseType = await query.ExecuteBaseAsync(cancellationToken);
return query.ConvertResult(baseType);
}

public async Task<TResult> NextPageAsync()
public async Task<TResult> NextPageAsync(CancellationToken cancellationToken = default)
{
query.QueryNode.SetArgumentValue("after", query.BaseResult?.PageInfo?.EndCursor);
query.QueryNode.SetArgumentValue("before", null);
return await ExecutePagerAsync();
return await ExecutePagerAsync(cancellationToken);
}

public async Task<TResult> PreviousPageAsync()
public async Task<TResult> PreviousPageAsync(CancellationToken cancellationToken = default)
{
query.QueryNode.SetArgumentValue("after", null);
query.QueryNode.SetArgumentValue("before", query.BaseResult?.PageInfo?.EndCursor);
return await ExecutePagerAsync();
return await ExecutePagerAsync(cancellationToken);
}
}
9 changes: 4 additions & 5 deletions src/Linq2GraphQL.Client/GraphQueryExecute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

namespace Linq2GraphQL.Client;


public class GraphCursorQueryExecute<T, TResult> : GraphQueryExecute<T, TResult> where T : ICursorPaging
{
public GraphCursorQueryExecute(GraphClient client, OperationType operationType, QueryNode queryNode, Expression<Func<T, TResult>> selector) : base(client, operationType, queryNode, selector)
{ }
public GraphCursorQueryExecute(GraphClient client, OperationType operationType, QueryNode queryNode,
Expression<Func<T, TResult>> selector) : base(client, operationType, queryNode, selector) { }

public GraphCursorPager<T, TResult> AsPager()
{
Expand All @@ -24,13 +23,13 @@ public class GraphQueryExecute<T, TResult> : GraphBaseExecute<T, TResult>

public async Task<T> ExecuteBaseAsync(CancellationToken cancellationToken = default)
{
BaseResult = await queryExecutor.ExecuteRequestAsync(QueryNode.Name, await GetRequestAsync(), cancellationToken);
BaseResult =
await queryExecutor.ExecuteRequestAsync(QueryNode.Name, await GetRequestAsync(), cancellationToken);
return BaseResult;
}

public async Task<TResult> ExecuteAsync(CancellationToken cancellationToken = default)
{
return ConvertResult(await ExecuteBaseAsync(cancellationToken));
}

}

0 comments on commit ee426c8

Please sign in to comment.