public void ValidateContext(IResolverContext context) { var first = context.ArgumentValue <int?>(CursorPagingArgumentNames.First); var last = AllowBackwardPagination ? context.ArgumentValue <int?>(CursorPagingArgumentNames.Last) : null; if (RequirePagingBoundaries && first is null && last is null) { throw ThrowHelper.PagingHandler_NoBoundariesSet( context.Selection.Field, context.Path); } if (first > MaxPageSize) { throw ThrowHelper.PagingHandler_MaxPageSize( (int)first, MaxPageSize, context.Selection.Field, context.Path); } if (last > MaxPageSize) { throw ThrowHelper.PagingHandler_MaxPageSize( (int)last, MaxPageSize, context.Selection.Field, context.Path); } }
/// <summary> /// Applies the offset pagination algorithm to the <paramref name="query"/>. /// </summary> /// <param name="query"> /// The query on which the the offset pagination algorithm shall be applied to. /// </param> /// <param name="context"> /// The field resolver context. /// </param> /// <param name="defaultPageSize"> /// The default page size if no boundaries are set. /// </param> /// <param name="totalCount"> /// The total count if already known. /// </param> /// <param name="cancellationToken"> /// The cancellation token. /// </param> /// <typeparam name="TEntity"> /// The entity type. /// </typeparam> /// <returns> /// Returns a collection segment instance that represents the result of applying the /// offset paging algorithm to the provided <paramref name="query"/>. /// </returns> public static ValueTask <CollectionSegment <TEntity> > ApplyOffsetPaginationAsync <TEntity>( this IQueryable <TEntity> query, IResolverContext context, int?defaultPageSize = null, int?totalCount = null, CancellationToken cancellationToken = default) { if (query is null) { throw new ArgumentNullException(nameof(query)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } var skip = context.ArgumentValue <int?>(OffsetPagingArgumentNames.Skip); var take = context.ArgumentValue <int?>(OffsetPagingArgumentNames.Take) ?? defaultPageSize; var arguments = new OffsetPagingArguments(skip, take); if (totalCount is null && context.IsTotalCountSelected()) { totalCount = query.Count(); } return(QueryableOffsetPagination <TEntity> .Instance.ApplyPaginationAsync( query, arguments, totalCount, cancellationToken)); }
public void ValidateContext(IResolverContext context) { int?first = context.ArgumentValue <int?>(CursorPagingArgumentNames.First); int?last = context.ArgumentValue <int?>(CursorPagingArgumentNames.Last); if (first > MaxPageSize || last > MaxPageSize) { throw ThrowHelper.ConnectionMiddleware_MaxPageSize(); } }
async ValueTask <IPage> IPagingHandler.SliceAsync( IResolverContext context, object source) { int?skip = context.ArgumentValue <int?>(OffsetPagingArgumentNames.Skip); int?take = context.ArgumentValue <int?>(OffsetPagingArgumentNames.Take); var arguments = new OffsetPagingArguments(skip, take ?? DefaultPageSize); return(await SliceAsync(context, source, arguments).ConfigureAwait(false)); }
/// <summary> /// Ensures that the arguments passed in by the user are valid and /// do not try to consume more items per page as specified by /// <see cref="MaxPageSize"/>. /// </summary> /// <param name="context"> /// The resolver context of the execution field. /// </param> public void ValidateContext(IResolverContext context) { int?take = context.ArgumentValue <int?>(OffsetPagingArgumentNames.Take); if (take > MaxPageSize) { throw ThrowHelper.OffsetPagingHandler_MaxPageSize(); } }
/// <summary> /// Applies the cursor pagination algorithm to the <paramref name="query"/>. /// </summary> /// <param name="query"> /// The query on which the the cursor pagination algorithm shall be applied to. /// </param> /// <param name="context"> /// The field resolver context. /// </param> /// <param name="defaultPageSize"> /// The default page size if no boundaries are set. /// </param> /// <param name="totalCount"> /// The total count if already known. /// </param> /// <param name="cancellationToken"> /// The cancellation token. /// </param> /// <typeparam name="TEntity"> /// The entity type. /// </typeparam> /// <returns> /// Returns a connection instance that represents the result of applying the /// cursor paging algorithm to the provided <paramref name="query"/>. /// </returns> public static ValueTask <Connection <TEntity> > ApplyCursorPaginationAsync <TEntity>( this IQueryable <TEntity> query, IResolverContext context, int?defaultPageSize = null, int?totalCount = null, CancellationToken cancellationToken = default) { if (query is null) { throw new ArgumentNullException(nameof(query)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } var first = context.ArgumentValue <int?>(CursorPagingArgumentNames.First); var last = context.ArgumentValue <int?>(CursorPagingArgumentNames.Last); if (totalCount is null && context.IsTotalCountSelected()) { totalCount = query.Count(); } if (first is null && last is null) { first = defaultPageSize; } var arguments = new CursorPagingArguments( first, last, context.ArgumentValue <string?>(CursorPagingArgumentNames.After), context.ArgumentValue <string?>(CursorPagingArgumentNames.Before)); return(QueryableCursorPagination <TEntity> .Instance.ApplyPaginationAsync( query, arguments, totalCount, cancellationToken)); }
async ValueTask <IPage> IPagingHandler.SliceAsync( IResolverContext context, object source) { int?first = context.ArgumentValue <int?>(CursorPagingArgumentNames.First); int?last = context.ArgumentValue <int?>(CursorPagingArgumentNames.Last); if (first is null && last is null) { first = DefaultPageSize; } var arguments = new CursorPagingArguments( first, last, context.ArgumentValue <string?>(CursorPagingArgumentNames.After), context.ArgumentValue <string?>(CursorPagingArgumentNames.Before)); return(await SliceAsync(context, source, arguments).ConfigureAwait(false)); }
/// <summary> /// Ensures that the arguments passed in by the user are valid and /// do not try to consume more items per page as specified by /// <see cref="MaxPageSize"/>. /// </summary> /// <param name="context"> /// The resolver context of the execution field. /// </param> public void ValidateContext(IResolverContext context) { var take = context.ArgumentValue <int?>(OffsetPagingArgumentNames.Take); if (RequirePagingBoundaries && take is null) { throw ThrowHelper.OffsetPagingHandler_NoBoundariesSet( context.Selection.Field, context.Path); } if (take > MaxPageSize) { throw ThrowHelper.OffsetPagingHandler_MaxPageSize( take.Value, MaxPageSize, context.Selection.Field, context.Path); } }
public string GetHello(string a, IResolverContext context) { return(a + context.ArgumentValue <string>("a")); }