@unthrown/pothos / index
index
Type Aliases
Caseable
type Caseable =
| {
_tag: string;
}
| {
code: string;
};Defined in: refusals.ts:31
A failure that names its case: a string _tag, or a string code. A field's resolver (and outcomeOf) answers Failure & Caseable, so a failure with a member naming no case does not compile — no refusal could answer it.
CaseOf
type CaseOf<Failure> = Failure extends object ? Tag : Failure extends object ?
| "_tag" extends keyof Failure ? string extends Failure["_tag"] ? string : Extract<Failure["_tag"], string> : never
| Code : never;Defined in: refusals.ts:14
The name of a failure's case: its _tag (a TaggedError), else its code (an ORPCError, or any code-discriminated object). An optional string _tag beside a code names the case whenever it is present, so both count; a tag that may hold any string (unknown, string) makes the cases non-finite, which Refusals refuses.
Type Parameters
| Type Parameter |
|---|
Failure |
Refusals
type Refusals<Failure> = [Failure] extends [never] ? object : [CaseOf<Failure>] extends [never] ? { readonly [Case in CaseOf<Failure>]: never } : [NonFiniteOf<CaseOf<Failure>>] extends [never] ? { readonly [Case in CaseOf<Failure>]: (failure: FailureOf<Failure, Case>) => Error } : object;Defined in: refusals.ts:65
One GraphQL error class per case of Failure, each constructed from the failure of that case. It is exhaustive by construction: a missing case, an extra one, or a class built from another case's failure does not compile — the same guarantee the error combinators' matcher gives, keyed by the case the failure names. A resolver that cannot fail takes an empty record, and a failure whose cases cannot be enumerated takes none at all.
The extra-case check is TypeScript's excess-property check, which holds for an object literal: write the record inline, or declare it apart with satisfies Refusals<Failure>.
The classes are the field's error types for @pothos/plugin-errors, so each must be registered as an object type (builder.objectType(NotFoundError, …)).
Type Parameters
| Type Parameter |
|---|
Failure |
ResolvedShape
type ResolvedShape<Type, Shape> = Type extends
| readonly unknown[]
| {
kind: "List";
} ? Shape extends readonly infer Item[] ? Iterable<Item | Promise<Item>> & object : Shape : Shape;Defined in: index.ts:56
A field's value as its Ok may carry it. A GraphQL list ([Type], a ListRef) takes any synchronous iterable of its items, each possibly a promise — an array, a generator, never a string; any other field takes its shape as it is, an array-shaped scalar included. An Ok holding an Error is answered as a defect at runtime: the errors plugin would take it for a refusal.
Type Parameters
| Type Parameter |
|---|
Type |
Shape |
ResultFieldOptions
type ResultFieldOptions<Types, ParentShape, Type, Nullable, Args, Kind, Failure> = Omit<FieldOptionsFromKind<Types, ParentShape, Type, Nullable, Args, Kind, ParentShape, unknown>, "resolve" | "errors"> & object;Defined in: index.ts:85
t.field's options with a Result-answering resolve and the refusals its failure maps to. errors keeps @pothos/plugin-errors' other options (directResult, dataField, …); its types are the refusals'.
Type Declaration
| Name | Type | Defined in |
|---|---|---|
errors? | Omit<ErrorFieldOptions<Types, Type, ResolvedShape<Type, ShapeFromTypeParam<Types, Type, false>>, Nullable>, "types"> | index.ts:97 |
refusals | NoInfer<Refusals<Failure>> | index.ts:108 |
resolve | ResultResolver<Types, ParentShape, Args, ResolvedShape<Type, ShapeFromTypeParam<Types, Type, Nullable>>, Failure> | index.ts:109 |
Type Parameters
| Type Parameter |
|---|
Types extends SchemaTypes |
ParentShape |
Type extends TypeParam<Types> |
Nullable extends FieldNullability<Type> |
Args extends InputFieldMap |
Kind extends FieldKind |
Failure |
ResultResolver
type ResultResolver<Types, Parent, Args, Value, Failure> = (parent, args, context, info) =>
| Result<Value, Failure & Caseable>
| AsyncResult<Value, Failure & Caseable>;Defined in: index.ts:67
A resolver answering a Result: Pothos' four resolver arguments, the field's value as the Ok and Failure as the error channel. Every member of Failure must name its case (Caseable).
Type Parameters
| Type Parameter |
|---|
Types extends SchemaTypes |
Parent |
Args extends InputFieldMap |
Value |
Failure |
Parameters
| Parameter | Type |
|---|---|
parent | Parent |
args | InputShapeFromFields<Args> |
context | Types["Context"] |
info | GraphQLResolveInfo |
Returns
| Result<Value, Failure & Caseable> | AsyncResult<Value, Failure & Caseable>
Variables
default
const default: "unthrown" = "unthrown";Defined in: index.ts:155
Functions
outcomeOf()
function outcomeOf<Value, Failure>(
result,
refusals,
defaultTypes?
): Promise<Value | Error>;Defined in: refusals.ts:178
A Result as a DataLoader answers one key: the value, or the refusal its failure maps to. A Defect is returned as an Error, never thrown, so one key's bug does not reject the batch — wrapped (new Error("Defect", { cause })) when one of the field's refusals or the builder's defaultTypes would claim it. Pass the builder's defaultTypes: a loader can only reject a key with an Error, so a base Error among them claims every defect a loader reports.
Type Parameters
| Type Parameter |
|---|
Value |
Failure |
Parameters
| Parameter | Type | Default value |
|---|---|---|
result | | Result<Value, Failure & Caseable> | AsyncResult<Value, Failure & Caseable> | undefined |
refusals | Refusals<Failure> | undefined |
defaultTypes | readonly ErrorClass[] | [] |
Returns
Promise<Value | Error>