@@ -16,6 +16,13 @@ import {DocumentNode, SimpleDocument} from 'graphql-typed';
16
16
const IMPORT_REGEX = / ^ # i m p o r t \s + [ ' " ] ( [ ^ ' " ] * ) [ ' " ] ; ? [ \s \n ] * / gm;
17
17
const DEFAULT_NAME = 'Operation' ;
18
18
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
+
19
26
export interface CleanDocumentOptions {
20
27
removeUnused ?: boolean ;
21
28
generateId ?: ( normalizedSource : string ) => string ;
@@ -41,18 +48,10 @@ export function cleanDocument(
41
48
stripLoc ( definition ) ;
42
49
}
43
50
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 ) ;
56
55
57
56
Reflect . defineProperty ( normalizedDocument , 'id' , {
58
57
value : id ,
0 commit comments