@pothos/plugin-relay
Advanced tools
Comparing version 4.1.0 to 4.2.0
# Change Log | ||
## 4.2.0 | ||
### Minor Changes | ||
- f3e8940: Add totalCount option to resolveOffsetConnection, which enables using `last` on offset and array connections without `before` | ||
## 4.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -10,2 +10,3 @@ import { type MaybePromise, type SchemaTypes } from '@pothos/core'; | ||
maxSize?: number; | ||
totalCount?: number; | ||
} | ||
@@ -36,3 +37,5 @@ export interface ResolveCursorConnectionOptions<T> { | ||
}; | ||
export declare function resolveOffsetConnection<T, U extends Promise<readonly T[] | null> | readonly T[] | null>(options: ResolveOffsetConnectionOptions, resolve: (params: { | ||
export declare function resolveOffsetConnection<T, U extends Promise<readonly T[] | null> | readonly T[] | null, C extends number | undefined = undefined>(options: ResolveOffsetConnectionOptions & { | ||
totalCount?: C; | ||
}, resolve: (params: { | ||
offset: number; | ||
@@ -43,3 +46,5 @@ limit: number; | ||
items: true; | ||
}, false>>>; | ||
}, false> & { | ||
totalCount: C; | ||
}>>; | ||
export declare function cursorToOffset(cursor: string): number; | ||
@@ -50,3 +55,5 @@ export declare function offsetToCursor(offset: number): string; | ||
items: true; | ||
}, false>>; | ||
}, false> & { | ||
totalCount: number; | ||
}>; | ||
type NodeType<T> = T extends (infer N)[] | Promise<(infer N)[] | null> | null ? N : never; | ||
@@ -53,0 +60,0 @@ export declare function resolveCursorConnection<U extends Promise<readonly unknown[] | null> | readonly unknown[] | null>(options: ResolveCursorConnectionOptions<NodeType<U>>, resolve: (params: ResolveCursorConnectionArgs) => U): Promise<RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>>>; |
@@ -10,2 +10,3 @@ import { type MaybePromise, type SchemaTypes } from '@pothos/core'; | ||
maxSize?: number; | ||
totalCount?: number; | ||
} | ||
@@ -36,3 +37,5 @@ export interface ResolveCursorConnectionOptions<T> { | ||
}; | ||
export declare function resolveOffsetConnection<T, U extends Promise<readonly T[] | null> | readonly T[] | null>(options: ResolveOffsetConnectionOptions, resolve: (params: { | ||
export declare function resolveOffsetConnection<T, U extends Promise<readonly T[] | null> | readonly T[] | null, C extends number | undefined = undefined>(options: ResolveOffsetConnectionOptions & { | ||
totalCount?: C; | ||
}, resolve: (params: { | ||
offset: number; | ||
@@ -43,3 +46,5 @@ limit: number; | ||
items: true; | ||
}, false>>>; | ||
}, false> & { | ||
totalCount: C; | ||
}>>; | ||
export declare function cursorToOffset(cursor: string): number; | ||
@@ -50,3 +55,5 @@ export declare function offsetToCursor(offset: number): string; | ||
items: true; | ||
}, false>>; | ||
}, false> & { | ||
totalCount: number; | ||
}>; | ||
type NodeType<T> = T extends (infer N)[] | Promise<(infer N)[] | null> | null ? N : never; | ||
@@ -53,0 +60,0 @@ export declare function resolveCursorConnection<U extends Promise<readonly unknown[] | null> | readonly unknown[] | null>(options: ResolveCursorConnectionOptions<NodeType<U>>, resolve: (params: ResolveCursorConnectionArgs) => U): Promise<RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>>>; |
@@ -20,3 +20,3 @@ import { PothosValidationError, decodeBase64, encodeBase64 } from '@pothos/core'; | ||
let startOffset = after ? afterOffset + 1 : 0; | ||
let endOffset = before ? Math.max(beforeOffset, startOffset) : Number.POSITIVE_INFINITY; | ||
let endOffset = before ? Math.max(beforeOffset, startOffset) : options.totalCount != null ? Math.max(options.totalCount, 0) : Number.POSITIVE_INFINITY; | ||
if (first != null) { | ||
@@ -58,2 +58,3 @@ endOffset = Math.min(endOffset, startOffset + first); | ||
edges: trimmed, | ||
totalCount: options.totalCount, | ||
pageInfo: { | ||
@@ -78,3 +79,6 @@ startCursor: offsetToCursor(offset), | ||
export function resolveArrayConnection(options, array) { | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs(options); | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs({ | ||
totalCount: array.length, | ||
...options | ||
}); | ||
const nodes = array.slice(offset, offset + limit); | ||
@@ -88,2 +92,3 @@ const edges = nodes.map((value, index) => value == null ? null : { | ||
edges: trimmed, | ||
totalCount: array.length, | ||
pageInfo: { | ||
@@ -90,0 +95,0 @@ startCursor: offsetToCursor(offset), |
@@ -50,3 +50,3 @@ "use strict"; | ||
let startOffset = after ? afterOffset + 1 : 0; | ||
let endOffset = before ? Math.max(beforeOffset, startOffset) : Number.POSITIVE_INFINITY; | ||
let endOffset = before ? Math.max(beforeOffset, startOffset) : options.totalCount != null ? Math.max(options.totalCount, 0) : Number.POSITIVE_INFINITY; | ||
if (first != null) { | ||
@@ -88,2 +88,3 @@ endOffset = Math.min(endOffset, startOffset + first); | ||
edges: trimmed, | ||
totalCount: options.totalCount, | ||
pageInfo: { | ||
@@ -108,3 +109,6 @@ startCursor: offsetToCursor(offset), | ||
function resolveArrayConnection(options, array) { | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs(options); | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs({ | ||
totalCount: array.length, | ||
...options | ||
}); | ||
const nodes = array.slice(offset, offset + limit); | ||
@@ -118,2 +122,3 @@ const edges = nodes.map((value, index)=>value == null ? null : { | ||
edges: trimmed, | ||
totalCount: array.length, | ||
pageInfo: { | ||
@@ -120,0 +125,0 @@ startCursor: offsetToCursor(offset), |
{ | ||
"name": "@pothos/plugin-relay", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "A Pothos plugin for adding relay style connections, nodes, and cursor based pagination to your GraphQL schema", | ||
@@ -48,3 +48,3 @@ "main": "./lib/index.js", | ||
"graphql-tag": "^2.12.6", | ||
"@pothos/core": "4.1.0", | ||
"@pothos/core": "4.2.0", | ||
"@pothos/plugin-complexity": "4.1.0", | ||
@@ -51,0 +51,0 @@ "@pothos/test-utils": "2.1.0" |
@@ -1,3 +0,1 @@ | ||
# Relay Plugin | ||
The Relay plugin adds a number of builder methods and helper functions to simplify building a relay | ||
@@ -297,2 +295,3 @@ compatible schema. | ||
maxSize?: number; // defaults to 100 | ||
totalCount?: number // required to support using `last` without `before` | ||
} | ||
@@ -299,0 +298,0 @@ ``` |
@@ -20,2 +20,3 @@ import { | ||
maxSize?: number; | ||
totalCount?: number; | ||
} | ||
@@ -64,3 +65,7 @@ | ||
let startOffset = after ? afterOffset + 1 : 0; | ||
let endOffset = before ? Math.max(beforeOffset, startOffset) : Number.POSITIVE_INFINITY; | ||
let endOffset = before | ||
? Math.max(beforeOffset, startOffset) | ||
: options.totalCount != null | ||
? Math.max(options.totalCount, 0) | ||
: Number.POSITIVE_INFINITY; | ||
@@ -97,4 +102,5 @@ if (first != null) { | ||
U extends Promise<readonly T[] | null> | readonly T[] | null, | ||
C extends number | undefined = undefined, | ||
>( | ||
options: ResolveOffsetConnectionOptions, | ||
options: ResolveOffsetConnectionOptions & { totalCount?: C }, | ||
resolve: (params: { | ||
@@ -112,3 +118,3 @@ offset: number; | ||
false | ||
> | ||
> & { totalCount: C } | ||
> | ||
@@ -137,2 +143,3 @@ > { | ||
edges: trimmed as never, | ||
totalCount: options.totalCount as never, | ||
pageInfo: { | ||
@@ -171,5 +178,8 @@ startCursor: offsetToCursor(offset), | ||
false | ||
> | ||
> & { totalCount: number } | ||
> { | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs(options); | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs({ | ||
totalCount: array.length, | ||
...options, | ||
}); | ||
@@ -191,2 +201,3 @@ const nodes = array.slice(offset, offset + limit); | ||
edges: trimmed as never, | ||
totalCount: array.length, | ||
pageInfo: { | ||
@@ -193,0 +204,0 @@ startCursor: offsetToCursor(offset), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
454977
5789
787