@graphql-codegen/typescript-resolvers

  • Version 2.7.3
  • Published
  • 47.8 kB
  • 6 dependencies
  • MIT license

Install

npm i @graphql-codegen/typescript-resolvers
yarn add @graphql-codegen/typescript-resolvers
pnpm add @graphql-codegen/typescript-resolvers

Overview

GraphQL Code Generator plugin for generating TypeScript types for resolvers signature

Index

Variables

variable plugin

const plugin: PluginFunction<
TypeScriptResolversPluginConfig,
Types.ComplexPluginOutput
>;

    Classes

    class TypeScriptResolversVisitor

    class TypeScriptResolversVisitor extends BaseResolversVisitor<
    TypeScriptResolversPluginConfig,
    ParsedTypeScriptResolversConfig
    > {}

      constructor

      constructor(
      pluginConfig: TypeScriptResolversPluginConfig,
      schema: GraphQLSchema
      );

        method buildEnumResolverContentBlock

        protected buildEnumResolverContentBlock: (
        node: EnumTypeDefinitionNode,
        mappedEnumType: string
        ) => string;

          method buildEnumResolversExplicitMappedValues

          protected buildEnumResolversExplicitMappedValues: (
          node: EnumTypeDefinitionNode,
          valuesMapping: { [valueName: string]: string | number }
          ) => string;

            method formatRootResolver

            protected formatRootResolver: (
            schemaTypeName: string,
            resolverType: string,
            declarationKind: DeclarationKind
            ) => string;

              method getParentTypeForSignature

              protected getParentTypeForSignature: (
              node: FieldDefinitionNode
              ) => 'ParentType' | 'UnwrappedObject<ParentType>';

                method getPunctuation

                protected getPunctuation: (_declarationKind: DeclarationKind) => string;

                  method ListType

                  ListType: (node: ListTypeNode) => string;

                    method NamedType

                    NamedType: (node: NamedTypeNode) => string;

                      method NonNullType

                      NonNullType: (node: NonNullTypeNode) => string;

                        method transformParentGenericType

                        protected transformParentGenericType: (parentType: string) => string;

                          method wrapWithListType

                          protected wrapWithListType: (str: string) => string;

                            Interfaces

                            interface TypeScriptResolversPluginConfig

                            interface TypeScriptResolversPluginConfig extends RawResolversConfig {}
                            • This plugin generates TypeScript signature for resolve functions of your GraphQL API. You can use this plugin to generate simple resolvers signature based on your GraphQL types, or you can change its behavior be providing custom model types (mappers).

                              You can find a blog post explaining the usage of this plugin here: https://the-guild.dev/blog/better-type-safety-for-resolvers-with-graphql-codegen

                            property allowParentTypeOverride

                            allowParentTypeOverride?: boolean;
                            • Allow you to override the ParentType generic in each resolver, by avoid enforcing the base type of the generated generic type.

                              This will generate ParentType = Type instead of ParentType extends Type = Type in each resolver.

                              config:
                              allowParentTypeOverride: true

                            property customResolveInfo

                            customResolveInfo?: string;
                            • You can provide your custom GraphQLResolveInfo instead of the default one from graphql-js "graphql#GraphQLResolveInfo"

                              generates:
                              path/to/file.ts:
                              plugins:
                              - typescript
                              - typescript-resolvers
                              config:
                              customResolveInfo: ./my-types#MyResolveInfo

                            property customResolverFn

                            customResolverFn?: string;
                            • You can provide your custom ResolveFn instead the default. It has to be a type that uses the generics <TResult, TParent, TContext, TArgs> "(parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => Promise | TResult"

                              ## Custom Signature

                              generates:
                              path/to/file.ts:
                              plugins:
                              - typescript
                              - typescript-resolvers
                              config:
                              customResolverFn: ./my-types#MyResolveFn

                              ## With Graphile

                              generates:
                              path/to/file.ts:
                              plugins:
                              - add:
                              content: "import { GraphileHelpers } from 'graphile-utils/node8plus/fieldHelpers';"
                              - typescript
                              - typescript-resolvers
                              config:
                              customResolverFn: |
                              (
                              parent: TParent,
                              args: TArgs,
                              context: TContext,
                              info: GraphQLResolveInfo & { graphile: GraphileHelpers<TParent> }
                              ) => Promise<TResult> | TResult;

                            property directiveResolverMappings

                            directiveResolverMappings?: Record<string, string>;
                            • Map the usage of a directive into using a specific resolver.

                              config:
                              customResolverFn: ../resolver-types.ts#UnauthenticatedResolver
                              directiveResolverMappings:
                              authenticated: ../resolvers-types.ts#AuthenticatedResolver

                            property makeResolverTypeCallable

                            makeResolverTypeCallable?: boolean;
                            • Set to true in order to allow the Resolver type to be callable

                              config:
                              makeResolverTypeCallable: true

                            property noSchemaStitching

                            noSchemaStitching?: boolean;
                            • Disables/Enables Schema Stitching support. By default, the resolver signature does not include the support for schema-stitching. Set to false to enable that.

                              true

                              generates:
                              path/to/file.ts:
                              plugins:
                              - typescript
                              - typescript-resolvers
                              config:
                              noSchemaStitching: false

                            property optionalInfoArgument

                            optionalInfoArgument?: boolean;
                            • Sets info argument of resolver function to be optional field. Useful for testing.

                              config:
                              optionalInfoArgument: true

                            property useIndexSignature

                            useIndexSignature?: boolean;
                            • Adds an index signature to any generates resolver. false

                              generates:
                              path/to/file.ts:
                              plugins:
                              - typescript
                              - typescript-resolvers
                              config:
                              useIndexSignature: true

                            property wrapFieldDefinitions

                            wrapFieldDefinitions?: boolean;
                            • Set to true in order to wrap field definitions with FieldWrapper. This is useful to allow return types such as Promises and functions. Needed for compatibility with federation: true when true

                            Package Files (3)

                            Dependencies (6)

                            Dev Dependencies (0)

                            No dev dependencies.

                            Peer Dependencies (1)

                            Badge

                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@graphql-codegen/typescript-resolvers.

                            • Markdown
                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@graphql-codegen/typescript-resolvers)
                            • HTML
                              <a href="https://www.jsdocs.io/package/@graphql-codegen/typescript-resolvers"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>