You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

graphql-codegen-typescript-typedefs

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-codegen-typescript-typedefs

Adds the combined graphql schema (string) and type definitions (DocumentNode) to the generated typescript file.

0.0.10
latest
npmnpm
Version published
Maintainers
0
Created
Source

GraphQL Codegen Typescript TypeDefs plugin

Adds the combined graphql schema (string) and type definitions (DocumentNode) to the generated typescript file.

Useful whenever you need the type definitions as a DocumentNode.

Warning:

The generated values are not just types, but actual values and may contribute to your bundle size.

Usage

Install Plugin

yarn add --dev graphql-codegen-typescript-typedefs
npm install --save-dev graphql-codegen-typescript-typedefs

Setup Codegen Config

Add the typescript-typedefs plugin to your codegen config.

Ex.

# codegen.yaml
generates:
  generated-types.ts:
    schema: "**/*.graphqls"
    plugins:
      - typescript
      - typescript-typedefs

The following variables will be exported by the generated file:

Variable NameTypeContent
SchemastringThe combined GraphQL schema in a compact string
TypeDefsDocumentNodeThe type definitions of the combined schema

Options

typesPrefix

Prefix the variables with this string.

parseSchema

Parse the schema string directly in the generated code by using gql from graphql-tag.

This is useful if you want to keep the generated code as small as possible.

useNamedImport

This option can be used together with parseSchema.

Generate import { gql } from "graphql-tag" instead of import gql from "graphql-tag"

Example Usage

import { TypeDefs } from "generated-types";

// ...

const server = new ApolloServer({ typeDefs: TypeDefs, resolvers });

FAQs

Package last updated on 19 Mar 2025

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