
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
@graphql-codegen/typescript-resolvers
Advanced tools
GraphQL Code Generator plugin for generating TypeScript types for resolvers signature
@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.
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!');
});
graphql-codegen-typescript is another plugin for GraphQL Code Generator that generates TypeScript typings for your GraphQL operations and schema. While it focuses on generating types for the schema and operations, it does not specifically generate resolver types like @graphql-codegen/typescript-resolvers.
graphql-tools is a set of utilities from Apollo that includes schema stitching, mock server, and schema generation. It provides some type safety features but does not generate TypeScript resolver types directly. It is more focused on schema creation and manipulation.
type-graphql is a library that allows you to create GraphQL schemas using TypeScript classes and decorators. It provides a different approach to type safety by leveraging TypeScript's type system directly in the schema definition, rather than generating types from an existing schema.
FAQs
GraphQL Code Generator plugin for generating TypeScript types for resolvers signature
The npm package @graphql-codegen/typescript-resolvers receives a total of 551,467 weekly downloads. As such, @graphql-codegen/typescript-resolvers popularity was classified as popular.
We found that @graphql-codegen/typescript-resolvers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.