public Task <IEnumerable <Human> > GetHumansAsync(SkipTakeOrderByArgument skipTakeArgs) { var query = _humans.AsQueryable(); if (!string.IsNullOrEmpty(skipTakeArgs.OrderBy)) { query = query.OrderBy(skipTakeArgs.OrderBy); } else if (!string.IsNullOrEmpty(skipTakeArgs.OrderByDesc)) { query = query.OrderBy($"{skipTakeArgs.OrderByDesc} descending"); } else { if (skipTakeArgs.Skip != null || skipTakeArgs.Take != null) { query = query.OrderBy(x => x.Id); } } if (skipTakeArgs.Skip != null) { query = query.Skip(skipTakeArgs.Skip.Value); } if (skipTakeArgs.Take != null) { query = query.Take(skipTakeArgs.Take.Value); } return(Task.FromResult(query.ToList().AsEnumerable())); }
public StarWarsQuery(StarWarsData data) { Name = "Query"; Field <CharacterInterface>("hero", resolve: context => data.GetDroidByIdAsync("3")); Field <HumanType>( "human", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the human" } ), resolve: context => data.GetHumanByIdAsync(context.GetArgument <string>("id"))); Field <ListGraphType <HumanType> >( "humans", arguments: new QueryArguments(DefaultQueryArguments.SkipTakeOrderByArguments <HumanType>()), resolve: context => data.GetHumansAsync(SkipTakeOrderByArgument.Parse(context)) ); Func <IResolveFieldContext, string, object> func = (context, id) => data.GetDroidByIdAsync(id); FieldDelegate <DroidType>( "droid", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the droid" } ), resolve: func ); }