Generate a deterministic hash of a GraphQL query for caching and persisted queries
npm install graphql-hashimport graphqlHash from 'graphql-hash';
graphqlHash('{ user { name } }');
//=> 'e3b0c44298fc1c14...'
// Whitespace and comments don't affect the hash
graphqlHash(`
# Fetch user
{
user {
name
}
}
`);
//=> 'e3b0c44298fc1c14...' (same hash)Returns a hex-encoded hash string.
Type: string
The GraphQL query string.
Type: object
Type: string
Default: 'sha256'
The hash algorithm to use. Any algorithm supported by node:crypto can be used.
Returns a normalized string with comments stripped, whitespace collapsed, and spaces removed around structural characters.
Type: string
The GraphQL query string to normalize.
- error-serialize - Serialize and deserialize Error objects
MIT