1
1
import gql from 'graphql-tag' ;
2
2
import { cloneDeep } from 'lodash' ;
3
3
4
- import { shouldInclude , hasDirectives } from '../directives' ;
5
4
import { getQueryDefinition } from '../getFromAST' ;
5
+ import {
6
+ shouldInclude ,
7
+ hasDirectives ,
8
+ hasAnyDirectives ,
9
+ hasAllDirectives ,
10
+ } from '../directives' ;
6
11
7
12
describe ( 'hasDirectives' , ( ) => {
8
13
it ( 'should allow searching the ast for a directive' , ( ) => {
@@ -91,7 +96,7 @@ describe('hasDirectives', () => {
91
96
92
97
it ( 'works with both any and all semantics' , ( ) => {
93
98
expect (
94
- hasDirectives ( [ 'client' , 'defer' ] , gql `
99
+ hasAnyDirectives ( [ 'client' , 'defer' ] , gql `
95
100
query {
96
101
meetings {
97
102
id
@@ -100,22 +105,22 @@ describe('hasDirectives', () => {
100
105
}
101
106
}
102
107
}
103
- ` , false ) // This false forces the default behavior (any )
108
+ ` )
104
109
) . toBe ( true ) ;
105
110
106
111
expect (
107
- hasDirectives ( [ 'client' , 'defer' ] , gql `
112
+ hasAnyDirectives ( [ 'client' , 'defer' ] , gql `
108
113
query {
109
114
meetings {
110
115
id
111
116
room { size }
112
117
}
113
118
}
114
- ` , false ) // This false forces the default behavior (any )
119
+ ` )
115
120
) . toBe ( false ) ;
116
121
117
122
expect (
118
- hasDirectives ( [ 'client' , 'defer' ] , gql `
123
+ hasAnyDirectives ( [ 'client' , 'defer' ] , gql `
119
124
query {
120
125
meetings {
121
126
id
@@ -125,11 +130,11 @@ describe('hasDirectives', () => {
125
130
}
126
131
}
127
132
}
128
- ` , false ) // This false forces the default behavior (any )
133
+ ` )
129
134
) . toBe ( true ) ;
130
135
131
136
expect (
132
- hasDirectives ( [ 'client' , 'defer' ] , gql `
137
+ hasAllDirectives ( [ 'client' , 'defer' ] , gql `
133
138
query {
134
139
meetings {
135
140
id
@@ -138,22 +143,22 @@ describe('hasDirectives', () => {
138
143
}
139
144
}
140
145
}
141
- ` , true ) // This true requires all directives to be present
146
+ ` )
142
147
) . toBe ( false ) ;
143
148
144
149
expect (
145
- hasDirectives ( [ 'client' , 'defer' ] , gql `
150
+ hasAllDirectives ( [ 'client' , 'defer' ] , gql `
146
151
query {
147
152
meetings {
148
153
id
149
154
room { size }
150
155
}
151
156
}
152
- ` , true ) // This true requires all directives to be present
157
+ ` )
153
158
) . toBe ( false ) ;
154
159
155
160
expect (
156
- hasDirectives ( [ 'client' , 'defer' ] , gql `
161
+ hasAllDirectives ( [ 'client' , 'defer' ] , gql `
157
162
query {
158
163
meetings {
159
164
id
@@ -163,11 +168,11 @@ describe('hasDirectives', () => {
163
168
}
164
169
}
165
170
}
166
- ` , true ) // This true requires all directives to be present
171
+ ` )
167
172
) . toBe ( false ) ;
168
173
169
174
expect (
170
- hasDirectives ( [ 'client' , 'defer' ] , gql `
175
+ hasAllDirectives ( [ 'client' , 'defer' ] , gql `
171
176
query {
172
177
meetings {
173
178
id
@@ -179,11 +184,11 @@ describe('hasDirectives', () => {
179
184
}
180
185
}
181
186
}
182
- ` , true ) // This true requires all directives to be present
187
+ ` )
183
188
) . toBe ( true ) ;
184
189
185
190
expect (
186
- hasDirectives ( [ 'live' , 'client' , 'defer' ] , gql `
191
+ hasAllDirectives ( [ 'live' , 'client' , 'defer' ] , gql `
187
192
query {
188
193
meetings {
189
194
id
@@ -195,11 +200,11 @@ describe('hasDirectives', () => {
195
200
}
196
201
}
197
202
}
198
- ` , true ) // This true requires all directives to be present
203
+ ` )
199
204
) . toBe ( false ) ;
200
205
201
206
expect (
202
- hasDirectives ( [ 'live' , 'client' , 'defer' ] , gql `
207
+ hasAllDirectives ( [ 'live' , 'client' , 'defer' ] , gql `
203
208
query @live {
204
209
meetings {
205
210
room {
@@ -211,13 +216,13 @@ describe('hasDirectives', () => {
211
216
id
212
217
}
213
218
}
214
- ` , true ) // This true requires all directives to be present
219
+ ` )
215
220
) . toBe ( true ) ;
216
221
} ) ;
217
222
218
223
it ( 'works when names are duplicated' , ( ) => {
219
224
expect (
220
- hasDirectives ( [ 'client' , 'client' , 'client' ] , gql `
225
+ hasAnyDirectives ( [ 'client' , 'client' , 'client' ] , gql `
221
226
query {
222
227
fromClient @client {
223
228
asdf
@@ -228,18 +233,18 @@ describe('hasDirectives', () => {
228
233
) . toBe ( true ) ;
229
234
230
235
expect (
231
- hasDirectives ( [ 'client' , 'client' , 'client' ] , gql `
236
+ hasAllDirectives ( [ 'client' , 'client' , 'client' ] , gql `
232
237
query {
233
238
fromClient @client {
234
239
asdf
235
240
foo
236
241
}
237
242
}
238
- ` , true ) // This true requires all directives to be present
243
+ ` )
239
244
) . toBe ( true ) ;
240
245
241
246
expect (
242
- hasDirectives ( [ 'live' , 'live' , 'defer' ] , gql `
247
+ hasAnyDirectives ( [ 'live' , 'live' , 'defer' ] , gql `
243
248
query {
244
249
fromClient @client {
245
250
asdf
@@ -250,18 +255,18 @@ describe('hasDirectives', () => {
250
255
) . toBe ( false ) ;
251
256
252
257
expect (
253
- hasDirectives ( [ 'live' , 'live' , 'defer' ] , gql `
258
+ hasAllDirectives ( [ 'live' , 'live' , 'defer' ] , gql `
254
259
query {
255
260
fromClient @client {
256
261
asdf
257
262
foo @include(if: true)
258
263
}
259
264
}
260
- ` , true )
265
+ ` )
261
266
) . toBe ( false ) ;
262
267
263
268
expect (
264
- hasDirectives ( [ 'live' , 'live' , 'defer' ] , gql `
269
+ hasAllDirectives ( [ 'live' , 'live' , 'defer' ] , gql `
265
270
query @live {
266
271
fromClient @client {
267
272
... @defer {
@@ -270,7 +275,7 @@ describe('hasDirectives', () => {
270
275
}
271
276
}
272
277
}
273
- ` , true )
278
+ ` )
274
279
) . toBe ( true ) ;
275
280
} ) ;
276
281
} ) ;
0 commit comments