@@ -191,7 +191,7 @@ describe('maxDepthPlugin', () => {
191
191
assertSingleExecutionValue ( result ) ;
192
192
expect ( result . errors ) . toBeDefined ( ) ;
193
193
expect ( result . errors ?. map ( ( error ) => error . message ) ) . toContain (
194
- 'Syntax Error: Query depth limit of 3 exceeded, found 4 .' ,
194
+ 'Syntax Error: Query depth limit of 3 exceeded, found 5 .' ,
195
195
) ;
196
196
} ) ;
197
197
@@ -239,4 +239,69 @@ describe('maxDepthPlugin', () => {
239
239
`Syntax Error: Query depth limit of ${ maxDepth } exceeded, found ${ maxDepth + 1 } .` ,
240
240
] ) ;
241
241
} ) ;
242
+
243
+ it ( 'rejects for fragment named `__schema` exceeding max depth' , async ( ) => {
244
+ const bypass_query = `
245
+ query {
246
+ books {
247
+ author {
248
+ books {
249
+ author {
250
+ ...__schema
251
+ }
252
+ }
253
+ }
254
+ }
255
+ }
256
+ fragment __schema on Author {
257
+ books {
258
+ title
259
+ }
260
+ }
261
+ ` ;
262
+ const maxDepth = 6 ;
263
+ const testkit = createTestkit ( [ maxDepthPlugin ( { n : maxDepth , exposeLimits : true } ) ] , schema ) ;
264
+ const result = await testkit . execute ( bypass_query ) ;
265
+
266
+ assertSingleExecutionValue ( result ) ;
267
+ expect ( result . errors ) . toBeDefined ( ) ;
268
+ expect ( result . errors ?. map ( ( error ) => error . message ) ) . toEqual ( [
269
+ `Syntax Error: Query depth limit of ${ maxDepth } exceeded, found ${ maxDepth + 2 } .` ,
270
+ ] ) ;
271
+ } ) ;
272
+
273
+ it ( 'rejects for exceeding max depth by reusing a cached Fragment' , async ( ) => {
274
+ const bypass_query = `
275
+ query {
276
+ books {
277
+ author {
278
+ ...Test
279
+ }
280
+ }
281
+ books {
282
+ author {
283
+ books {
284
+ author {
285
+ ...Test
286
+ }
287
+ }
288
+ }
289
+ }
290
+ }
291
+ fragment Test on Author {
292
+ books {
293
+ title
294
+ }
295
+ }
296
+ ` ;
297
+ const maxDepth = 6 ;
298
+ const testkit = createTestkit ( [ maxDepthPlugin ( { n : maxDepth , exposeLimits : true } ) ] , schema ) ;
299
+ const result = await testkit . execute ( bypass_query ) ;
300
+
301
+ assertSingleExecutionValue ( result ) ;
302
+ expect ( result . errors ) . toBeDefined ( ) ;
303
+ expect ( result . errors ?. map ( ( error ) => error . message ) ) . toEqual ( [
304
+ `Syntax Error: Query depth limit of ${ maxDepth } exceeded, found ${ maxDepth + 2 } .` ,
305
+ ] ) ;
306
+ } ) ;
242
307
} ) ;
0 commit comments