@@ -16,6 +16,15 @@ 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' )
24
+ . update ( minifySource ( normalizedSource ) )
25
+ . digest ( 'hex' ) ;
26
+ }
27
+
19
28
export interface CleanDocumentOptions {
20
29
removeUnused ?: boolean ;
21
30
generateId ?: ( normalizedSource : string ) => string ;
@@ -41,18 +50,10 @@ export function cleanDocument(
41
50
stripLoc ( definition ) ;
42
51
}
43
52
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
- }
53
+ const id =
54
+ generateId === undefined
55
+ ? defaultGenerateId ( normalizedSource )
56
+ : generateId ( documentSource ) ;
56
57
57
58
Reflect . defineProperty ( normalizedDocument , 'id' , {
58
59
value : id ,
0 commit comments