UNPKG

@pothos/plugin-federation

Version:

A Pothos plugin for implementing apollo federation subGraphs

113 lines (112 loc) 6.48 kB
import '@pothos/plugin-directives'; import type { FieldNullability, FieldRequiredness, InferredFieldOptionsByKind, InputFieldMap, InputType, MaybePromise, Resolver, SchemaTypes, ShapeFromTypeParam, TypeParam } from '@pothos/core'; import type { GraphQLResolveInfo, GraphQLSchema } from 'graphql'; import type { KeyDirective, PothosFederationPlugin, Selection, SelectionFromShape, selectionShapeKey } from './index.js'; import type { ExternalEntityRef } from './external-ref.js'; declare global { export namespace PothosSchemaTypes { interface Plugins<Types extends SchemaTypes> { federation: PothosFederationPlugin<Types>; } interface PothosKindToGraphQLType { ExtendedEntity: "Object"; ExternalEntity: "Object"; EntityObject: "Object"; } interface FieldOptionsByKind<Types extends SchemaTypes, ParentShape, Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, Args extends InputFieldMap, ResolveShape, ResolveReturnShape> { ExtendedEntity: ObjectFieldOptions<Types, ParentShape & ResolveShape, Type, Nullable, Args, ResolveReturnShape> & { requires?: Selection<ResolveShape & object>; } & InferredFieldOptionsByKind<Types, Types["InferredFieldOptionsKind"], ParentShape & ResolveShape, Type, Nullable, Args, ResolveReturnShape>; ExternalEntity: ObjectFieldOptions<Types, ParentShape, Type, Nullable, Args, ResolveReturnShape>; EntityObject: ObjectFieldOptions<Types, ParentShape, Type, Nullable, Args, ResolveReturnShape> & { resolve: Resolver<ParentShape, Args, Types["Context"], Type extends [ unknown ] ? ((ShapeFromTypeParam<Types, Type, false> & unknown[])[number] & ResolveShape)[] : ResolveShape & ShapeFromTypeParam<Types, Type, false>, ResolveReturnShape>; }; } interface SchemaBuilder<Types extends SchemaTypes> { externalRef: <KeySelection extends Selection<object>, Shape extends object = KeySelection[typeof selectionShapeKey]>(name: string, key?: KeySelection | KeySelection[], resolveReference?: (parent: KeySelection[typeof selectionShapeKey], context: Types["Context"], info: GraphQLResolveInfo) => MaybePromise<Shape | null | undefined>) => ExternalEntityRef<Types, Shape, KeySelection>; selection: <Shape extends object>(selection: SelectionFromShape<Shape>) => Selection<Shape>; keyDirective: <Shape extends object, Resolvable extends boolean = true>(key: Selection<Shape>, resolvable?: Resolvable) => KeyDirective<Shape, Resolvable>; toSubGraphSchema: (options: BuildSchemaOptions<Types> & { linkUrl?: string; composeDirectives?: `@${string}`[]; federationDirectives?: string[]; }) => GraphQLSchema; asEntity: <Param extends InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>, KeySelection extends Selection<object>>(param: Param, options: { key: KeySelection | KeySelection[]; resolveReference: (parent: KeySelection[typeof selectionShapeKey], context: Types["Context"], info: GraphQLResolveInfo) => MaybePromise<ShapeFromTypeParam<Types, Param, true>>; interfaceObject?: Param extends ObjectRef<Types, unknown> ? boolean : never; }) => void; } interface UserSchemaTypes { FederationScopes: unknown; FederationPolicies: unknown; } interface ExtendDefaultTypes<PartialTypes extends Partial<UserSchemaTypes>> { FederationScopes: string extends PartialTypes["FederationScopes"] ? string : PartialTypes["FederationScopes"]; FederationPolicies: string extends PartialTypes["FederationPolicies"] ? string : PartialTypes["FederationPolicies"]; } interface ObjectTypeOptions<Types extends SchemaTypes, Shape> { shareable?: boolean; tag?: string[] | string; authenticated?: boolean; requiresScopes?: Types["FederationScopes"][][]; policy?: Types["FederationPolicies"][][]; cost?: number; } interface InterfaceTypeOptions<Types extends SchemaTypes, Shape> { authenticated?: boolean; requiresScopes?: Types["FederationScopes"][][]; policy?: Types["FederationPolicies"][][]; } interface ScalarTypeOptions<Types extends SchemaTypes> { authenticated?: boolean; requiresScopes?: Types["FederationScopes"][][]; policy?: Types["FederationPolicies"][][]; cost?: number; } interface EnumTypeOptions<Types extends SchemaTypes> { authenticated?: boolean; requiresScopes?: Types["FederationScopes"][][]; policy?: Types["FederationPolicies"][][]; cost?: number; } interface BaseTypeOptions<Types extends SchemaTypes = SchemaTypes> { inaccessible?: boolean; } interface EnumValueConfig<Types extends SchemaTypes> { inaccessible?: boolean; cost?: number; } interface FieldOptions<Types extends SchemaTypes, ParentShape, Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, Args extends InputFieldMap, ResolveShape, ResolveReturnShape> { shareable?: boolean; inaccessible?: boolean; override?: { from: string; label?: string; }; tag?: string[] | string; authenticated?: boolean; requiresScopes?: Types["FederationScopes"][][]; policy?: Types["FederationPolicies"][][]; cost?: number; listSize?: { assumedSize?: number; slicingArguments?: string[]; sizedFields?: string[]; requireOneSlicingArgument?: boolean; }; } interface InputFieldOptions<Types extends SchemaTypes = SchemaTypes, Type extends InputType<Types> | [ InputType<Types> ] = InputType<Types> | [ InputType<Types> ], Req extends FieldRequiredness<Type> = FieldRequiredness<Type>> { inaccessible?: boolean; tag?: string[] | string; cost?: number; } } } //# sourceMappingURL=global-types.d.ts.map