import type { DirectiveNode, DocumentNode, GraphQLFieldConfig, GraphQLResolveInfo } from 'graphql'; import type { Plugin } from 'graphql-yoga'; import type { GlobalContext } from '@cedarjs/context'; export interface DirectiveParams> { root: unknown; args: Record; context: GlobalContext; info: GraphQLResolveInfo; directiveNode?: DirectiveNode; directiveArgs: DirectiveArgs; resolvedValue: FieldType; } /** * Generic Type for the arguments/parameters passed to the validate function for validator directives * * You have to pass in the type of directiveArgs * @example ValidateArgs<{ roles?: string[] }> */ export declare type ValidateArgs> = Omit, // we remove resolvedValue anyway in this type 'resolvedValue'>; /** * Write your validation logic inside this function. * Validator directives do not have access to the field value, i.e. they are called before resolving the value * * - Throw an error, if you want to stop executing e.g. not sufficient permissions * - Validator directives can be async or sync * - Returned value will be ignored * * You have to pass in the type of directiveArgs * @example ValidatorDirectiveFunc<{ roles?: string[] }> * */ export type ValidatorDirectiveFunc> = (args: ValidateArgs) => Promise | void; /** * Generic Type for the arguments/parameters passed to the transform function for transformer directives * * You have to pass in the type of directiveArgs, and the resolverValue (i.e. the type of the field you are transforming) * @example TransformArgs */ export declare type TransformArgs> = DirectiveParams; /** * Write your transformation logic inside this function. * Transformer directives run **after** resolving the value * * - You can also throw an error, if you want to stop executing, but note that the value has already been resolved * - Transformer directives **must** be synchronous, and return a value * * You have to pass in the type of directiveArgs, and the resolverValue (i.e. the type of the field you are transforming) * @example TransformerDirectiveFunc * */ export type TransformerDirectiveFunc> = (args: TransformArgs) => TField; export declare enum DirectiveType { VALIDATOR = "VALIDATOR_DIRECTIVE", TRANSFORMER = "TRANSFORMER_DIRECTIVE" } export type CedarDirective = ValidatorDirective | TransformerDirective; /** @deprecated Use `CedarDirective` instead. */ export type RedwoodDirective = CedarDirective; export interface ValidatorDirective extends ValidatorDirectiveOptions { schema: DocumentNode; } export interface TransformerDirective extends TransformerDirectiveOptions { schema: DocumentNode; } interface ValidatorDirectiveOptions { onResolvedValue: ValidatorDirectiveFunc; type: DirectiveType.VALIDATOR; name: string; } interface TransformerDirectiveOptions { onResolvedValue: TransformerDirectiveFunc; type: DirectiveType.TRANSFORMER; name: string; } export type DirectivePluginOptions = ValidatorDirectiveOptions | TransformerDirectiveOptions; export declare function hasDirective(info: GraphQLResolveInfo): boolean; export declare function getDirectiveByName(fieldConfig: GraphQLFieldConfig, directiveName: string): null | DirectiveNode; export declare function isPromise(value: any): value is Promise; export type UseCedarDirectiveReturn = Plugin<{ onResolvedValue: ValidatorDirectiveFunc | TransformerDirectiveFunc; }>; /** @deprecated Use `UseCedarDirectiveReturn` instead. */ export type useRedwoodDirectiveReturn = UseCedarDirectiveReturn; export declare const useCedarDirective: (options: DirectivePluginOptions) => UseCedarDirectiveReturn; /** @deprecated Use `useCedarDirective` instead. */ export declare const useRedwoodDirective: (options: DirectivePluginOptions) => UseCedarDirectiveReturn; export {}; //# sourceMappingURL=useRedwoodDirective.d.ts.map