Sign In

graphql-hash

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-hash

Generate a deterministic hash of a GraphQL query for caching and persisted queries

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
73
1360%
Maintainers
1
Weekly downloads
 
Created
Source

graphql-hash

Generate a deterministic hash of a GraphQL query for caching and persisted queries

Install

npm install graphql-hash

Usage

import graphqlHash from 'graphql-hash';

graphqlHash('{ user { name } }');
//=> 'e3b0c44298fc1c14...'

// Whitespace and comments don't affect the hash
graphqlHash(`
	# Fetch user
	{
		user {
			name
		}
	}
`);
//=> 'e3b0c44298fc1c14...' (same hash)

API

graphqlHash(query, options?)

Returns a hex-encoded hash string.

query

Type: string

The GraphQL query string.

options

Type: object

algorithm

Type: string
Default: 'sha256'

The hash algorithm to use. Any algorithm supported by node:crypto can be used.

normalizeQuery(query)

Returns a normalized string with comments stripped, whitespace collapsed, and spaces removed around structural characters.

query

Type: string

The GraphQL query string to normalize.

  • error-serialize - Serialize and deserialize Error objects

License

MIT

Keywords

graphql

FAQs

Package last updated on 16 Feb 2026

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