Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@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
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.