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

Commit f6d9023

Browse files
committed
Apply code review change
1 parent fad6a45 commit f6d9023

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

packages/graphql-mini-transforms/src/document.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import {DocumentNode, SimpleDocument} from 'graphql-typed';
1616
const IMPORT_REGEX = /^#import\s+['"]([^'"]*)['"];?[\s\n]*/gm;
1717
const DEFAULT_NAME = 'Operation';
1818

19+
function defaultGenerateId(normalizedSource: string) {
20+
// This ID is a hash of the full file contents that are part of the document,
21+
// including other documents that are injected in, but excluding any unused
22+
// fragments. This is useful for things like persisted queries.
23+
return createHash('sha256').update(normalizedSource).digest('hex');
24+
}
25+
1926
export interface CleanDocumentOptions {
2027
removeUnused?: boolean;
2128
generateId?: (normalizedSource: string) => string;
@@ -41,18 +48,10 @@ export function cleanDocument(
4148
stripLoc(definition);
4249
}
4350

44-
let id: string;
45-
46-
if (generateId === undefined) {
47-
// This ID is a hash of the full file contents that are part of the document,
48-
// including other documents that are injected in, but excluding any unused
49-
// fragments. This is useful for things like persisted queries.
50-
id = createHash('sha256')
51-
.update(minifySource(normalizedSource))
52-
.digest('hex');
53-
} else {
54-
id = generateId(documentSource);
55-
}
51+
const id =
52+
generateId === undefined
53+
? defaultGenerateId(normalizedSource)
54+
: generateId(documentSource);
5655

5756
Reflect.defineProperty(normalizedDocument, 'id', {
5857
value: id,

0 commit comments

Comments
 (0)