Skip to content

Commit 908c83f

Browse files
committed
logger also accepts gql parsed queries
1 parent 7bc3ad4 commit 908c83f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/logger.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { print } from 'graphql/language/printer';
22
import { parse } from 'graphql/language/parser';
3+
import {DocumentNode} from "graphql";
34

45
export default class Logger {
56
private readonly enabled: boolean;
@@ -24,12 +25,17 @@ export default class Logger {
2425
}
2526
}
2627

27-
// TODO also accept gql parsed queries
28-
public logQuery(query: string) {
28+
public logQuery(query: string|DocumentNode) {
2929
if (this.enabled) {
3030
try {
3131
this.group('Sending query:')
32-
console.log(this.prettify(query));
32+
33+
if (typeof query === 'object' && query.loc) {
34+
console.log(this.prettify(query.loc.source.body));
35+
} else {
36+
console.log(this.prettify(<string>query));
37+
}
38+
3339
this.groupEnd();
3440
} catch(e) {
3541
console.error('[Vuex-ORM-Apollo] There is a syntax error in the query!', e, query);

0 commit comments

Comments
 (0)