Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-codegen/core

Package Overview
Dependencies
Maintainers
4
Versions
4898
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-codegen/core

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8M
decreased by-12.06%
Maintainers
4
Weekly downloads
 
Created

What is @graphql-codegen/core?

@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.

What are @graphql-codegen/core's main functionalities?

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();

Other packages similar to @graphql-codegen/core

Keywords

FAQs

Package last updated on 06 Feb 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc