File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1
1
package graphql
2
2
3
+ import graphql.analysis.MaxQueryComplexityInstrumentation
3
4
import graphql.analysis.MaxQueryDepthInstrumentation
4
5
import graphql.language.SourceLocation
5
6
import graphql.schema.DataFetcher
@@ -627,4 +628,47 @@ class GraphQLTest extends Specification {
627
628
" { f2 :field {field {field {scalar}}} f1 : field{scalar} f3 : field {scalar}}" | _
628
629
}
629
630
631
+ @Unroll
632
+ def " abort execution if complexity is too high (#query)" () {
633
+ given:
634
+ def foo = newObject()
635
+ .name(" Foo " )
636
+ .field(newFieldDefinition()
637
+ .name(" field" )
638
+ .type(new GraphQLTypeReference('Foo'))
639
+ .build())
640
+ .field(newFieldDefinition()
641
+ .name(" scalar" )
642
+ .type(GraphQLString)
643
+ .build())
644
+ .build()
645
+ GraphQLSchema schema = newSchema().query(
646
+ newObject()
647
+ .name(" RootQueryType " )
648
+ .field(newFieldDefinition()
649
+ .name(" field" )
650
+ .type(foo)
651
+ .build()).build())
652
+ .build()
653
+
654
+ MaxQueryComplexityInstrumentation maxQueryComplexityInstrumentation = new MaxQueryComplexityInstrumentation(3);
655
+
656
+
657
+ def graphql = GraphQL.newGraphQL(schema).instrumentation(maxQueryComplexityInstrumentation).build()
658
+
659
+ when:
660
+ def result = graphql.execute(query)
661
+
662
+ then:
663
+ result.errors.size() == 1
664
+ result.errors[0].message.contains(" maximum query complexity exceeded" )
665
+
666
+ where:
667
+ query | _
668
+ " { field {field {field {field {scalar}}}} }" | _
669
+ " { field {field {field {scalar}}}} " | _
670
+ " { field {field {field {field {scalar}}}} }" | _
671
+ " { f2 :field {scalar} f1 : field{scalar} f3 : field {scalar}}" | _
672
+ }
673
+
630
674
}
You can’t perform that action at this time.
0 commit comments