File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 1818use GraphQL \Language \VisitorOperation ;
1919use GraphQL \Type \Definition \Directive ;
2020use GraphQL \Type \Definition \FieldDefinition ;
21+ use GraphQL \Type \Introspection ;
2122use GraphQL \Validator \QueryValidationContext ;
2223
2324/**
@@ -117,6 +118,11 @@ protected function nodeComplexity(SelectionNode $node): int
117118 {
118119 switch (true ) {
119120 case $ node instanceof FieldNode:
121+ // Exclude __schema field and all nested content from complexity calculation
122+ if ($ node ->name ->value === Introspection::SCHEMA_FIELD_NAME ) {
123+ return 0 ;
124+ }
125+
120126 if ($ this ->directiveExcludesField ($ node )) {
121127 return 0 ;
122128 }
Original file line number Diff line number Diff line change 55use GraphQL \Error \Error ;
66use GraphQL \Language \AST \NodeKind ;
77use GraphQL \Language \Parser ;
8+ use GraphQL \Type \Introspection ;
89use GraphQL \Validator \DocumentValidator ;
910use GraphQL \Validator \Rules \CustomValidationRule ;
1011use GraphQL \Validator \Rules \QueryComplexity ;
@@ -164,7 +165,16 @@ public function testQueryWithCustomAndSkipDirective(): void
164165
165166 public function testComplexityIntrospectionQuery (): void
166167 {
167- $ this ->assertIntrospectionQuery (187 );
168+ $ query = Introspection::getIntrospectionQuery ();
169+
170+ $ this ->assertDocumentValidator ($ query , 0 );
171+ }
172+
173+ public function testMixedIntrospectionAndRegularFields (): void
174+ {
175+ $ query = 'query MyQuery { __schema { queryType { name } } human { firstName } } ' ;
176+
177+ $ this ->assertDocumentValidators ($ query , 2 , 3 );
168178 }
169179
170180 public function testIntrospectionTypeMetaFieldQuery (): void
You can’t perform that action at this time.
0 commit comments