import type { GraphQLFieldResolver } from "graphql"; import { GraphQLSchema } from "graphql"; import * as graphql from "graphql"; import type { AbstractTypePlanner, ArgumentApplyPlanResolver, BaseGraphQLArguments, EnumValueApplyResolver, FieldPlanResolver, InputObjectFieldApplyResolver, InputObjectTypeBakedResolver, PlanTypeInfo, ScalarPlanResolver } from "./interfaces.ts"; import type { Step } from "./step.ts"; export interface ObjectFieldConfig { plan?: FieldPlanResolver; subscribePlan?: FieldPlanResolver; resolve?: GraphQLFieldResolver; subscribe?: GraphQLFieldResolver; args?: { [argName: string]: ArgumentApplyPlanResolver | { applyPlan?: ArgumentApplyPlanResolver; applySubscribePlan?: ArgumentApplyPlanResolver; extensions?: graphql.GraphQLArgumentExtensions; }; }; } /** * When defining a field with `typeDefs/objects` you can declare the field plan * directly, or you can define a configuration object that accepts the plan and * more. */ export type FieldPlan = FieldPlanResolver | ObjectFieldConfig; export type DeprecatedObjectPlan = { __assertStep?: ((step: Step) => asserts step is TSource) | { new (...args: any[]): TSource; }; __isTypeOf?: graphql.GraphQLIsTypeOfFn; __planType?($specifier: Step): TSource; } & { [key: string]: FieldPlan; }; /** * The plans/config for each field of a GraphQL object type. */ export interface ObjectPlan { assertStep?: ((step: Step) => asserts step is TSource) | { new (...args: any[]): TSource; }; isTypeOf?: graphql.GraphQLIsTypeOfFn; planType?($specifier: Step): TSource; plans?: { [key: string]: FieldPlan; }; } /** * The plans for each field of a GraphQL input object type. */ export type DeprecatedInputObjectPlan = { __baked?: InputObjectTypeBakedResolver; } & { [fieldName: string]: InputObjectFieldApplyResolver | { apply?: InputObjectFieldApplyResolver; extensions?: graphql.GraphQLInputFieldExtensions; }; }; export interface InputObjectFieldConfig { apply?: InputObjectFieldApplyResolver; extensions?: graphql.GraphQLInputFieldExtensions; } export type InputFieldPlan = InputObjectFieldApplyResolver | InputObjectFieldConfig; export interface InputObjectPlan { baked?: InputObjectTypeBakedResolver; plans?: { [fieldName: string]: InputFieldPlan; }; } /** * The plan config for an interface or union type. * * @param TSource - A step representing the data at the abstract position * @param TSpecifier - The runtime data that specifies which concrete type the abstract step relates to */ export interface AbstractTypePlan { /** * Runtime. If the polymorphic data just needs resolving to a type name, this * method can be used to return said type name. If planning of polymorphism * is more complex for this polymorphic type (for example, if it includes * fetching of data) then the `planType` method should be used instead. * * Warning: this method is more expensive than planType because it requires * the implementation of GraphQL.js emulation. */ resolveType?: graphql.GraphQLTypeResolver; /** * Takes a step representing this polymorphic position, and returns a * "specifier" step that will be input to planType. If not specified, the * step's own `.toSpecifier()` will be used, if present, otherwise the * step's own `.toRecord()`, and failing that the step itself. */ toSpecifier?($step: TSource): Step; /** * Plantime. `$specifier` is either a step returned from a field or list * position with an abstract type, or a `__ValueStep` that represents the * combined values of such steps (to prevent unbounded plan branching). * `planType` must then construct a step that represents the `__typename` * related to this given specifier (or `null` if no match can be found) and a * `planForType` method which, when called, should return the step for the * given type. */ planType?: ($specifier: Step, info: PlanTypeInfo) => AbstractTypePlanner; } export interface InterfacePlan extends AbstractTypePlan { } export interface UnionPlan extends AbstractTypePlan { } export type DeprecatedUnionOrInterfacePlan = { [TKey in keyof AbstractTypePlan as `__${TKey}`]: AbstractTypePlan[TKey]; }; /** * The config for a GraphQL scalar type. */ export interface ScalarPlan extends Omit, "name" | "description" | "specifiedByURL" | "astNode" | "extensionASTNodes"> { plan?: ScalarPlanResolver; } export interface EnumValueConfig extends Omit { apply?: EnumValueApplyResolver; } export type EnumValueInput = EnumValueApplyResolver | EnumValueConfig | string | number | boolean; /** * The values/configs for the entries in a GraphQL enum type. */ export interface EnumPlan { values?: { [enumValueName: string]: EnumValueInput | undefined; }; } /** * A map from GraphQL named type to the config for that type. * * @deprecated Please use the different plan types instead */ export interface GrafastPlans { [typeName: string]: DeprecatedObjectPlan | DeprecatedInputObjectPlan | DeprecatedUnionOrInterfacePlan | ScalarPlan | EnumPlan; } export interface GrafastSchemaConfig { typeDefs: string | graphql.DocumentNode | graphql.DocumentNode[]; /** * All the different types of plans smooshed together to simulate the old * typeDefs/resolvers pattern. Avoid. * * @deprecated Please use objects, unions, interfaces, inputObjects, scalars or enums as appropriate. */ plans?: GrafastPlans; scalars?: { [typeName: string]: ScalarPlan; }; enums?: { [typeName: string]: EnumPlan; }; objects?: { [typeName: string]: ObjectPlan; }; unions?: { [typeName: string]: UnionPlan; }; interfaces?: { [typeName: string]: InterfacePlan; }; inputObjects?: { [typeName: string]: InputObjectPlan; }; extensions?: graphql.GraphQLSchemaExtensions; enableDeferStream?: boolean; } /** * Takes a GraphQL schema definition in Interface Definition Language (IDL/SDL) * syntax and configs for the types in it and returns a GraphQL schema. */ export declare function makeGrafastSchema(details: GrafastSchemaConfig): GraphQLSchema; //# sourceMappingURL=makeGrafastSchema.d.ts.map