@pothos/plugin-relay
Advanced tools
Comparing version 3.37.0 to 3.38.0
# Change Log | ||
## 3.38.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.37.0 | ||
@@ -4,0 +12,0 @@ |
import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, FieldRequiredness, InputFieldMap, InputFieldRef, InputFieldsFromShape, InputShapeFromFields, InputShapeFromTypeParam, inputShapeKey, InterfaceParam, NormalizeArgs, ObjectFieldsShape, ObjectFieldThunk, ObjectParam, OutputShape, OutputType, ParentShape, Resolver, SchemaTypes, ShapeFromTypeParam } from '@pothos/core'; | ||
import { NodeRef } from './node-ref'; | ||
import { ConnectionShape, ConnectionShapeForType, ConnectionShapeFromResolve, GlobalIDFieldOptions, GlobalIDInputFieldOptions, GlobalIDInputShape, GlobalIDListFieldOptions, GlobalIDListInputFieldOptions, GlobalIDShape, InputShapeWithClientMutationId, NodeFieldOptions, NodeListFieldOptions, NodeObjectOptions, PageInfoShape, RelayMutationFieldOptions, RelayMutationInputOptions, RelayMutationPayloadOptions, RelayPluginOptions } from './types'; | ||
import { ConnectionResultShape, ConnectionShape, ConnectionShapeForType, ConnectionShapeFromResolve, GlobalIDFieldOptions, GlobalIDInputFieldOptions, GlobalIDInputShape, GlobalIDListFieldOptions, GlobalIDListInputFieldOptions, GlobalIDShape, InputShapeWithClientMutationId, NodeFieldOptions, NodeListFieldOptions, NodeObjectOptions, PageInfoShape, RelayMutationFieldOptions, RelayMutationInputOptions, RelayMutationPayloadOptions, RelayPluginOptions } from './types'; | ||
import type { DefaultEdgesNullability, PothosRelayPlugin } from '.'; | ||
@@ -78,6 +78,6 @@ declare global { | ||
nodeList: <Args extends InputFieldMap, ResolveShape>(options: NodeListFieldOptions<Types, ParentShape, Args, ResolveShape, Kind>) => FieldRef<readonly unknown[]>; | ||
connection: <Type extends OutputType<Types>, Args extends InputFieldMap, Nullable extends boolean, ResolveShape, ResolveReturnShape, EdgeNullability extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullability extends boolean = Types['DefaultNodeNullability'], ConnectionInterfaces extends InterfaceParam<Types>[] = [], EdgeInterfaces extends InterfaceParam<Types>[] = []>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, (InputFieldMap extends Args ? {} : Args) & InputFieldsFromShape<DefaultConnectionArguments>, Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
connection: <Type extends OutputType<Types>, Args extends InputFieldMap, Nullable extends boolean, ResolveShape, ResolveReturnShape, EdgeNullability extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullability extends boolean = Types['DefaultNodeNullability'], ConnectionInterfaces extends InterfaceParam<Types>[] = [], EdgeInterfaces extends InterfaceParam<Types>[] = [], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, (InputFieldMap extends Args ? {} : Args) & InputFieldsFromShape<DefaultConnectionArguments>, Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
resolve?: (parent: infer P, ...args: any[]) => unknown; | ||
} ? P : unknown extends ResolveShape ? ParentShape : ResolveShape, Type, Nullable, EdgeNullability, NodeNullability, Args, ResolveReturnShape> & Omit<FieldOptions, 'args' | 'resolve' | 'type'> : never, ...args: NormalizeArgs<[ | ||
connectionOptions: ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability>> | Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape, ConnectionInterfaces>, 'edgesNullable'>, | ||
} ? P : unknown extends ResolveShape ? ParentShape : ResolveShape, Type, Nullable, EdgeNullability, NodeNullability, Args, ResolveReturnShape, ConnectionResult> & Omit<FieldOptions, 'args' | 'resolve' | 'type'> : never, ...args: NormalizeArgs<[ | ||
connectionOptions: ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability, ConnectionResult>> | Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape, ConnectionInterfaces>, 'edgesNullable'>, | ||
edgeOptions: ObjectRef<{ | ||
@@ -89,3 +89,3 @@ cursor: string; | ||
} | ||
interface ConnectionFieldOptions<Types extends SchemaTypes, ParentShape, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Args extends InputFieldMap, ResolveReturnShape> { | ||
interface ConnectionFieldOptions<Types extends SchemaTypes, ParentShape, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Args extends InputFieldMap, ResolveReturnShape, ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> { | ||
type: Type; | ||
@@ -95,5 +95,5 @@ args?: Args; | ||
nodeNullable?: NodeNullability; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, ResolveReturnShape>; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>, ResolveReturnShape>; | ||
} | ||
interface ConnectionObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Resolved, Interfaces extends InterfaceParam<Types>[] = []> extends ObjectTypeWithInterfaceOptions<Types, ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved>, Interfaces> { | ||
interface ConnectionObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Resolved, Interfaces extends InterfaceParam<Types>[] = [], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> extends ObjectTypeWithInterfaceOptions<Types, ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved, ConnectionResult>, Interfaces> { | ||
name?: string; | ||
@@ -104,3 +104,3 @@ edgesNullable?: EdgeNullability; | ||
} | ||
interface ConnectionEdgeObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, NodeNullability extends boolean, Resolved, Interfaces extends InterfaceParam<Types>[] = []> extends ObjectTypeWithInterfaceOptions<Types, NonNullable<ConnectionShapeFromResolve<Types, Type, false, false, NodeNullability, Resolved>['edges']>[number], Interfaces> { | ||
interface ConnectionEdgeObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, NodeNullability extends boolean, Resolved, Interfaces extends InterfaceParam<Types>[] = []> extends ObjectTypeWithInterfaceOptions<Types, NonNullable<Awaited<ConnectionShapeFromResolve<Types, Type, false, false, NodeNullability, Resolved>['edges']>>[number], Interfaces> { | ||
name?: string; | ||
@@ -107,0 +107,0 @@ nodeField?: Omit<ObjectFieldOptions<Types, {}, ObjectRef<{}>, Types['DefaultNodeNullability'], {}, GlobalIDShape<Types> | string>, 'args' | 'nullable' | 'resolve' | 'type'>; |
import { ObjectRef, SchemaTypes } from '@pothos/core'; | ||
import { ConnectionShape } from './types'; | ||
export declare const connectionRefs: WeakMap<PothosSchemaTypes.SchemaBuilder<SchemaTypes>, ObjectRef<ConnectionShape<SchemaTypes, unknown, boolean, import("@pothos/core").FieldNullability<[unknown]>, boolean>, ConnectionShape<SchemaTypes, unknown, boolean, import("@pothos/core").FieldNullability<[unknown]>, boolean>>[]>; | ||
export declare const connectionRefs: WeakMap<PothosSchemaTypes.SchemaBuilder<SchemaTypes>, ObjectRef<ConnectionShape<SchemaTypes, unknown, boolean, import("@pothos/core").FieldNullability<[unknown]>, boolean, import("./types").ConnectionResultShape<SchemaTypes, unknown, import("@pothos/core").FieldNullability<[unknown]>, boolean>>, ConnectionShape<SchemaTypes, unknown, boolean, import("@pothos/core").FieldNullability<[unknown]>, boolean, import("./types").ConnectionResultShape<SchemaTypes, unknown, import("@pothos/core").FieldNullability<[unknown]>, boolean>>>[]>; | ||
export declare const globalConnectionFieldsMap: WeakMap<PothosSchemaTypes.SchemaBuilder<SchemaTypes>, ((ref: ObjectRef<ConnectionShape<SchemaTypes, unknown, boolean>>) => void)[]>; | ||
//# sourceMappingURL=schema-builder.d.ts.map |
@@ -22,3 +22,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
typename: string; | ||
}) => Promise<unknown>) => MaybePromise<unknown>; | ||
}) => MaybePromise<unknown>) => MaybePromise<unknown>; | ||
}); | ||
@@ -97,14 +97,16 @@ nodesQueryOptions: false | (Omit<PothosSchemaTypes.QueryFieldOptions<Types, [ | ||
} | ||
export type ConnectionShape<Types extends SchemaTypes, T, Nullable, EdgesNullable extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullable extends boolean = Types['DefaultNodeNullability']> = (Nullable extends false ? never : null | undefined) | (Types['Connection'] & { | ||
pageInfo: PageInfoShape; | ||
edges: ShapeFromListTypeParam<Types, [ | ||
ObjectRef<{ | ||
cursor: string; | ||
node: NodeNullable extends false ? T : T | null | undefined; | ||
}> | ||
], EdgesNullable>; | ||
}); | ||
export type ConnectionEdgesShape<Types extends SchemaTypes, T, NodeNullable extends boolean, EdgesNullable extends FieldNullability<[unknown]>> = ShapeFromListTypeParam<Types, [ | ||
ObjectRef<{ | ||
cursor: string; | ||
node: NodeNullable extends false ? T : T | null | undefined; | ||
}> | ||
], EdgesNullable>; | ||
export interface ConnectionResultShape<Types extends SchemaTypes, T, EdgesNullable extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullable extends boolean = Types['DefaultNodeNullability']> { | ||
pageInfo: MaybePromise<PageInfoShape>; | ||
edges: MaybePromise<ConnectionEdgesShape<Types, T, NodeNullable, EdgesNullable>>; | ||
} | ||
export type ConnectionShape<Types extends SchemaTypes, T, Nullable, EdgesNullable extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullable extends boolean = Types['DefaultNodeNullability'], ConnectionResult extends ConnectionResultShape<Types, T, EdgesNullable, NodeNullable> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>> = (Nullable extends false ? never : null | undefined) | (Types['Connection'] & ConnectionResult); | ||
export type ConnectionShapeFromBaseShape<Types extends SchemaTypes, Shape, Nullable extends boolean> = ConnectionShape<Types, Shape, Nullable>; | ||
export type ConnectionShapeForType<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean> = ConnectionShape<Types, ShapeFromTypeParam<Types, Type, false>, Nullable, EdgeNullability, NodeNullability>; | ||
export type ConnectionShapeFromResolve<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Resolved> = Resolved extends Promise<infer T> ? NonNullable<T> extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> ? NonNullable<T> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> : Resolved extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> ? NonNullable<Resolved> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>; | ||
export type ConnectionShapeForType<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> = ConnectionShape<Types, ShapeFromTypeParam<Types, Type, false>, Nullable, EdgeNullability, NodeNullability, ConnectionResult>; | ||
export type ConnectionShapeFromResolve<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Resolved, ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> = Resolved extends Promise<infer T> ? NonNullable<T> extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> ? NonNullable<T> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult> : Resolved extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult> ? NonNullable<Resolved> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>; | ||
export interface DefaultConnectionArguments extends PothosSchemaTypes.DefaultConnectionArguments { | ||
@@ -111,0 +113,0 @@ } |
import { MaybePromise, SchemaTypes } from '@pothos/core'; | ||
import { ConnectionShape, DefaultConnectionArguments } from '../types'; | ||
type RemoveMaybePromiseProps<T> = { | ||
[K in keyof T]: Awaited<T[K]>; | ||
}; | ||
interface ResolveOffsetConnectionOptions { | ||
@@ -28,15 +31,15 @@ args: DefaultConnectionArguments; | ||
limit: number; | ||
}) => U & (MaybePromise<T[] | null> | null)): Promise<ConnectionShape<SchemaTypes, NonNullable<T>, U extends NonNullable<U> ? (Promise<null> extends U ? true : false) : true, T extends NonNullable<T> ? false : { | ||
}) => U & (MaybePromise<T[] | null> | null)): Promise<RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NonNullable<T>, U extends NonNullable<U> ? (Promise<null> extends U ? true : false) : true, T extends NonNullable<T> ? false : { | ||
list: false; | ||
items: true; | ||
}, false>>; | ||
}, false>>>; | ||
export declare function cursorToOffset(cursor: string): number; | ||
export declare function offsetToCursor(offset: number): string; | ||
export declare function resolveArrayConnection<T>(options: ResolveArrayConnectionOptions, array: T[]): ConnectionShape<SchemaTypes, NonNullable<T>, false, T extends NonNullable<T> ? false : { | ||
export declare function resolveArrayConnection<T>(options: ResolveArrayConnectionOptions, array: T[]): RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NonNullable<T>, false, T extends NonNullable<T> ? false : { | ||
list: false; | ||
items: true; | ||
}, false>; | ||
}, false>>; | ||
type NodeType<T> = T extends Promise<(infer N)[] | null> | (infer N)[] | null ? N : never; | ||
export declare function resolveCursorConnection<U extends Promise<unknown[] | null> | unknown[] | null>(options: ResolveCursorConnectionOptions<NodeType<U>>, resolve: (params: ResolveCursorConnectionArgs) => U): Promise<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>>; | ||
export declare function resolveCursorConnection<U extends Promise<unknown[] | null> | unknown[] | null>(options: ResolveCursorConnectionOptions<NodeType<U>>, resolve: (params: ResolveCursorConnectionArgs) => U): Promise<RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>>>; | ||
export {}; | ||
//# sourceMappingURL=connections.d.ts.map |
import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, FieldRequiredness, InputFieldMap, InputFieldRef, InputFieldsFromShape, InputShapeFromFields, InputShapeFromTypeParam, inputShapeKey, InterfaceParam, NormalizeArgs, ObjectFieldsShape, ObjectFieldThunk, ObjectParam, OutputShape, OutputType, ParentShape, Resolver, SchemaTypes, ShapeFromTypeParam } from '@pothos/core'; | ||
import { NodeRef } from './node-ref.js'; | ||
import { ConnectionShape, ConnectionShapeForType, ConnectionShapeFromResolve, GlobalIDFieldOptions, GlobalIDInputFieldOptions, GlobalIDInputShape, GlobalIDListFieldOptions, GlobalIDListInputFieldOptions, GlobalIDShape, InputShapeWithClientMutationId, NodeFieldOptions, NodeListFieldOptions, NodeObjectOptions, PageInfoShape, RelayMutationFieldOptions, RelayMutationInputOptions, RelayMutationPayloadOptions, RelayPluginOptions } from './types.js'; | ||
import { ConnectionResultShape, ConnectionShape, ConnectionShapeForType, ConnectionShapeFromResolve, GlobalIDFieldOptions, GlobalIDInputFieldOptions, GlobalIDInputShape, GlobalIDListFieldOptions, GlobalIDListInputFieldOptions, GlobalIDShape, InputShapeWithClientMutationId, NodeFieldOptions, NodeListFieldOptions, NodeObjectOptions, PageInfoShape, RelayMutationFieldOptions, RelayMutationInputOptions, RelayMutationPayloadOptions, RelayPluginOptions } from './types.js'; | ||
import type { DefaultEdgesNullability, PothosRelayPlugin } from './index.js'; | ||
@@ -101,6 +101,6 @@ declare global { | ||
], EdgeInterfaces extends InterfaceParam<Types>[] = [ | ||
]>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, (InputFieldMap extends Args ? {} : Args) & InputFieldsFromShape<DefaultConnectionArguments>, Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, (InputFieldMap extends Args ? {} : Args) & InputFieldsFromShape<DefaultConnectionArguments>, Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
resolve?: (parent: infer P, ...args: any[]) => unknown; | ||
} ? P : unknown extends ResolveShape ? ParentShape : ResolveShape, Type, Nullable, EdgeNullability, NodeNullability, Args, ResolveReturnShape> & Omit<FieldOptions, "args" | "resolve" | "type"> : never, ...args: NormalizeArgs<[ | ||
connectionOptions: ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability>> | Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape, ConnectionInterfaces>, "edgesNullable">, | ||
} ? P : unknown extends ResolveShape ? ParentShape : ResolveShape, Type, Nullable, EdgeNullability, NodeNullability, Args, ResolveReturnShape, ConnectionResult> & Omit<FieldOptions, "args" | "resolve" | "type"> : never, ...args: NormalizeArgs<[ | ||
connectionOptions: ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability, ConnectionResult>> | Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape, ConnectionInterfaces>, "edgesNullable">, | ||
edgeOptions: ObjectRef<{ | ||
@@ -114,3 +114,3 @@ cursor: string; | ||
unknown | ||
]>, NodeNullability extends boolean, Args extends InputFieldMap, ResolveReturnShape> { | ||
]>, NodeNullability extends boolean, Args extends InputFieldMap, ResolveReturnShape, ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> { | ||
type: Type; | ||
@@ -120,3 +120,3 @@ args?: Args; | ||
nodeNullable?: NodeNullability; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types["Context"], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, ResolveReturnShape>; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types["Context"], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>, ResolveReturnShape>; | ||
} | ||
@@ -126,3 +126,3 @@ interface ConnectionObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, EdgeNullability extends FieldNullability<[ | ||
]>, NodeNullability extends boolean, Resolved, Interfaces extends InterfaceParam<Types>[] = [ | ||
]> extends ObjectTypeWithInterfaceOptions<Types, ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved>, Interfaces> { | ||
], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> extends ObjectTypeWithInterfaceOptions<Types, ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved, ConnectionResult>, Interfaces> { | ||
name?: string; | ||
@@ -134,3 +134,3 @@ edgesNullable?: EdgeNullability; | ||
interface ConnectionEdgeObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, NodeNullability extends boolean, Resolved, Interfaces extends InterfaceParam<Types>[] = [ | ||
]> extends ObjectTypeWithInterfaceOptions<Types, NonNullable<ConnectionShapeFromResolve<Types, Type, false, false, NodeNullability, Resolved>["edges"]>[number], Interfaces> { | ||
]> extends ObjectTypeWithInterfaceOptions<Types, NonNullable<Awaited<ConnectionShapeFromResolve<Types, Type, false, false, NodeNullability, Resolved>["edges"]>>[number], Interfaces> { | ||
name?: string; | ||
@@ -137,0 +137,0 @@ nodeField?: Omit<ObjectFieldOptions<Types, {}, ObjectRef<{}>, Types["DefaultNodeNullability"], {}, GlobalIDShape<Types> | string>, "args" | "nullable" | "resolve" | "type">; |
@@ -5,6 +5,10 @@ import { ObjectRef, SchemaTypes } from '@pothos/core'; | ||
unknown | ||
]>, boolean>, ConnectionShape<SchemaTypes, unknown, boolean, import("@pothos/core").FieldNullability<[ | ||
]>, boolean, import("./types.js").ConnectionResultShape<SchemaTypes, unknown, import("@pothos/core").FieldNullability<[ | ||
unknown | ||
]>, boolean>>[]>; | ||
]>, boolean>>, ConnectionShape<SchemaTypes, unknown, boolean, import("@pothos/core").FieldNullability<[ | ||
unknown | ||
]>, boolean, import("./types.js").ConnectionResultShape<SchemaTypes, unknown, import("@pothos/core").FieldNullability<[ | ||
unknown | ||
]>, boolean>>>[]>; | ||
export declare const globalConnectionFieldsMap: WeakMap<PothosSchemaTypes.SchemaBuilder<SchemaTypes>, ((ref: ObjectRef<ConnectionShape<SchemaTypes, unknown, boolean>>) => void)[]>; | ||
//# sourceMappingURL=schema-builder.d.ts.map |
import { defaultTypeResolver } from 'graphql'; | ||
import SchemaBuilder, { createContextCache, getTypeBrand, InputObjectRef, ObjectRef, PothosValidationError, verifyRef } from '@pothos/core'; | ||
import SchemaBuilder, { completeValue, createContextCache, getTypeBrand, InputObjectRef, ObjectRef, PothosValidationError, verifyRef } from '@pothos/core'; | ||
import { NodeRef } from './node-ref.js'; | ||
@@ -110,7 +110,7 @@ import { capitalize, resolveNodes } from './utils/index.js'; | ||
}, | ||
resolve: resolveNodeFn ? (root, args, context, info) => resolveNodeFn(root, args, context, info, async (ids) => (await resolveNodes(this, context, info, [ | ||
resolve: resolveNodeFn ? (root, args, context, info) => resolveNodeFn(root, args, context, info, (ids) => completeValue(resolveNodes(this, context, info, [ | ||
args.id | ||
]))[0]) : async (root, args, context, info) => (await resolveNodes(this, context, info, [ | ||
]), (nodes) => nodes[0])) : (root, args, context, info) => completeValue(resolveNodes(this, context, info, [ | ||
args.id | ||
]))[0] | ||
]), (nodes) => nodes[0]) | ||
})); | ||
@@ -186,7 +186,7 @@ } | ||
args: {}, | ||
resolve: async (parent, args, context, info) => ({ | ||
resolve: (parent, args, context, info) => // eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
completeValue(id.resolve(parent, args, context, info), (globalId) => ({ | ||
type: nodeConfig.name, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
id: await id.resolve(parent, args, context, info) | ||
}) | ||
id: globalId | ||
})) | ||
})); | ||
@@ -305,3 +305,3 @@ }); | ||
const edgeItemsNullable = typeof edgesNullableOption === "object" && "items" in edgesNullableOption ? edgesNullableOption.items : false; | ||
var _ref, _ref1, _con_edges_map; | ||
var _ref, _ref1, _edges_map; | ||
this.objectType(connectionRef, { | ||
@@ -339,6 +339,7 @@ ...(_this_options_relayOptions = this.options.relayOptions) === null || _this_options_relayOptions === void 0 ? void 0 : _this_options_relayOptions.defaultConnectionTypeOptions, | ||
resolve: (con) => { | ||
var _con_edges; | ||
return (_con_edges_map = (_con_edges = con.edges) === null || _con_edges === void 0 ? void 0 : _con_edges.map((edge) => { | ||
return edge === null || edge === void 0 ? void 0 : edge.node; | ||
})) !== null && _con_edges_map !== void 0 ? _con_edges_map : []; | ||
return completeValue(con.edges, (edges) => { | ||
return (_edges_map = edges === null || edges === void 0 ? void 0 : edges.map((e) => { | ||
return e === null || e === void 0 ? void 0 : e.node; | ||
})) !== null && _edges_map !== void 0 ? _edges_map : edgeListNullable ? null : []; | ||
}); | ||
} | ||
@@ -345,0 +346,0 @@ }) |
@@ -22,3 +22,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
typename: string; | ||
}) => Promise<unknown>) => MaybePromise<unknown>; | ||
}) => MaybePromise<unknown>) => MaybePromise<unknown>; | ||
}); | ||
@@ -99,20 +99,26 @@ nodesQueryOptions: false | (Omit<PothosSchemaTypes.QueryFieldOptions<Types, [ | ||
} | ||
export type ConnectionEdgesShape<Types extends SchemaTypes, T, NodeNullable extends boolean, EdgesNullable extends FieldNullability<[ | ||
unknown | ||
]>> = ShapeFromListTypeParam<Types, [ | ||
ObjectRef<{ | ||
cursor: string; | ||
node: NodeNullable extends false ? T : T | null | undefined; | ||
}> | ||
], EdgesNullable>; | ||
export interface ConnectionResultShape<Types extends SchemaTypes, T, EdgesNullable extends FieldNullability<[ | ||
unknown | ||
]> = Types["DefaultEdgesNullability"], NodeNullable extends boolean = Types["DefaultNodeNullability"]> { | ||
pageInfo: MaybePromise<PageInfoShape>; | ||
edges: MaybePromise<ConnectionEdgesShape<Types, T, NodeNullable, EdgesNullable>>; | ||
} | ||
export type ConnectionShape<Types extends SchemaTypes, T, Nullable, EdgesNullable extends FieldNullability<[ | ||
unknown | ||
]> = Types["DefaultEdgesNullability"], NodeNullable extends boolean = Types["DefaultNodeNullability"]> = (Nullable extends false ? never : null | undefined) | (Types["Connection"] & { | ||
pageInfo: PageInfoShape; | ||
edges: ShapeFromListTypeParam<Types, [ | ||
ObjectRef<{ | ||
cursor: string; | ||
node: NodeNullable extends false ? T : T | null | undefined; | ||
}> | ||
], EdgesNullable>; | ||
}); | ||
]> = Types["DefaultEdgesNullability"], NodeNullable extends boolean = Types["DefaultNodeNullability"], ConnectionResult extends ConnectionResultShape<Types, T, EdgesNullable, NodeNullable> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>> = (Nullable extends false ? never : null | undefined) | (Types["Connection"] & ConnectionResult); | ||
export type ConnectionShapeFromBaseShape<Types extends SchemaTypes, Shape, Nullable extends boolean> = ConnectionShape<Types, Shape, Nullable>; | ||
export type ConnectionShapeForType<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[ | ||
unknown | ||
]>, NodeNullability extends boolean> = ConnectionShape<Types, ShapeFromTypeParam<Types, Type, false>, Nullable, EdgeNullability, NodeNullability>; | ||
]>, NodeNullability extends boolean, ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> = ConnectionShape<Types, ShapeFromTypeParam<Types, Type, false>, Nullable, EdgeNullability, NodeNullability, ConnectionResult>; | ||
export type ConnectionShapeFromResolve<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[ | ||
unknown | ||
]>, NodeNullability extends boolean, Resolved> = Resolved extends Promise<infer T> ? NonNullable<T> extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> ? NonNullable<T> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> : Resolved extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> ? NonNullable<Resolved> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>; | ||
]>, NodeNullability extends boolean, Resolved, ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> = Resolved extends Promise<infer T> ? NonNullable<T> extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> ? NonNullable<T> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult> : Resolved extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult> ? NonNullable<Resolved> : ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>; | ||
export interface DefaultConnectionArguments extends PothosSchemaTypes.DefaultConnectionArguments { | ||
@@ -119,0 +125,0 @@ } |
import { MaybePromise, SchemaTypes } from '@pothos/core'; | ||
import { ConnectionShape, DefaultConnectionArguments } from '../types.js'; | ||
type RemoveMaybePromiseProps<T> = { | ||
[K in keyof T]: Awaited<T[K]>; | ||
}; | ||
interface ResolveOffsetConnectionOptions { | ||
@@ -28,15 +31,15 @@ args: DefaultConnectionArguments; | ||
limit: number; | ||
}) => U & (MaybePromise<T[] | null> | null)): Promise<ConnectionShape<SchemaTypes, NonNullable<T>, U extends NonNullable<U> ? (Promise<null> extends U ? true : false) : true, T extends NonNullable<T> ? false : { | ||
}) => U & (MaybePromise<T[] | null> | null)): Promise<RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NonNullable<T>, U extends NonNullable<U> ? (Promise<null> extends U ? true : false) : true, T extends NonNullable<T> ? false : { | ||
list: false; | ||
items: true; | ||
}, false>>; | ||
}, false>>>; | ||
export declare function cursorToOffset(cursor: string): number; | ||
export declare function offsetToCursor(offset: number): string; | ||
export declare function resolveArrayConnection<T>(options: ResolveArrayConnectionOptions, array: T[]): ConnectionShape<SchemaTypes, NonNullable<T>, false, T extends NonNullable<T> ? false : { | ||
export declare function resolveArrayConnection<T>(options: ResolveArrayConnectionOptions, array: T[]): RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NonNullable<T>, false, T extends NonNullable<T> ? false : { | ||
list: false; | ||
items: true; | ||
}, false>; | ||
}, false>>; | ||
type NodeType<T> = T extends Promise<(infer N)[] | null> | (infer N)[] | null ? N : never; | ||
export declare function resolveCursorConnection<U extends Promise<unknown[] | null> | unknown[] | null>(options: ResolveCursorConnectionOptions<NodeType<U>>, resolve: (params: ResolveCursorConnectionArgs) => U): Promise<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>>; | ||
export declare function resolveCursorConnection<U extends Promise<unknown[] | null> | unknown[] | null>(options: ResolveCursorConnectionOptions<NodeType<U>>, resolve: (params: ResolveCursorConnectionArgs) => U): Promise<RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>>>; | ||
export {}; | ||
//# sourceMappingURL=connections.d.ts.map |
@@ -162,7 +162,7 @@ "use strict"; | ||
}, | ||
resolve: resolveNodeFn ? (root, args, context, info)=>resolveNodeFn(root, args, context, info, async (ids)=>(await (0, _utils.resolveNodes)(this, context, info, [ | ||
resolve: resolveNodeFn ? (root, args, context, info)=>resolveNodeFn(root, args, context, info, (ids)=>(0, _core.completeValue)((0, _utils.resolveNodes)(this, context, info, [ | ||
args.id | ||
]))[0]) : async (root, args, context, info)=>(await (0, _utils.resolveNodes)(this, context, info, [ | ||
]), (nodes)=>nodes[0])) : (root, args, context, info)=>(0, _core.completeValue)((0, _utils.resolveNodes)(this, context, info, [ | ||
args.id | ||
]))[0] | ||
]), (nodes)=>nodes[0]) | ||
})); | ||
@@ -237,7 +237,7 @@ } | ||
args: {}, | ||
resolve: async (parent, args, context, info)=>({ | ||
type: nodeConfig.name, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
id: await id.resolve(parent, args, context, info) | ||
}) | ||
resolve: (parent, args, context, info)=>// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
(0, _core.completeValue)(id.resolve(parent, args, context, info), (globalId)=>({ | ||
type: nodeConfig.name, | ||
id: globalId | ||
})) | ||
})); | ||
@@ -355,3 +355,3 @@ }); | ||
const edgeItemsNullable = typeof edgesNullableOption === 'object' && 'items' in edgesNullableOption ? edgesNullableOption.items : false; | ||
var _ref, _ref1, _con_edges_map; | ||
var _ref, _ref1, _edges_map; | ||
this.objectType(connectionRef, { | ||
@@ -389,6 +389,7 @@ ...(_this_options_relayOptions = this.options.relayOptions) === null || _this_options_relayOptions === void 0 ? void 0 : _this_options_relayOptions.defaultConnectionTypeOptions, | ||
resolve: (con)=>{ | ||
var _con_edges; | ||
return (_con_edges_map = (_con_edges = con.edges) === null || _con_edges === void 0 ? void 0 : _con_edges.map((edge)=>{ | ||
return edge === null || edge === void 0 ? void 0 : edge.node; | ||
})) !== null && _con_edges_map !== void 0 ? _con_edges_map : []; | ||
return (0, _core.completeValue)(con.edges, (edges)=>{ | ||
return (_edges_map = edges === null || edges === void 0 ? void 0 : edges.map((e)=>{ | ||
return e === null || e === void 0 ? void 0 : e.node; | ||
})) !== null && _edges_map !== void 0 ? _edges_map : edgeListNullable ? null : []; | ||
}); | ||
} | ||
@@ -395,0 +396,0 @@ }) |
{ | ||
"name": "@pothos/plugin-relay", | ||
"version": "3.37.0", | ||
"version": "3.38.0", | ||
"description": "A Pothos plugin for adding relay style connections, nodes, and cursor based pagination to your GraphQL schema", | ||
@@ -46,3 +46,3 @@ "main": "./lib/index.js", | ||
"graphql-tag": "^2.12.6", | ||
"@pothos/core": "3.27.0", | ||
"@pothos/core": "3.28.0", | ||
"@pothos/plugin-complexity": "3.12.0", | ||
@@ -49,0 +49,0 @@ "@pothos/test-utils": "1.4.7" |
@@ -181,3 +181,3 @@ # Relay Plugin | ||
`node` and `nodes` which can be used to directly fetch nodes using global IDs by calling the | ||
provided `loadOne` or `laodMany` method. Each node will only be loaded once by id, and cached if the | ||
provided `loadOne` or `loadMany` method. Each node will only be loaded once by id, and cached if the | ||
same node is loaded multiple times inn the same request. You can provide `loadWithoutCache` or | ||
@@ -184,0 +184,0 @@ `loadManyWithoutCache` instead if caching is not desired, or you are already using a caching |
@@ -27,2 +27,3 @@ import { | ||
import { | ||
ConnectionResultShape, | ||
ConnectionShape, | ||
@@ -269,2 +270,13 @@ ConnectionShapeForType, | ||
EdgeInterfaces extends InterfaceParam<Types>[] = [], | ||
ConnectionResult extends ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
> = ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
>, | ||
>( | ||
@@ -294,3 +306,4 @@ options: FieldOptionsFromKind< | ||
Args, | ||
ResolveReturnShape | ||
ResolveReturnShape, | ||
ConnectionResult | ||
> & | ||
@@ -303,3 +316,10 @@ Omit<FieldOptions, 'args' | 'resolve' | 'type'> | ||
| ObjectRef< | ||
ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability> | ||
ConnectionShapeForType< | ||
Types, | ||
Type, | ||
false, | ||
EdgeNullability, | ||
NodeNullability, | ||
ConnectionResult | ||
> | ||
> | ||
@@ -346,2 +366,13 @@ | Omit< | ||
ResolveReturnShape, | ||
ConnectionResult extends ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
> = ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
>, | ||
> { | ||
@@ -356,3 +387,10 @@ type: Type; | ||
Types['Context'], | ||
ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, | ||
ConnectionShapeForType< | ||
Types, | ||
Type, | ||
Nullable, | ||
EdgeNullability, | ||
NodeNullability, | ||
ConnectionResult | ||
>, | ||
ResolveReturnShape | ||
@@ -369,5 +407,24 @@ >; | ||
Interfaces extends InterfaceParam<Types>[] = [], | ||
ConnectionResult extends ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
> = ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
>, | ||
> extends ObjectTypeWithInterfaceOptions< | ||
Types, | ||
ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved>, | ||
ConnectionShapeFromResolve< | ||
Types, | ||
Type, | ||
false, | ||
EdgeNullability, | ||
NodeNullability, | ||
Resolved, | ||
ConnectionResult | ||
>, | ||
Interfaces | ||
@@ -400,3 +457,12 @@ > { | ||
NonNullable< | ||
ConnectionShapeFromResolve<Types, Type, false, false, NodeNullability, Resolved>['edges'] | ||
Awaited< | ||
ConnectionShapeFromResolve< | ||
Types, | ||
Type, | ||
false, | ||
false, | ||
NodeNullability, | ||
Resolved | ||
>['edges'] | ||
> | ||
>[number], | ||
@@ -403,0 +469,0 @@ Interfaces |
import { defaultTypeResolver, GraphQLResolveInfo } from 'graphql'; | ||
import SchemaBuilder, { | ||
completeValue, | ||
createContextCache, | ||
@@ -9,2 +10,3 @@ FieldRef, | ||
InterfaceRef, | ||
MaybePromise, | ||
ObjectFieldsShape, | ||
@@ -176,15 +178,15 @@ ObjectFieldThunk, | ||
info, | ||
async (ids) => | ||
( | ||
await resolveNodes(this, context, info, [ | ||
(ids) => | ||
completeValue( | ||
resolveNodes(this, context, info, [ | ||
args.id as { id: string; typename: string }, | ||
]) | ||
)[0], | ||
]), | ||
(nodes) => nodes[0], | ||
), | ||
) as never | ||
: async (root, args, context, info) => | ||
( | ||
await resolveNodes(this, context, info, [ | ||
args.id as { id: string; typename: string }, | ||
]) | ||
)[0], | ||
: (root, args, context, info) => | ||
completeValue( | ||
resolveNodes(this, context, info, [args.id as { id: string; typename: string }]), | ||
(nodes) => nodes[0], | ||
), | ||
}) as FieldRef<unknown>, | ||
@@ -292,3 +294,3 @@ ); | ||
this.objectField(ref, this.options.relayOptions.idFieldName ?? 'id', (t) => | ||
t.globalID<{}, false, Promise<GlobalIDShape<SchemaTypes>>>({ | ||
t.globalID<{}, false, MaybePromise<GlobalIDShape<SchemaTypes>>>({ | ||
nullable: false, | ||
@@ -298,7 +300,8 @@ ...this.options.relayOptions.idFieldOptions, | ||
args: {}, | ||
resolve: async (parent, args, context, info) => ({ | ||
type: nodeConfig.name, | ||
resolve: (parent, args, context, info): MaybePromise<GlobalIDShape<SchemaTypes>> => | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
id: await id.resolve(parent, args, context, info), | ||
}), | ||
completeValue(id.resolve(parent, args, context, info), (globalId) => ({ | ||
type: nodeConfig.name, | ||
id: globalId, | ||
})), | ||
}), | ||
@@ -528,3 +531,7 @@ ); | ||
}, | ||
resolve: (con) => (con.edges?.map((edge) => edge?.node) ?? []) as never, | ||
resolve: (con) => | ||
completeValue( | ||
con.edges, | ||
(edges) => edges?.map((e) => e?.node) ?? (edgeListNullable ? null : []), | ||
) as never, | ||
}), | ||
@@ -531,0 +538,0 @@ } |
102
src/types.ts
@@ -65,3 +65,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
info: GraphQLResolveInfo, | ||
resolveNode: (id: { id: string; typename: string }) => Promise<unknown>, | ||
resolveNode: (id: { id: string; typename: string }) => MaybePromise<unknown>, | ||
) => MaybePromise<unknown>; | ||
@@ -277,2 +277,28 @@ }); | ||
export type ConnectionEdgesShape< | ||
Types extends SchemaTypes, | ||
T, | ||
NodeNullable extends boolean, | ||
EdgesNullable extends FieldNullability<[unknown]>, | ||
> = ShapeFromListTypeParam< | ||
Types, | ||
[ | ||
ObjectRef<{ | ||
cursor: string; | ||
node: NodeNullable extends false ? T : T | null | undefined; | ||
}>, | ||
], | ||
EdgesNullable | ||
>; | ||
export interface ConnectionResultShape< | ||
Types extends SchemaTypes, | ||
T, | ||
EdgesNullable extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], | ||
NodeNullable extends boolean = Types['DefaultNodeNullability'], | ||
> { | ||
pageInfo: MaybePromise<PageInfoShape>; | ||
edges: MaybePromise<ConnectionEdgesShape<Types, T, NodeNullable, EdgesNullable>>; | ||
} | ||
export type ConnectionShape< | ||
@@ -284,17 +310,9 @@ Types extends SchemaTypes, | ||
NodeNullable extends boolean = Types['DefaultNodeNullability'], | ||
> = | ||
| (Nullable extends false ? never : null | undefined) | ||
| (Types['Connection'] & { | ||
pageInfo: PageInfoShape; | ||
edges: ShapeFromListTypeParam< | ||
Types, | ||
[ | ||
ObjectRef<{ | ||
cursor: string; | ||
node: NodeNullable extends false ? T : T | null | undefined; | ||
}>, | ||
], | ||
EdgesNullable | ||
>; | ||
}); | ||
ConnectionResult extends ConnectionResultShape< | ||
Types, | ||
T, | ||
EdgesNullable, | ||
NodeNullable | ||
> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>, | ||
> = (Nullable extends false ? never : null | undefined) | (Types['Connection'] & ConnectionResult); | ||
@@ -313,2 +331,13 @@ export type ConnectionShapeFromBaseShape< | ||
NodeNullability extends boolean, | ||
ConnectionResult extends ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
> = ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
>, | ||
> = ConnectionShape< | ||
@@ -319,3 +348,4 @@ Types, | ||
EdgeNullability, | ||
NodeNullability | ||
NodeNullability, | ||
ConnectionResult | ||
>; | ||
@@ -330,2 +360,13 @@ | ||
Resolved, | ||
ConnectionResult extends ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
> = ConnectionResultShape< | ||
Types, | ||
ShapeFromTypeParam<Types, Type, false>, | ||
EdgeNullability, | ||
NodeNullability | ||
>, | ||
> = Resolved extends Promise<infer T> | ||
@@ -340,6 +381,27 @@ ? NonNullable<T> extends ConnectionShapeForType< | ||
? NonNullable<T> | ||
: ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> | ||
: Resolved extends ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability> | ||
: ConnectionShapeForType< | ||
Types, | ||
Type, | ||
Nullable, | ||
EdgeNullability, | ||
NodeNullability, | ||
ConnectionResult | ||
> | ||
: Resolved extends ConnectionShapeForType< | ||
Types, | ||
Type, | ||
Nullable, | ||
EdgeNullability, | ||
NodeNullability, | ||
ConnectionResult | ||
> | ||
? NonNullable<Resolved> | ||
: ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>; | ||
: ConnectionShapeForType< | ||
Types, | ||
Type, | ||
Nullable, | ||
EdgeNullability, | ||
NodeNullability, | ||
ConnectionResult | ||
>; | ||
@@ -346,0 +408,0 @@ export interface DefaultConnectionArguments extends PothosSchemaTypes.DefaultConnectionArguments {} |
@@ -10,2 +10,8 @@ import { | ||
// Since we know the return types of the connection helpers, we can | ||
// remove the MaybePromise wrappers on the ConnectionResult shape | ||
type RemoveMaybePromiseProps<T> = { | ||
[K in keyof T]: Awaited<T[K]>; | ||
}; | ||
interface ResolveOffsetConnectionOptions { | ||
@@ -91,8 +97,10 @@ args: DefaultConnectionArguments; | ||
): Promise< | ||
ConnectionShape< | ||
SchemaTypes, | ||
NonNullable<T>, | ||
U extends NonNullable<U> ? (Promise<null> extends U ? true : false) : true, | ||
T extends NonNullable<T> ? false : { list: false; items: true }, | ||
false | ||
RemoveMaybePromiseProps< | ||
ConnectionShape< | ||
SchemaTypes, | ||
NonNullable<T>, | ||
U extends NonNullable<U> ? (Promise<null> extends U ? true : false) : true, | ||
T extends NonNullable<T> ? false : { list: false; items: true }, | ||
false | ||
> | ||
> | ||
@@ -147,8 +155,10 @@ > { | ||
array: T[], | ||
): ConnectionShape< | ||
SchemaTypes, | ||
NonNullable<T>, | ||
false, | ||
T extends NonNullable<T> ? false : { list: false; items: true }, | ||
false | ||
): RemoveMaybePromiseProps< | ||
ConnectionShape< | ||
SchemaTypes, | ||
NonNullable<T>, | ||
false, | ||
T extends NonNullable<T> ? false : { list: false; items: true }, | ||
false | ||
> | ||
> { | ||
@@ -216,3 +226,5 @@ const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs(options); | ||
resolve: (params: ResolveCursorConnectionArgs) => U, | ||
): Promise<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>> { | ||
): Promise< | ||
RemoveMaybePromiseProps<ConnectionShape<SchemaTypes, NodeType<U>, false, false, false>> | ||
> { | ||
const { before, after, limit, inverted, expectedSize, hasPreviousPage, hasNextPage } = | ||
@@ -219,0 +231,0 @@ parseCurserArgs(options); |
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
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
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
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
417180
5364