forked from Quramy/graphql-decorator
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding functional tests and some fixes
- Loading branch information
1 parent
3f012fb
commit 25b3235
Showing
10 changed files
with
263 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'reflect-metadata'; | ||
|
||
import { FieldMetadata } from './metadata'; | ||
import { PageInfo } from './page-info.type'; | ||
import { PaginationResponse } from './pagination.type'; | ||
import { getMetadataBuilder } from './metadata-builder'; | ||
|
||
export function PaginationMiddleware(target: any, propertyKey: string, methodDescriptor: TypedPropertyDescriptor<any>): any { | ||
return { | ||
value: async function (...args: any[]) { | ||
let [data, count] = await methodDescriptor.value.apply(this, args); | ||
|
||
return getMetadataBuilder().buildFieldMetadata(target) | ||
.filter(metadata => metadata.property === propertyKey) | ||
.map(metadata => metadata.arguments) | ||
.map(fieldArguments => { | ||
const paginationValues = fieldArguments | ||
.reduce((indexMap, metadata) => { | ||
indexMap[metadata.name] = metadata.index; | ||
return indexMap; | ||
}, {} as { [name: string]: number; }); | ||
return new PaginationResponse(count, data, new PageInfo(count, paginationValues['offset'], paginationValues['limit'])); | ||
}) | ||
.find((_, index) => index === 0); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.