Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

add-typenames

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-typenames

Recursively adds __typename to the input using a passed in schema

  • 0.1.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
411
increased by41.24%
Maintainers
1
Weekly downloads
 
Created
Source

add-typenames

addTypenames copies a given input object and recursively adds GraphQL __typenames to the output.

Installation

yarn install add-typenames graphql

Usage

const typedItem = addTypenames({ item, schema });

Example
import addTypenames from 'add-typenames';
import { buildSchema } from 'graphql'

const typeDefs = `
    """ Add your schema definition here
`;
const item = {
    /* Your item to be typed */
};

const schema = buildSchema(typeDefs);

const typedItem = addTypenames({ item, schema });

Hint: Adding __typename to the root of the input item will resolve most issues that may arise by leveraging the schema to resolve all types rather than relying on heuristics

Handling Unions, Interfaces and Scalars

In order to properly resolve Unions, Interfaces and Scalars we need the resolvers for those types to be included as part of the schema. This can be done with makeExecutableSchema

import { makeExecutableSchema } from '@graphql-tools/schema';

const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
});

Hint: Only include the resolvers for Unions, Interfaces and Scalars. The rest are unused and not needed.

FAQs

Package last updated on 07 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc