Registry / devops / graphql-typescript

graphql-typescript

JSON →
library0.3.0jsnpmunverified

Define and build GraphQL schemas using TypeScript classes with decorators (static v0.3.0, last release Sep 2020). Uses `@Type`, `@Field`, `@Mutation`, `@Nullable`, and `@Input` decorators to generate a full GraphQL schema via `makeSchema()`. Unlike type-graphql or nestjs/graphql, it is minimal with no dependency injection, no resolvers file, and no runtime reflection beyond decorator metadata. Requires `graphql@^0.13.2` (not v15+) and TypeScript with `experimentalDecorators` and `emitDecoratorMetadata`. Unmaintained since 2020 – incompatible with modern GraphQL versions.

npm install graphql-typescript
INSTALL
IMPORT
SIG · GRAPHQL-TYPESCRIPT
G
graphql-typescript
devopsjavascriptv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Type
import { Type } from 'graphql-typescript'
import { Type } from 'graphql'
Decorator for defining GraphQL object types.
Field
import { Field } from 'graphql-typescript'
import Field from 'graphql-typescript'
Default import is not available – only named exports.
makeSchema
import { makeSchema } from 'graphql-typescript'
const { makeSchema } = require('graphql-typescript')
CommonJS require works but ESM is recommended for TypeScript.

Shows basic schema generation: a Query type with a single field, then prints the resulting GraphQL schema.

import { Type, Field, Nullable, String, Int, makeSchema } from 'graphql-typescript'; @Type class Query { @Field(() => String) hello: string = 'world'; } const schema = makeSchema(Query, { types: [], }); console.log(require('graphql').printSchema(schema));
Debug
Known issues
breakinggraphql-typescript only supports graphql@^0.13.2 – using graphql@15+ will cause compatibility errors.
fix
Downgrade graphql to ^0.13.2 or migrate to type-graphql / graphql-compose.
affects: >=15.0.0
deprecatedPackage is unmaintained since 2020. No fixes for modern TypeScript/GraphQL.
fix
Consider using type-graphql or nestjs/graphql for active development.
affects: >=0.3.0
gotchaRequires TypeScript decorator flags: experimentalDecorators and emitDecoratorMetadata in tsconfig.json.
fix
Set "experimentalDecorators": true and "emitDecoratorMetadata": true in compilerOptions.
affects: >=0.1.0
breakingAll fields are non-null by default; use @Nullable to make them nullable. This is a design choice but often surprises users coming from other libraries.
fix
Add @Nullable decorator above @Field for nullable fields.
affects: >=0.1.0
gotchaClass property initializers are required for fields, otherwise they will be undefined at runtime.
fix
Initialize every @Field property with a default value (e.g., hello: string = 'world').
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'graphql/utilities/buildASTSchema'
Incompatible graphql version (tried v15+). Package expects graphql@^0.13.2 internal structure.
fix
Install graphql@0.13.2: npm install graphql@0.13.2
Experimental support for decorators is a feature that is subject to change in a future release. Set 'experimentalDecorators' to true in your tsconfig.json.
TypeScript decorator feature not enabled.
fix
Add "experimentalDecorators": true to tsconfig.json compilerOptions.
TypeError: Class extends value undefined is not a constructor or null
Missing @Type decorator on a class used as a type.
fix
Ensure all object types are decorated with @Type.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency for building GraphQL schemas
Agent activity
10 hits · last 30 days
node
10
Resources
graphql-typescript — npm install graphql-typescript · libregistry