Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@graphql-codegen/core
Advanced tools
@graphql-codegen/core is a powerful tool for generating code from GraphQL schemas and operations. It allows developers to automate the creation of type-safe code, reducing the risk of errors and improving development efficiency.
Generate TypeScript Types
This feature allows you to generate TypeScript types from a GraphQL schema. The code sample demonstrates how to use the @graphql-codegen/core package along with the TypeScript plugin to generate type definitions.
const { generate } = require('@graphql-codegen/core');
const typescriptPlugin = require('@graphql-codegen/typescript');
const schema = `
type Query {
hello: String
}
`;
const config = {
documents: [],
config: {},
filename: 'types.ts',
schema: schema,
plugins: [
{ typescript: {} }
],
pluginMap: {
typescript: typescriptPlugin
}
};
async function generateTypes() {
const output = await generate(config, true);
console.log(output);
}
generateTypes();
Generate React Apollo Hooks
This feature allows you to generate React Apollo hooks from a GraphQL schema and operations. The code sample demonstrates how to use the @graphql-codegen/core package along with the TypeScript and React Apollo plugins to generate hooks.
const { generate } = require('@graphql-codegen/core');
const typescriptPlugin = require('@graphql-codegen/typescript');
const reactApolloPlugin = require('@graphql-codegen/typescript-react-apollo');
const schema = `
type Query {
hello: String
}
`;
const documents = `
query GetHello {
hello
}
`;
const config = {
documents: [{ document: documents }],
config: {},
filename: 'hooks.ts',
schema: schema,
plugins: [
{ typescript: {} },
{ 'typescript-react-apollo': {} }
],
pluginMap: {
typescript: typescriptPlugin,
'typescript-react-apollo': reactApolloPlugin
}
};
async function generateHooks() {
const output = await generate(config, true);
console.log(output);
}
generateHooks();
graphql-code-generator is a comprehensive tool for generating code from GraphQL schemas and operations. It offers a wide range of plugins and supports multiple languages and frameworks. Compared to @graphql-codegen/core, it provides a more extensive set of features and integrations.
apollo-codegen is a tool specifically designed for generating code for Apollo Client. It supports TypeScript and Flow and can generate type definitions and query/mutation hooks. While it is more focused on Apollo Client, @graphql-codegen/core offers a broader range of plugins and use cases.
Live demo and full documentation: the-guild.dev/graphql/codegen
Project repository: graphql-code-generator
FAQs
Unknown package
The npm package @graphql-codegen/core receives a total of 613,148 weekly downloads. As such, @graphql-codegen/core popularity was classified as popular.
We found that @graphql-codegen/core 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.