Minor Changes
-
5086791: Allow overwriting the resolver type signature based on directive usages.
WARNING: Using this option does only change the generated type definitions.
For actually ensuring that a type is correct at runtime you will have to use schema transforms (e.g. with @graphql-tools/utils mapSchema) that apply those rules! Otherwise, you might end up with a runtime type mismatch which could cause unnoticed bugs or runtime errors.
Example configuration:
config: # This was possible before customResolverFn: ../resolver-types.ts#UnauthenticatedResolver # This is new directiveResolverMappings: authenticated: ../resolvers-types.ts#AuthenticatedResolver
Example mapping file (
resolver-types.ts
):export type UnauthenticatedContext = { user: null; }; export type AuthenticatedContext = { user: { id: string }; }; export type UnauthenticatedResolver<TResult, TParent, _TContext, TArgs> = ( parent: TParent, args: TArgs, context: UnauthenticatedContext, info: GraphQLResolveInfo ) => Promise<TResult> | TResult; export type AuthenticatedResolver<TResult, TParent, _TContext, TArgs> = ( parent: TParent, args: TArgs, context: AuthenticatedContext, info: GraphQLResolveInfo ) => Promise<TResult> | TResult;
Example Schema:
directive @authenticated on FIELD_DEFINITION type Query { yee: String foo: String @authenticated }