Socket
Socket
Sign inDemoInstall

@graphql-codegen/typescript-resolvers

Package Overview
Dependencies
Maintainers
4
Versions
6005
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-codegen/typescript-resolvers

GraphQL Code Generator plugin for generating TypeScript types for resolvers signature


Version published
Weekly downloads
639K
decreased by-11.56%
Maintainers
4
Weekly downloads
 
Created

What is @graphql-codegen/typescript-resolvers?

@graphql-codegen/typescript-resolvers is a plugin for GraphQL Code Generator that generates TypeScript typings for your GraphQL resolvers. This helps in ensuring type safety and better developer experience when working with GraphQL APIs in TypeScript.

What are @graphql-codegen/typescript-resolvers's main functionalities?

Generate TypeScript Resolver Types

This feature allows you to generate TypeScript types for your GraphQL resolvers based on your GraphQL schema. The generated types help in ensuring that your resolvers adhere to the schema, providing type safety and reducing runtime errors.

const config = {
  schema: 'path/to/your/schema.graphql',
  generates: {
    'path/to/output.ts': {
      plugins: ['typescript', 'typescript-resolvers']
    }
  }
};

// Run the codegen
import { generate } from '@graphql-codegen/cli';
generate(config).then(() => {
  console.log('Types generated successfully!');
});

Custom Scalars Mapping

This feature allows you to map custom scalars in your GraphQL schema to specific TypeScript types. This is useful when you have custom scalar types like DateTime or JSON in your schema and you want to ensure they are correctly typed in TypeScript.

const config = {
  schema: 'path/to/your/schema.graphql',
  generates: {
    'path/to/output.ts': {
      plugins: ['typescript', 'typescript-resolvers'],
      config: {
        scalars: {
          DateTime: 'Date',
          JSON: 'any'
        }
      }
    }
  }
};

// Run the codegen
import { generate } from '@graphql-codegen/cli';
generate(config).then(() => {
  console.log('Types generated with custom scalars!');
});

Context Type

This feature allows you to specify a custom context type for your resolvers. The context type is often used to pass shared data like authentication information or database connections to your resolvers. By specifying the context type, you ensure that your resolvers have access to the correct context properties.

const config = {
  schema: 'path/to/your/schema.graphql',
  generates: {
    'path/to/output.ts': {
      plugins: ['typescript', 'typescript-resolvers'],
      config: {
        contextType: './my-context#MyContext'
      }
    }
  }
};

// Run the codegen
import { generate } from '@graphql-codegen/cli';
generate(config).then(() => {
  console.log('Types generated with custom context type!');
});

Other packages similar to @graphql-codegen/typescript-resolvers

FAQs

Package last updated on 19 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc