Registry / database / graphql-annotations

graphql-annotations

JSON →
library0.0.3jsnpmunverified

Utility library for parsing and stripping annotated metadata from GraphQL schema descriptions (v0.0.3). Allows extracting custom annotations like @db.length or @db.unique from type/field descriptions, returning structured objects. Supports multiple namespaces and JSON-like values. Lightweight, no runtime dependencies, ships TypeScript definitions. Created by Guillaume Chau (Akryum), maintainer of vue-apollo and GraphQL tools. Suitable for code generation or ORM mapping where directives are not available.

npm install graphql-annotations
INSTALL
IMPORT
SIG · GRAPHQL-ANNOTATION
G
graphql-annotations
databasejavascriptv0.0.3
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.

parseAnnotations
import { parseAnnotations } from 'graphql-annotations'
const { parseAnnotations } = require('graphql-annotations')
ESM and CJS both supported; no tree-shaking advantage.
stripAnnotations
import { stripAnnotations } from 'graphql-annotations'
import stripAnnotations from 'graphql-annotations'
Named export only; default export does not exist.
ALL
import { parseAnnotations, stripAnnotations } from 'graphql-annotations'
import * as annotations from 'graphql-annotations'
Only named exports available; namespace import works but not typical.

Demonstrates parsing and stripping @db annotations from a description string.

import { parseAnnotations, stripAnnotations } from 'graphql-annotations'; const description = ` A field with annotations @db.length: 200 @db.unique `; const parsed = parseAnnotations('db', description); console.log(parsed); // { length: 200, unique: true } const stripped = stripAnnotations('db', description); console.log(stripped); // '\n A field with annotations\n'
Debug
Known issues
gotchaAnnotation values are interpreted via JSON.parse-like parser. Strings must be quoted with single or double quotes, numbers unquoted. Unquoted strings will fail.
fix
Ensure string values are quoted: @db.foo: 'bar' or @db.foo: "bar"
affects: >=0.0.1
gotchaBoolean annotations without value (e.g., @db.unique) are parsed as literal true. To set false you must write @db.unique: false? Not supported; omit annotation instead.
fix
For false, do not include the annotation.
affects: >=0.0.1
breakingNo breaking changes have been documented; version is low and stable.
fix
N/A
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: parseAnnotations is not a function
Using default import instead of named import.
fix
Use import { parseAnnotations } from 'graphql-annotations'
SyntaxError: Unexpected token
Unquoted string value in annotation (e.g., @db.foo: bar).
fix
Quote string values: @db.foo: 'bar'
Cannot find module 'graphql-annotations'
Package not installed or typo.
fix
Run npm install graphql-annotations
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Resources
graphql-annotations — npm install graphql-annotations · libregistry