File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
packages/plugins/max-depth Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @escape.tech/graphql-armor-max-depth " : patch
3+ ---
4+
5+ fix: max-depth ignore only Field Node named __ schema
Original file line number Diff line number Diff line change @@ -76,7 +76,12 @@ class MaxDepthVisitor {
7676 node : FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode | FragmentSpreadNode ,
7777 parentDepth = 0 ,
7878 ) : number {
79- if ( this . config . ignoreIntrospection && 'name' in node && node . name ?. value === '__schema' ) {
79+ if (
80+ this . config . ignoreIntrospection &&
81+ 'name' in node &&
82+ node . name ?. value === '__schema' &&
83+ node . kind === Kind . FIELD
84+ ) {
8085 return 0 ;
8186 }
8287 let depth = parentDepth ;
Original file line number Diff line number Diff line change @@ -239,4 +239,34 @@ describe('maxDepthPlugin', () => {
239239 `Syntax Error: Query depth limit of ${ maxDepth } exceeded, found ${ maxDepth + 1 } .` ,
240240 ] ) ;
241241 } ) ;
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+ } ) ;
242272} ) ;
You can’t perform that action at this time.
0 commit comments