Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@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,890,049 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 0 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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.