Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
Apply code review change
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Dec 14, 2020
1 parent fad6a45 commit a7bc4a3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/graphql-mini-transforms/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ import {DocumentNode, SimpleDocument} from 'graphql-typed';
const IMPORT_REGEX = /^#import\s+['"]([^'"]*)['"];?[\s\n]*/gm;
const DEFAULT_NAME = 'Operation';

function defaultGenerateId(normalizedSource: string) {
// This ID is a hash of the full file contents that are part of the document,
// including other documents that are injected in, but excluding any unused
// fragments. This is useful for things like persisted queries.
return createHash('sha256')
.update(minifySource(normalizedSource))
.digest('hex');
}

export interface CleanDocumentOptions {
removeUnused?: boolean;
generateId?: (normalizedSource: string) => string;
Expand All @@ -41,18 +50,10 @@ export function cleanDocument(
stripLoc(definition);
}

let id: string;

if (generateId === undefined) {
// This ID is a hash of the full file contents that are part of the document,
// including other documents that are injected in, but excluding any unused
// fragments. This is useful for things like persisted queries.
id = createHash('sha256')
.update(minifySource(normalizedSource))
.digest('hex');
} else {
id = generateId(documentSource);
}
const id =
generateId === undefined
? defaultGenerateId(normalizedSource)
: generateId(documentSource);

Reflect.defineProperty(normalizedDocument, 'id', {
value: id,
Expand Down

0 comments on commit a7bc4a3

Please sign in to comment.