Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@graphql-codegen/typescript
Advanced tools
GraphQL Code Generator plugin for generating TypeScript types
The @graphql-codegen/typescript package is a powerful tool designed for generating TypeScript typings directly from GraphQL schemas and operations. It automates the process of creating type definitions, making it easier to work with GraphQL in TypeScript projects by ensuring type safety and reducing the manual effort required to keep types in sync with the GraphQL schema.
Generating TypeScript Types from a GraphQL Schema
This feature allows you to generate TypeScript interfaces and types from a GraphQL schema. The code sample demonstrates how to programmatically generate TypeScript types using the GraphQL Code Generator CLI.
const { generate } = require('@graphql-codegen/cli');
async function generateTypes() {
const output = await generate(
{
schema: './schema.graphql',
generates: {
'./types.ts': {
plugins: ['typescript']
}
}
},
true
);
}
generateTypes();
Generating TypeScript Operations (Queries, Mutations, Subscriptions)
This feature generates TypeScript types for GraphQL operations, such as queries, mutations, and subscriptions. The code sample shows how to generate types for operations, enhancing type safety and development experience in TypeScript projects.
const { generate } = require('@graphql-codegen/cli');
async function generateOperations() {
const output = await generate(
{
schema: './schema.graphql',
documents: './src/**/*.graphql',
generates: {
'./graphql.ts': {
plugins: ['typescript', 'typescript-operations']
}
}
},
true
);
}
generateOperations();
Apollo Client is a comprehensive state management library for JavaScript that enables you to manage both local and remote data with GraphQL. While it provides strong integration with GraphQL, including generating types for operations, it is more focused on state management rather than solely on type generation like @graphql-codegen/typescript.
GraphQL Code Generator is the core package that @graphql-codegen/typescript is a part of. It supports various plugins for different languages and tools, making it highly versatile. While @graphql-codegen/typescript focuses specifically on TypeScript, graphql-code-generator provides a broader ecosystem for code generation across different technologies.
TypeGraphQL is a framework for building GraphQL APIs in Node.js with TypeScript, focusing on defining the schema using TypeScript classes. Unlike @graphql-codegen/typescript, which generates types from an existing schema, TypeGraphQL allows you to create the schema directly from TypeScript classes, offering a different approach to integrating GraphQL with TypeScript.
FAQs
GraphQL Code Generator plugin for generating TypeScript types
The npm package @graphql-codegen/typescript receives a total of 2,880,347 weekly downloads. As such, @graphql-codegen/typescript popularity was classified as popular.
We found that @graphql-codegen/typescript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.