1
1
import { default as gql , disableFragmentWarnings } from "graphql-tag" ;
2
2
3
- import { printWithReducedWhitespace , hideLiterals } from "../transforms" ;
3
+ import {
4
+ printWithReducedWhitespace ,
5
+ hideLiterals ,
6
+ hideStringAndNumericLiterals
7
+ } from "../transforms" ;
4
8
5
9
// The gql duplicate fragment warning feature really is just warnings; nothing
6
10
// breaks if you turn it off in tests.
@@ -44,14 +48,27 @@ describe("hideLiterals", () => {
44
48
name : "full test" ,
45
49
input : gql `
46
50
query Foo($b: Int, $a: Boolean) {
47
- user(name: "hello", age: 5) {
51
+ user(
52
+ name: "hello"
53
+ age: 5
54
+ pct: 0.4
55
+ lst: ["a", "b", "c"]
56
+ obj: { a: "a", b: 1 }
57
+ ) {
48
58
...Bar
49
59
... on User {
50
60
hello
51
61
bee
52
62
}
53
63
tz
54
64
aliased: name
65
+ withInputs(
66
+ str: "hi"
67
+ int: 2
68
+ flt: 0.3
69
+ lst: ["x", "y", "z"]
70
+ obj: { q: "r", s: 1 }
71
+ )
55
72
}
56
73
}
57
74
@@ -65,7 +82,8 @@ describe("hideLiterals", () => {
65
82
}
66
83
` ,
67
84
output :
68
- 'query Foo($b:Int,$a:Boolean){user(name:"",age:0){...Bar...on User{hello bee}tz aliased:name}}' +
85
+ 'query Foo($b:Int,$a:Boolean){user(name:"",age:0,pct:0,lst:[],obj:{}){...Bar...on User{hello bee}tz aliased:name ' +
86
+ 'withInputs(str:"",int:0,flt:0,lst:[],obj:{})}}' +
69
87
"fragment Bar on User{age@skip(if:$a)...Nested}fragment Nested on User{blah}"
70
88
}
71
89
] ;
@@ -75,3 +93,57 @@ describe("hideLiterals", () => {
75
93
} ) ;
76
94
} ) ;
77
95
} ) ;
96
+
97
+ describe ( "hideStringAndNumericLiterals" , ( ) => {
98
+ const cases = [
99
+ {
100
+ name : "full test" ,
101
+ input : gql `
102
+ query Foo($b: Int, $a: Boolean) {
103
+ user(
104
+ name: "hello"
105
+ age: 5
106
+ pct: 0.4
107
+ lst: ["a", "b", "c"]
108
+ obj: { a: "a", b: 1 }
109
+ ) {
110
+ ...Bar
111
+ ... on User {
112
+ hello
113
+ bee
114
+ }
115
+ tz
116
+ aliased: name
117
+ withInputs(
118
+ str: "hi"
119
+ int: 2
120
+ flt: 0.3
121
+ lst: ["", "", ""]
122
+ obj: { q: "", s: 0 }
123
+ )
124
+ }
125
+ }
126
+
127
+ fragment Bar on User {
128
+ age @skip(if: $a)
129
+ ...Nested
130
+ }
131
+
132
+ fragment Nested on User {
133
+ blah
134
+ }
135
+ ` ,
136
+ output :
137
+ 'query Foo($b:Int,$a:Boolean){user(name:"",age:0,pct:0,lst:["","",""],obj:{a:"",b:0}){...Bar...on User{hello bee}tz aliased:name ' +
138
+ 'withInputs(str:"",int:0,flt:0,lst:["","",""],obj:{q:"",s:0})}}' +
139
+ "fragment Bar on User{age@skip(if:$a)...Nested}fragment Nested on User{blah}"
140
+ }
141
+ ] ;
142
+ cases . forEach ( ( { name, input, output } ) => {
143
+ test ( name , ( ) => {
144
+ expect (
145
+ printWithReducedWhitespace ( hideStringAndNumericLiterals ( input ) )
146
+ ) . toEqual ( output ) ;
147
+ } ) ;
148
+ } ) ;
149
+ } ) ;
0 commit comments