public async Task <IPreProcessedOffsetPageResults <ICharacter> > GetCharactersWithOffsetPagingAsync(
            [Service] ICharacterRepository repository,
            //THIS is now injected by Pre-Processed extensions middleware...
            [GraphQLParams] IParamsContext graphQLParams
            )
        {
            var repoDbParams = new GraphQLRepoDbMapper <CharacterDbModel>(graphQLParams);

            //********************************************************************************
            //Get the data from the database via our lower level data access repository class.
            //NOTE: Selections (e.g. Projections), SortFields, PagingArgs are all pushed
            //       down to the Repository (and underlying Database) layer.
            var charactersPage = await repository.GetOffsetPagedCharactersAsync(
                repoDbParams.GetSelectFields(),
                repoDbParams.GetSortOrderFields(),
                repoDbParams.GetOffsetPagingParameters()
                );

            //With a valid Page/Slice we can return a PreProcessed Cursor Result so that
            //  it will not have additional post-processing in the HotChocolate pipeline!
            //NOTE: Filtering can be applied but ONLY to the results we are now returning;
            //       Because this would normally be pushed down to the Sql Database layer.
            return(charactersPage.AsPreProcessedPageResults());
            //********************************************************************************
        }
        public async Task <PreProcessedCursorSlice <Droid> > GetDroidsPaginatedAsync(
            [Service] ICharacterRepository repository,
            //THIS is now injected by Pre-Processed extensions middleware...
            [GraphQLParams] IParamsContext graphQLParams
            )
        {
            var repoDbParams = new GraphQLRepoDbMapper <CharacterDbModel>(graphQLParams);

            //********************************************************************************
            //Get the data and convert to List() to ensure it's an Enumerable
            //  and no longer using IQueryable to successfully simulate
            //  pre-processed results.
            //NOTE: Selections (e.g. Projections), SortFields, PagingArgs are all pushed
            //       down to the Repository (and underlying Database) layer.
            var charactersSlice = await repository.GetPagedDroidCharactersAsync(
                repoDbParams.GetSelectFields(),
                repoDbParams.GetSortOrderFields() ?? OrderField.Parse(new { Name = Order.Ascending }),
                repoDbParams.GetCursorPagingParameters()
                );

            //With a valid Page/Slice we can return a PreProcessed Cursor Result so that
            //  it will not have additional post-processing in the HotChocolate pipeline!
            //NOTE: Filtering can be applied but ONLY to the results we are now returning;
            //       Because this would normally be pushed down to the Sql Database layer.
            return(charactersSlice.AsPreProcessedCursorSlice());
            //********************************************************************************
        }
Example #3
0
        public IEnumerable <Review> GetReviews(
            Episode episode,
            [Service] IReviewRepository repository,
            //THIS is now injected by Pre-Processed extensions middleware...
            [GraphQLParams] IParamsContext graphQLParams
            )
        {
            //********************************************************************************
            //Get the data and convert to List() to ensure it's an Enumerable
            //  and no longer using IQueryable to successfully simulate
            //  pre-processed results.
            var reviews = repository.GetReviews(episode).ToList();

            //Perform some pre-processed Sorting & Then Paging!
            //This could be done in a lower repository or pushed to the Database!
            var sortedReviews = reviews.SortDynamically(graphQLParams.SortArgs);
            var slicedreviews = sortedReviews.SliceAsCursorPage(graphQLParams.PagingArgs);

            //With a valid Page/Slice we can return a PreProcessed Cursor Result so that
            //  it will not have additional post-processing in the HotChocolate pipeline!
            //NOTE: Filtering will be applied but ONLY to the results we are now returning;
            //       Because this would normally be pushed down to the Sql Database layer.
            return(new PreProcessedCursorSlice <Review>(slicedreviews));
            //********************************************************************************
        }
Example #4
0
 public HtmlExporter(
     IFlashcardsFormatterResolver flashcardsFormatterResolver,
     ILoggerFactory loggerFactory,
     IParamsContext paramsContext)
 {
     this.flashcardsFormatterResolver = flashcardsFormatterResolver;
     this.logger        = loggerFactory.CreateLogger <HtmlExporter>();
     this.paramsContext = paramsContext;
 }
 public FlashcardsTranslator(
     IFlashcardsTranslatorResolver flashcardsTranslatorResolver,
     ILoggerFactory loggerFactory,
     IParamsContext paramsContext)
 {
     this.flashcardsTranslatorResolver = flashcardsTranslatorResolver;
     this.logger        = loggerFactory.CreateLogger <FlashcardsTranslator>();
     this.paramsContext = paramsContext;
 }
        /// <summary>
        /// Gets all Characters for the specified Id values.
        /// </summary>
        /// <param name="ids">The ids of the human to retrieve.</param>
        /// <param name="repository"></param>
        /// <returns>The character.</returns>
        public async Task <IEnumerable <ICharacter> > GetCharactersByIdAsync(
            [Service] ICharacterRepository repository,
            [GraphQLParams] IParamsContext graphQLParams,
            int[] ids
            )
        {
            var repoDbParams = new GraphQLRepoDbMapper <CharacterDbModel>(graphQLParams);
            var characters   = await repository.GetCharactersByIdAsync(repoDbParams.GetSelectFields(), ids);

            return(characters);
        }
        public Task <IEnumerable <StarWarsDroid> > GetDroidsAsync(
            [Parent] StarWarsHuman character,
            [GraphQLParams] IParamsContext graphQLParams
            )
        {
            #if DEBUG
            Debug.WriteLine($"Pre-processing Dependency Fields: [{string.Join(", ", graphQLParams.SelectionDependencies.Select(d => d.DependencyMemberName))}]");
            #endif

            var allDroids = StarWarsCharacterRepo.CreateCharacters().OfType <StarWarsDroid>().ToLookup(d => d.Id);
            var droids    = character.DroidIds.Select(droidId => allDroids[droidId].FirstOrDefault());
            return(Task.FromResult(droids));
        }
Example #8
0
        public Task <PreProcessedOffsetPageResults <IStarWarsCharacter> > GetStarWarsCharactersWithOffsetPagingAsync(
            [GraphQLParams] IParamsContext paramsContext,
            bool testEmptyResults = false
            )
        {
            var characters = testEmptyResults
                ? Enumerable.Empty <IStarWarsCharacter>()
                : StarWarsCharacterRepo.CreateCharacters();

            var results = characters.SliceAsOffsetPage(paramsContext.OffsetPagingArgs);

            return(Task.FromResult(results.AsPreProcessedPageResults()));
        }
        public async Task <IEnumerable <ICharacter> > GetAllCharactersAsync(
            [Service] ICharacterRepository repository,
            [GraphQLParams] IParamsContext graphQLParams
            )
        {
            var repoDbParams = new GraphQLRepoDbMapper <CharacterDbModel>(graphQLParams);

            var sortedCharacters = await repository.GetAllSortedCharactersAsync(
                selectFields : repoDbParams.GetSelectFields(),
                sortFields : repoDbParams.GetSortOrderFields()
                );

            return(sortedCharacters.AsPreProcessedSortResults());
        }
        public async Task <IEnumerable <Droid> > GetDroidsAsync(
            [Service] ICharacterRepository repository,
            [Parent] ICharacter character,
            [GraphQLParams] IParamsContext graphQLParams
            )
        {
            #if DEBUG
            Debug.WriteLine($"Pre-processing Dependency Fields: [{string.Join(", ", graphQLParams.SelectionDependencies.Select(d => d.DependencyMemberName))}]");
            #endif

            var friends = await repository.GetCharacterFriendsAsync(character.Id);

            var droids = friends.OfType <Droid>();
            return(droids);
        }
Example #11
0
 public ParamsContextTestHarness(IParamsContext paramsContext)
 {
     //BBernard
     //THIS will force initialization of all data for Test cases
     //  to then have access to even if out of scope, since we have our own
     //  references here!
     this.ResolverContext        = paramsContext.ResolverContext;
     this.AllArgumentSchemaNames = paramsContext.AllArgumentSchemaNames;
     this.AllArguments           = paramsContext.AllArguments;
     this.AllSelectionFields     = paramsContext.AllSelectionFields;
     this.AllSelectionNames      = paramsContext.AllSelectionNames;
     this.SelectionDependencies  = paramsContext.SelectionDependencies;
     this.SortArgs              = paramsContext.SortArgs;
     this.PagingArgs            = paramsContext.PagingArgs;
     this.CursorPagingArgs      = paramsContext.CursorPagingArgs;
     this.OffsetPagingArgs      = paramsContext.OffsetPagingArgs;
     this.TotalCountSelection   = paramsContext.TotalCountSelection;
     this.IsTotalCountRequested = paramsContext.IsTotalCountRequested;
 }
Example #12
0
 public GraphQLRepoDbMapper(IParamsContext graphQLParams)
 {
     this.GraphQLParamsContext = graphQLParams;
 }