@@ -6,6 +6,13 @@ import { FetchPolicy } from 'apollo-client';
6
6
export default class Logger {
7
7
private readonly enabled : boolean ;
8
8
9
+ private PREFIX = process . env . NODE_ENV === 'test' ? [ '[Vuex-ORM-Apollo]' ] :
10
+ [
11
+ '%c Vuex-ORM: Apollo Plugin %c' ,
12
+ 'background: #35495e; padding: 1px 0; border-radius: 3px; color: #eee;' ,
13
+ 'background: transparent;'
14
+ ] ;
15
+
9
16
public constructor ( enabled : boolean ) {
10
17
this . enabled = enabled ;
11
18
this . log ( 'Logging is enabled.' ) ;
@@ -14,9 +21,9 @@ export default class Logger {
14
21
public group ( ...messages : Array < any > ) : void {
15
22
if ( this . enabled ) {
16
23
if ( process . env . NODE_ENV === 'test' ) {
17
- console . group ( '[Vuex-ORM-Apollo]' , ...messages ) ;
24
+ console . group ( ... this . PREFIX , ...messages ) ;
18
25
} else {
19
- console . groupCollapsed ( '[Vuex-ORM-Apollo]' , ...messages ) ;
26
+ console . groupCollapsed ( ... this . PREFIX , ...messages ) ;
20
27
}
21
28
}
22
29
}
@@ -27,21 +34,23 @@ export default class Logger {
27
34
28
35
public log ( ...messages : Array < any > ) : void {
29
36
if ( this . enabled ) {
30
- console . log ( '[Vuex-ORM-Apollo]' , ...messages ) ;
37
+ console . log ( ... this . PREFIX , ...messages ) ;
31
38
}
32
39
}
33
40
34
41
public logQuery ( query : string | DocumentNode , variables ?: Arguments , fetchPolicy ?: FetchPolicy ) {
35
42
if ( this . enabled ) {
36
43
try {
37
- this . group ( 'Sending query:' ) ;
38
-
44
+ let prettified = '' ;
39
45
if ( typeof query === 'object' && query . loc ) {
40
- console . log ( QueryBuilder . prettify ( query . loc . source . body ) ) ;
46
+ prettified = QueryBuilder . prettify ( query . loc . source . body ) ;
41
47
} else {
42
- console . log ( QueryBuilder . prettify ( query as string ) ) ;
48
+ prettified = QueryBuilder . prettify ( query as string ) ;
43
49
}
44
50
51
+ this . group ( 'Sending query:' , prettified . split ( '\n' ) [ 1 ] . replace ( '{' , '' ) . trim ( ) ) ;
52
+ console . log ( prettified ) ;
53
+
45
54
if ( variables ) console . log ( 'VARIABLES:' , variables ) ;
46
55
if ( fetchPolicy ) console . log ( 'FETCH POLICY:' , fetchPolicy ) ;
47
56
0 commit comments