import '@pothos/core' import '@pothos/plugin-scope-auth' import '@pothos/plugin-dataloader' import '@pothos/plugin-relay' import * as _pothos_core_dts_refs_union from '@pothos/core/dts/refs/union'; import * as _pothos_core_dts_refs_interface from '@pothos/core/dts/refs/interface'; import * as _pothos_plugin_dataloader from '@pothos/plugin-dataloader'; import { LoadableNodeOptions } from '@pothos/plugin-dataloader'; import { MaybePromise, SchemaTypes, OutputType, ShapeFromTypeParam, BasePlugin, InputFieldMap, Resolver, InputShapeFromFields, FieldKind, FieldOptionsFromKind, InputFieldsFromShape, FieldRef, InterfaceParam, ObjectTypeOptions, ImplementableObjectRef, EnumValues, EnumRef, ShapeFromEnumValues, InputObjectRef, InputFieldBuilder } from '@pothos/core'; import { GraphQLParams, YogaInitialContext } from 'graphql-yoga'; export { decodeGlobalID, encodeGlobalID } from '@pothos/plugin-relay'; import { GraphQLError } from 'graphql'; interface ListResultShape { totalCount?: number | null; nodes: MaybePromise[]; } type ListShape = ListResultShape> = (Nullable extends false ? never : null | undefined) | (ListResult & Types['ListWrapper']); type ListShapeForType, Nullable extends boolean, ListResult extends ListResultShape> = ListResultShape>> = ListShape, Nullable, ListResult>; declare class PothosListPlugin extends BasePlugin { } declare global { export namespace PothosSchemaTypes { interface Plugins { fuselist: PothosListPlugin; } interface UserSchemaTypes { ListWrapper: {}; } interface SchemaBuilder { listObject: , NodeNullable extends boolean>(listOptions: { name: string; type: Type; nullable: NodeNullable; }) => ObjectRef>; } interface ListFieldOptions, Nullable extends boolean, NodeNullability extends boolean, Args extends InputFieldMap, ResolveReturnShape, ConnectionResult extends ListResultShape> = ListResultShape>> { type: Type; args?: Args; nullable?: Nullable; nodeNullable?: NodeNullability; resolve: Resolver, Types['Context'], ListShapeForType, ResolveReturnShape>; } interface RootFieldBuilder { list: , Args extends InputFieldMap, Nullable extends boolean, NodeNullable extends boolean, ResolveShape, ResolveReturnShape, ConnectionResult extends ListResultShape> = ListResultShape>>(options: FieldOptionsFromKind, Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ListFieldOptions unknown; } ? P : unknown extends ResolveShape ? ParentShape : ResolveShape, Type, Nullable, NodeNullable, Args, ResolveReturnShape, ConnectionResult> & Omit : never) => FieldRef>; } } } type InitialContext = { headers: Headers; params: GraphQLParams; request: YogaInitialContext['request']; }; type UserContext = Record; type GetContext = ((ctx: InitialContext) => UserContext & AdditionalContext) | ((ctx: InitialContext) => Promise) | (UserContext & AdditionalContext); interface StellateOptions { loggingToken: string; serviceName: string; } declare abstract class FuseError extends GraphQLError { abstract readonly name: string; constructor(message: string, extensions: { code: string; http?: { status: number; }; }); } /** For use when user is not authenticated or unknown. */ declare class AuthenticationError extends FuseError { name: string; constructor(message?: string); } /** For use when a resource is not found or not accessible by an authenticated user. */ declare class ForbiddenError extends FuseError { name: string; constructor(message?: string); } /** For use when a resource is not found. */ declare class NotFoundError extends FuseError { name: string; constructor(message?: string); } /** For use when any input was invalid or when a resource does not exist but is assumed to exist. */ declare class BadRequestError extends FuseError { name: string; constructor(message?: string); } declare const builder: PothosSchemaTypes.SchemaBuilder>; type Builder = Omit; declare const reducedBuilder: Builder; type BuilderTypes = typeof builder extends PothosSchemaTypes.SchemaBuilder ? T : never; /** * An overridable type, which will be used in all your schema-building functions to inform * you what scopes are available to be used. * * @example * ```ts * import 'fuse' * import { defineAuthScopes, Scopes } from 'fuse' * * declare module 'fuse' { * export interface Scopes { * isLoggedIn: boolean * } * } * ``` */ interface Scopes { } /** * A function to define auth-scopes that can be used throughout your schema * definition to authorize both fields as well as types. * * @remarks * This function should only be called once and will carry your scope-definitions for * the lifetime of the application. * * @example * ```ts * defineAuthScopes((ctx) => ({ isLoggedIn: !!ctx.user })) * addQueryFields((t) => ({ * me: t.field({ * type: User, * authScopes: { * isLoggedIn: true, * }, * resolve: async (_, args, context) => { * // return the user * } * }), * })) * ``` */ declare const defineAuthScopes: (func: (ctx: any) => Promise | Scopes) => void; /** A function to create a keyed object, this will inherit from the `Node` interface and hence be * query-able from `node(id: ID!): Node` and `nodes(ids: [ID!]!): [Node]`. Additionally a Query.typeName * will be created that you can query with (id: ID!). * * @remarks * This is a helper function to create a node with an associated way to fetch it. * Nodes get assigned a unique ID which is derived from `base64Encode(nameOfType + node[key || 'id'])`. * The fields property can be used to rename properties, type them and even create custom resolve functions * for computed properties or transformations. * Optionally when the output-type has no `id` property you can use the `key` option to specify a different * property used to uniquely identify the node. * * @example * ```ts * export const LaunchNode = node({ * name: 'Launch', * key: 'flight_number', * async load(ids) { * // get and return the data * } * fields: (t) => ({ * // we tell our node that it can find the name on a different property named mission_name and to * // expose it as a string. * name: t.exposeString('mission_name'), * details: t.exposeString('details', { nullable: true }), * image: t.field({ * type: 'String', * resolve: (parent) => parent.links.mission_patch, * }), * launchDate: t.exposeString('launch_date_utc'), * }), * }) * ``` */ declare function node[] = InterfaceParam[]>(opts: ('id' extends keyof T ? { name: string; key?: keyof T; description?: string; load: (ids: Array, ctx: Record) => Promise>; } : { name: string; key: keyof T; description?: string; load: (ids: Array, ctx: Record) => Promise>; }) & Pick, 'authScopes' | 'fields' | 'interfaces' | 'isTypeOf'>): Omit<_pothos_plugin_dataloader.ImplementableLoadableNodeRef, Record>; } & UserContext; AuthScopes: Scopes; DefaultFieldNullability: true; Scalars: { JSON: { Input: unknown; Output: unknown; }; Date: { Input: Date; Output: Date; }; }; }>, T | Key, T, string, Key, Key>, "implement">; /** * A function to create an (unkeyed) object that can be resolved, this can subsequently be used in a * query/mutation/node/... * * @example * ```ts * const Location = objectType({ * name: 'Location', * fields: (t) => ({ * name: t.exposeString('name'), * region: t.exposeString('region'), * latitude: t.exposeFloat('latitude'), * longitude: t.exposeFloat('longitude'), * }), *}) * ``` */ declare function objectType[] = InterfaceParam[]>(opts: { name: string; } & Omit, T, Interfaces>, 'name'>): PothosSchemaTypes.ObjectRef; /** * Add entry points to the graph, these can subsequently be used from your * front-end to query data. * * @example * ```ts * addQueryFields((t) => ({ * launches: t.list({ * description: 'Get a paginated list of launches.', * type: LaunchNode, * args: { limit: t.arg.int({ default: 10 }), offset: t.arg.int({ default: 0 }) } * resolve: async (_, args) => { * const data = fetch(`/launches?offset=${args.offset}&limit=${args.limit}`).then((x) => x.json())); * return { nodes: data.results, totalCount: data.count } * } * }) * }) * ``` */ declare const addQueryFields: typeof builder.queryFields; /** * Add entry points to the graph, these can subsequently be used from your * front-end to query data. * * @example * ```ts * addMutationFields((t) => ({ * addToCart: t.field({ * description: 'Add a product to the cart.', * type: Cart, * args: { productId: t.arg.string() }, * resolve: async (_, args, context) => { * const data = fetch('/cart', { * method: 'POST', * body: JSON.stringify({ product: args.productId }). * headers: { Authorization: context.token } * }).then((x) => x.json())); * return data * } * }) * }) * ``` */ declare const addMutationFields: typeof builder.mutationFields; /** * Add more fields to an existing objectType. * * @example * ```ts * addObjectFields(CartObject, (t) => ({ * user: t.field({ * description: 'The user owning a certain cart.', * type: User, * resolve: (parent) => { * const data = fetch(`/users/${parent.userId}`).then((x) => x.json())); * return data; * } * }) * }) */ declare const addObjectFields: typeof builder.objectFields; /** * Add more fields to an existing node. * * @example * ```ts * addNodeFields(LaunchNode, (t) => ({ * rocket: t.field({ * description: 'The rocket used for a given launch.', * type: Rocket, * resolve: (parent) => { * const data = fetch(`/rockets/${parent.rocketId}`).then((x) => x.json())); * return data; * } * }) * }) */ declare const addNodeFields: typeof builder.objectFields; /** * Narrow down the possible values of a field by providing an enum. * * @example * ```ts * const SiteStatus = enumType({ * name: 'SiteStatus', * description: 'Describes the Status of a given Launch Site', * values: ['ACTIVE', 'INACTIVE', 'UNKNOWN'] as const * }) * * // Which can then be used like * t.field({ * type: SiteStatus, * resolve: (parent) => { * switch (parent.status) { * case 'active': * return 'ACTIVE' * case 'inactive': * return 'INACTIVE' * default: * return 'UNKNOWN' * } * }, * }), * ``` */ declare const enumType: >>(opts: { name: string; } & PothosSchemaTypes.EnumTypeOptions, Values>) => EnumRef, Values>>; interface InputObjectTypeOptions { isOneOf?: boolean; fields: (t: InputFieldBuilder) => Fields; description?: string; extensions?: Readonly>; } /** * Creates a re-usable input-type that can be used in arguments to your fields. * * @example * ```ts * const Pagination = inputType({ * description: 'The default pagination input type, allowing you to specify a limit and offset', * name: 'Pagination', * fields: (t) => ({ * limit: t.int({ default: 10 }), * offset: t.int({ default: 0 }) * }) * }) * * addQueryFields((t) => ({ * myList: t.list({ * args: input: t.arg({ type: Pagination }) * }) * }) * ``` */ declare const inputType: (opts: { name: string; } & InputObjectTypeOptions, Fields>) => InputObjectRef>; /** * Creates an interface-type which can be used in the `interfaces` option of `object` and `node`. * * @example * ```ts * const NewInterface = interfaceType({ * name: 'NewInterface', * resolveType: (parent) => 'Launch', * fields: (t) => ({ * name: t.string() * }), * }) * ``` */ declare const interfaceType: (opts: Parameters<(typeof builder)['interfaceType']>['1'] & { name: string; }) => _pothos_core_dts_refs_interface.default; /** * Creates a union of types, these can be used in fields and will then have to resolve to * one of the union types. * * @example * ```ts * const NewInterface = unionType({ * name: 'Resource', * resolveType: (parent) => 'Engine', * types: [Fuel, Engine] * }) * ``` */ declare const unionType: (opts: Parameters<(typeof builder)['unionType']>['1'] & { name: string; }) => _pothos_core_dts_refs_union.default; export { AuthenticationError, BadRequestError, ForbiddenError, FuseError, GetContext, InitialContext, NotFoundError, Scopes, StellateOptions, UserContext, addMutationFields, addNodeFields, addObjectFields, addQueryFields, reducedBuilder as builder, defineAuthScopes, enumType, inputType, interfaceType, node, objectType, unionType };