@pothos/core
Advanced tools
Comparing version 3.27.1 to 3.28.0
# Change Log | ||
## 3.28.0 | ||
### Minor Changes | ||
- e8d75349: - allow connection fields (edges / pageInfo) to be promises | ||
- add completeValue helper to core for unwrapping MaybePromise values | ||
- set nodes as null if edges is null and the field permits a null return | ||
## 3.27.1 | ||
@@ -4,0 +12,0 @@ |
@@ -10,3 +10,3 @@ import { InputType, InputTypeParam, OutputType, SchemaTypes, TypeParam } from '../types'; | ||
export declare function assertArray(value: unknown): value is unknown[]; | ||
export declare function isThenable(value: unknown): value is Promise<unknown>; | ||
export declare function isThenable(value: unknown): value is PromiseLike<unknown>; | ||
export declare function verifyRef(ref: unknown): void; | ||
@@ -19,2 +19,7 @@ export declare function verifyInterfaces(interfaces: unknown): void; | ||
export declare function unwrapInputListParam<Types extends SchemaTypes>(param: InputTypeParam<Types>): InputType<Types>; | ||
/** | ||
* Helper for allowing plugins to fulfill the return of the `next` resolver, without paying the cost of the | ||
* Promise if not required. | ||
*/ | ||
export declare function completeValue<T, R>(valOrPromise: PromiseLike<T> | T, onSuccess: (completedVal: T) => R, onError?: (errVal: unknown) => R): R | Promise<R>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -10,3 +10,3 @@ import { InputType, InputTypeParam, OutputType, SchemaTypes, TypeParam } from '../types/index.js'; | ||
export declare function assertArray(value: unknown): value is unknown[]; | ||
export declare function isThenable(value: unknown): value is Promise<unknown>; | ||
export declare function isThenable(value: unknown): value is PromiseLike<unknown>; | ||
export declare function verifyRef(ref: unknown): void; | ||
@@ -19,2 +19,7 @@ export declare function verifyInterfaces(interfaces: unknown): void; | ||
export declare function unwrapInputListParam<Types extends SchemaTypes>(param: InputTypeParam<Types>): InputType<Types>; | ||
/** | ||
* Helper for allowing plugins to fulfill the return of the `next` resolver, without paying the cost of the | ||
* Promise if not required. | ||
*/ | ||
export declare function completeValue<T, R>(valOrPromise: PromiseLike<T> | T, onSuccess: (completedVal: T) => R, onError?: (errVal: unknown) => R): R | Promise<R>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -102,2 +102,18 @@ import { PothosSchemaError, PothosValidationError } from '../errors.js'; | ||
} | ||
/** | ||
* Helper for allowing plugins to fulfill the return of the `next` resolver, without paying the cost of the | ||
* Promise if not required. | ||
*/ export function completeValue(valOrPromise, onSuccess, onError) { | ||
if (isThenable(valOrPromise)) { | ||
return Promise.resolve(valOrPromise).then(onSuccess, onError); | ||
} | ||
// No need to handle onError, this should just be a try/catch inside the `onSuccess` block | ||
const result = onSuccess(valOrPromise); | ||
// If the result of the synchronous call is a promise like, convert to a promise | ||
// for consistency | ||
if (isThenable(result)) { | ||
return Promise.resolve(result); | ||
} | ||
return result; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -21,3 +21,4 @@ "use strict"; | ||
unwrapOutputListParam: ()=>unwrapOutputListParam, | ||
unwrapInputListParam: ()=>unwrapInputListParam | ||
unwrapInputListParam: ()=>unwrapInputListParam, | ||
completeValue: ()=>completeValue | ||
}); | ||
@@ -141,3 +142,16 @@ const _errors = require("../errors"); | ||
} | ||
function completeValue(valOrPromise, onSuccess, onError) { | ||
if (isThenable(valOrPromise)) { | ||
return Promise.resolve(valOrPromise).then(onSuccess, onError); | ||
} | ||
// No need to handle onError, this should just be a try/catch inside the `onSuccess` block | ||
const result = onSuccess(valOrPromise); | ||
// If the result of the synchronous call is a promise like, convert to a promise | ||
// for consistency | ||
if (isThenable(result)) { | ||
return Promise.resolve(result); | ||
} | ||
return result; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pothos/core", | ||
"version": "3.27.1", | ||
"version": "3.28.0", | ||
"description": "Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -32,3 +32,3 @@ import { PothosSchemaError, PothosValidationError } from '../errors'; | ||
export function isThenable(value: unknown): value is Promise<unknown> { | ||
export function isThenable(value: unknown): value is PromiseLike<unknown> { | ||
return !!( | ||
@@ -142,1 +142,24 @@ value && | ||
} | ||
/** | ||
* Helper for allowing plugins to fulfill the return of the `next` resolver, without paying the cost of the | ||
* Promise if not required. | ||
*/ | ||
export function completeValue<T, R>( | ||
valOrPromise: PromiseLike<T> | T, | ||
onSuccess: (completedVal: T) => R, | ||
onError?: (errVal: unknown) => R, | ||
): R | Promise<R> { | ||
if (isThenable(valOrPromise)) { | ||
return Promise.resolve(valOrPromise).then(onSuccess, onError); | ||
} | ||
// No need to handle onError, this should just be a try/catch inside the `onSuccess` block | ||
const result = onSuccess(valOrPromise); | ||
// If the result of the synchronous call is a promise like, convert to a promise | ||
// for consistency | ||
if (isThenable(result)) { | ||
return Promise.resolve(result); | ||
} | ||
return result; | ||
} |
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
1022173
14800