Security News
OpenJS: “XZ Utils Cyberattack Likely Not an Isolated Incident”
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
@graphql-codegen/typescript
Advanced tools
Weekly downloads
Package description
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,608,526 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.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
Company News
Come meet the Socket team at BSidesSF and RSA! We're sponsoring several fun networking events and we would love to see you there.
Security News
OSI is starting a conversation aimed at removing the excuse of the SaaS loophole for companies navigating licensing and the complexities of doing business with open source.