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.
yarn add --dev graphql-codegen-typescript-typedefs
npm install --save-dev graphql-codegen-typescript-typedefs
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 Name | Type | Content |
---|---|---|
Schema | string |
The combined GraphQL schema in a compact string |
TypeDefs | DocumentNode |
The type definitions of the combined schema |
Prefix the variables with this string.
Use import { gql } from "graphql-tag"
instead of import gql from "graphql-tag"
import { TypeDefs } from "generated-types";
// ...
const server = new ApolloServer({ typeDefs: TypeDefs, resolvers });