Registry / testing / type-graphql-utils

type-graphql-utils

JSON →
library2.1.0jsnpmunverified

Utilities to transform type-graphql types. Current stable version is 2.1.0. This library provides utility functions similar to TypeScript's Pick, Omit, Partial, and Required, but for GraphQL object and input types defined with type-graphql decorators. It operates at runtime to create new classes with modified fields, preserving decorators and type metadata. Pitfalls: requires peer dependencies graphql ^15 and type-graphql ^1; does not support graphql v16 or type-graphql v2; the 'names' parameter must be an object with value 1 (e.g. { field: 1 }) not an array; the 'directives' option is false by default and may cause issues if omitted.

npm install type-graphql-utils
INSTALL
IMPORT
SIG · TYPE-GRAPHQL-UTILS
T
type-graphql-utils
testingjavascriptv2.1.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.

Pick
import { Pick } from 'type-graphql-utils'
import Pick from 'type-graphql-utils'
Named export, not default export
Partial
import { Partial } from 'type-graphql-utils'
const Partial = require('type-graphql-utils').Partial
CommonJS require works, but 'correct' shows ESM pattern
Omit
import { Omit } from 'type-graphql-utils'
Required
import { Required } from 'type-graphql-utils'

Demonstrates Pick, Partial, and Required utilities to create InputType classes from an ObjectType.

import { Field, InputType, ObjectType } from 'type-graphql'; import { Pick, Partial, Required } from 'type-graphql-utils'; @ObjectType() class User { @Field() id!: number; @Field() name!: string; @Field() email!: string; } @InputType() class UserInput1 extends Partial(User) {} // Input fields: id (optional), name (optional), email (optional) @InputType() class UserInput2 extends Pick(User, { name: 1 }) {} // Input field: name (required) @InputType() class UserInput3 extends Required(Partial(User), { id: 1 }) {} // Input fields: id (required), name (optional), email (optional)
Debug
Known issues
breakingRequires graphql ^15 and type-graphql ^1. Does not support graphql v16 or type-graphql v2.
fix
Downgrade to graphql 15.x and type-graphql 1.x, or look for alternative libraries that support newer versions.
affects: >=2.0.0
gotchaThe 'names' parameter must be an object with integer values equal to 1, e.g. { field: 1 }, not an array or other object shape.
fix
Always use object syntax: { field1: 1, field2: 1 }.
affects: >=1.0.0
gotcha'directives' option defaults to false; if your type-graphql classes use directives, they will be lost unless you pass { directives: true }.
fix
Pass options object with directives: true when needed.
affects: >=2.0.0
deprecatedLibrary is no longer actively maintained; last release was in 2020.
fix
Consider using native type-graphql utilities or migrating to TypeGraphQL v2 with class-transformer-validator.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
Missing peer dependency 'reflect-metadata' or incorrect import order
fix
Ensure 'reflect-metadata' is imported at the top of your entry file: import 'reflect-metadata';
Error: Cannot find module 'graphql' Require stack: - /node_modules/type-graphql-utils/dist/index.js
Missing peer dependency graphql
fix
Install graphql: npm install graphql@15
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency required for GraphQL type system utilities
type-graphqlrequiredPeer dependency required to access decorated class metadata
Agent activity
10 hits · last 30 days
node
10
Resources
type-graphql-utils — npm install type-graphql-utils · libregistry