github dotansimha/graphql-code-generator @graphql-codegen/typescript-resolvers@2.2.0

latest releases: release-1730117942954, @graphql-codegen/visitor-plugin-common@5.5.0, @graphql-codegen/typescript@4.1.1...
3 years ago

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
    }

Patch Changes

  • Updated dependencies [d6c2d4c]
  • Updated dependencies [feeae1c]
  • Updated dependencies [8261e41]
  • Updated dependencies [5086791]
    • @graphql-codegen/visitor-plugin-common@2.2.0
    • @graphql-codegen/typescript@2.2.0

Don't miss a new graphql-code-generator release

NewReleases is sending notifications on new releases.