public static Task <List <EntityT> > GetPageAsync <EntityT>(this ICrudAsync <EntityT> crud, int after, int take) where EntityT : class { return(crud.Query() .Skip(after) .Take(take) .ToListAsync()); }
public CrudRootResolver(ICrudAsync <TResolveEntity> crud) { this._crud = crud; // id: ID! base.Add(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", Description = "Get by ID" }); }
/// <summary> /// This is a helper method for resolvers to resolve an entity via an <see cref="ICrudAsync"/> /// </summary> /// <param name="context">The GraphQL context. Used to access parameters.</param> /// <param name="crud">The <see cref="ICrudAsync{EntityT}"/> used to resolve the entity.</param> /// <param name="idParamName">The name of the GraphQL parameter containing the entity's ID. Defaults to 'id'.</param> /// <param name="policy">The ASP Core policy that the user must pass in order to access this function.</param> /// <param name="userContext">Used to gain access to the user performing this action.</param> protected async Task <object> ResolveCrudAsync( string policy, ICrudAsync <TResolveEntity> crud, IResolveFieldContext <object> context, DataAccessUserContext userContext, string idParamName = "id" ) { await userContext.EnforceHasPolicyAsync(policy); // ARGS var id = context.GetArgument <int>(idParamName); // Find the entity var entity = await crud.GetByIdAsync(id); if (!entity.Succeeded) { throw new ExecutionError(entity.GatherErrorMessages().Aggregate((a, b) => $"{a}\n{b}")); } return(entity.Value); }