@@ -16,26 +16,14 @@ 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
-
28
19
export interface CleanDocumentOptions {
29
20
removeUnused ?: boolean ;
30
21
generateId ?: ( normalizedSource : string ) => string ;
31
22
}
32
23
33
24
export function cleanDocument (
34
25
document : UntypedDocumentNode ,
35
- {
36
- removeUnused = true ,
37
- generateId = defaultGenerateId ,
38
- } : CleanDocumentOptions = { } ,
26
+ { removeUnused = true , generateId} : CleanDocumentOptions = { } ,
39
27
) : DocumentNode < any , any , any > {
40
28
if ( removeUnused ) {
41
29
removeUnusedDefinitions ( document ) ;
@@ -53,7 +41,18 @@ export function cleanDocument(
53
41
stripLoc ( definition ) ;
54
42
}
55
43
56
- const id = generateId ( documentSource ) ;
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
+ }
57
56
58
57
Reflect . defineProperty ( normalizedDocument , 'id' , {
59
58
value : id ,
0 commit comments