|
2 | 2 | /* eslint-disable no-param-reassign, no-use-before-define */ |
3 | 3 |
|
4 | 4 | import { Resolver, TypeComposer } from 'graphql-compose'; |
5 | | -import type { |
6 | | - ResolveParams, |
7 | | - ConnectionResolveParams, |
8 | | - ComposeWithConnectionOpts, |
9 | | - ConnectionSortOpts, |
10 | | - ConnectionSortMapOpts, |
11 | | - GraphQLConnectionType, |
12 | | -} from './definition'; |
| 5 | +import type { ResolveParams, ProjectionType } from 'graphql-compose'; |
| 6 | +import type { GraphQLResolveInfo } from 'graphql-compose/lib/graphql'; |
13 | 7 | import { prepareConnectionType } from './types/connectionType'; |
14 | 8 | import { prepareSortType } from './types/sortInputType'; |
15 | 9 | import CursorType from './types/cursorType'; |
16 | | -import { cursorToData, dataToCursor } from './cursor'; |
| 10 | +import { cursorToData, dataToCursor, type CursorDataType } from './cursor'; |
| 11 | +import type { ComposeWithConnectionOpts } from './composeWithConnection'; |
| 12 | + |
| 13 | +export type ConnectionSortOpts = { |
| 14 | + value: any, |
| 15 | + cursorFields: string[], |
| 16 | + beforeCursorQuery: ( |
| 17 | + rawQuery: any, |
| 18 | + cursorData: CursorDataType, |
| 19 | + resolveParams: ConnectionResolveParams<*, *> |
| 20 | + ) => any, |
| 21 | + afterCursorQuery: ( |
| 22 | + rawQuery: any, |
| 23 | + cursorData: CursorDataType, |
| 24 | + resolveParams: ConnectionResolveParams<*, *> |
| 25 | + ) => any, |
| 26 | +}; |
| 27 | + |
| 28 | +export type ConnectionSortMapOpts = { |
| 29 | + [sortName: string]: ConnectionSortOpts, |
| 30 | +}; |
| 31 | + |
| 32 | +export type ConnectionResolveParams<TSource, TContext> = { |
| 33 | + source: TSource, |
| 34 | + args: { |
| 35 | + first?: ?number, |
| 36 | + after?: string, |
| 37 | + last?: ?number, |
| 38 | + before?: string, |
| 39 | + sort?: ConnectionSortOpts, |
| 40 | + filter?: { [fieldName: string]: any }, |
| 41 | + [argName: string]: any, |
| 42 | + }, |
| 43 | + context: TContext, |
| 44 | + info: GraphQLResolveInfo, |
| 45 | + projection: $Shape<ProjectionType>, |
| 46 | + [opt: string]: any, |
| 47 | +}; |
| 48 | + |
| 49 | +export type ConnectionType = { |
| 50 | + count: number, |
| 51 | + edges: ConnectionEdgeType[], |
| 52 | + pageInfo: PageInfoType, |
| 53 | +}; |
| 54 | + |
| 55 | +export type ConnectionEdgeType = { |
| 56 | + cursor: string, |
| 57 | + node: mixed, |
| 58 | +}; |
| 59 | + |
| 60 | +export type PageInfoType = { |
| 61 | + startCursor: string, |
| 62 | + endCursor: string, |
| 63 | + hasPreviousPage: boolean, |
| 64 | + hasNextPage: boolean, |
| 65 | +}; |
17 | 66 |
|
18 | 67 | export function prepareConnectionResolver<TSource, TContext>( |
19 | 68 | typeComposer: TypeComposer, |
@@ -326,7 +375,7 @@ export function prepareLimitSkipFallback( |
326 | 375 | return [newLimit, newSkip]; |
327 | 376 | } |
328 | 377 |
|
329 | | -export function emptyConnection(): GraphQLConnectionType { |
| 378 | +export function emptyConnection(): ConnectionType { |
330 | 379 | return { |
331 | 380 | count: 0, |
332 | 381 | edges: [], |
|
0 commit comments