@@ -7,7 +7,48 @@ import dedent from '../../jsutils/dedent';
7
7
import { Source } from '../../language' ;
8
8
import { printSourceLocation } from '../printLocation' ;
9
9
10
- describe ( 'printLocation' , ( ) => {
10
+ describe ( 'printSourceLocation' , ( ) => {
11
+ it ( 'prints minified documents' , ( ) => {
12
+ const minifiedSource = new Source (
13
+ 'query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String){someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD...on THIRD_ERROR_HERE}}}' ,
14
+ ) ;
15
+
16
+ const firstLocation = printSourceLocation ( minifiedSource , {
17
+ line : 1 ,
18
+ column : minifiedSource . body . indexOf ( 'FIRST_ERROR_HERE' ) + 1 ,
19
+ } ) ;
20
+ expect ( firstLocation + '\n' ) . to . equal ( dedent `
21
+ GraphQL request:1:53
22
+ 1 | query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
23
+ | ^
24
+ | {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
25
+ ` ) ;
26
+
27
+ const secondLocation = printSourceLocation ( minifiedSource , {
28
+ line : 1 ,
29
+ column : minifiedSource . body . indexOf ( 'SECOND_ERROR_HERE' ) + 1 ,
30
+ } ) ;
31
+ expect ( secondLocation + '\n' ) . to . equal ( dedent `
32
+ GraphQL request:1:114
33
+ 1 | query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
34
+ | {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
35
+ | ^
36
+ | ..on THIRD_ERROR_HERE}}}
37
+ ` ) ;
38
+
39
+ const thirdLocation = printSourceLocation ( minifiedSource , {
40
+ line : 1 ,
41
+ column : minifiedSource . body . indexOf ( 'THIRD_ERROR_HERE' ) + 1 ,
42
+ } ) ;
43
+ expect ( thirdLocation + '\n' ) . to . equal ( dedent `
44
+ GraphQL request:1:166
45
+ 1 | query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
46
+ | {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
47
+ | ..on THIRD_ERROR_HERE}}}
48
+ | ^
49
+ ` ) ;
50
+ } ) ;
51
+
11
52
it ( 'prints single digit line number with no padding' , ( ) => {
12
53
const result = printSourceLocation (
13
54
new Source ( '*' , 'Test' , { line : 9 , column : 1 } ) ,
0 commit comments