Registry / devops / remove-graphql-typename

remove-graphql-typename

JSON →
library1.0.2jsnpmunverified

A utility that recursively removes all __typename properties from GraphQL responses. Version 1.0.2 provides a single pure function that walks through objects and arrays and deletes any key named __typename. It ships with TypeScript types and is released as a stable package. Compared to alternatives like apollo's removeTypenameFromVariables, this package focuses solely on responses and does not modify the original object. It is a zero-dependency, lightweight solution for cleaning up Apollo Client or Relay responses before caching or serializing. The package is maintained with weekly downloads in the low thousands and an MIT license.

npm install remove-graphql-typename
INSTALL
IMPORT
SIG · REMOVE-GRAPHQL-TYP
R
remove-graphql-typename
devopsjavascriptv1.0.2
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.

default
import removeTypename from 'remove-graphql-typename';
import { removeTypename } from 'remove-graphql-typename';
The package exports a default function only. Named import will result in undefined.
default
const removeTypename = require('remove-graphql-typename');
const { removeTypename } = require('remove-graphql-typename');
CommonJS require works with default export. Destructuring will fail as there is no named export.
type (TypeScript)
import removeTypename from 'remove-graphql-typename';
import type { removeTypename } from 'remove-graphql-typename';
The package types are auto-inferred from the function signature. Attempting a named type import will error because there is no named export.

Demonstrates recursively removing __typename from a GraphQL response object.

import removeTypename from 'remove-graphql-typename'; const data = { __typename: 'Query', items: [ { __typename: 'Item', id: '1', name: 'foo' }, { __typename: 'Item', id: '2', name: 'bar' } ] }; const cleaned = removeTypename(data); console.log(cleaned); // { items: [ { id: '1', name: 'foo' }, { id: '2', name: 'bar' } ] }
Debug
Known issues
gotchaThe function mutates the original object? No – it does not mutate the original object. It returns a new object with __typename removed. However, nested objects that are not __typename are still references to the original objects (shallow copy).
fix
If you need deep immutability, consider using JSON.parse(JSON.stringify(data)) before calling removeTypename.
affects: >=1.0.0
gotchaThe function only removes keys named exactly '__typename'. It will not remove any other keys that resemble it (e.g., '__Typename' with different casing).
fix
Ensure your data uses the exact key '__typename'. If you have variations, you may need a custom solution.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: removeTypename is not a function
Named import instead of default import.
fix
Use 'import removeTypename from 'remove-graphql-typename'' or 'const removeTypename = require('remove-graphql-typename')'
Cannot read property 'map' of undefined
Passing null or undefined to removeTypename.
fix
Ensure the argument is an object or array. Check: if (data) removeTypename(data);
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
remove-graphql-typename — npm install remove-graphql-typename · libregistry