Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix introspection query validator
Patryk Zawadzkiba0f225cc7d3
diff --git a/saleor/graphql/tests/test_utils.py b/saleor/graphql/tests/test_utils.pyindex 03fb13517b..b6a4f21d2e 100644--- a/saleor/graphql/tests/test_utils.py+++ b/saleor/graphql/tests/test_utils.py@@ -223,3 +223,112 @@ def test_check_if_query_contains_only_schema_with_schema_query_and_fragments():# thenassert result is True+++def test_check_if_query_contains_only_schema_with_introspection():+ # given+ query = """+ query IntrospectionQuery {+ __schema {+ queryType { name }+ mutationType { name }+ subscriptionType { name }+ types {+ ...FullType+ }+ directives {+ name+ description+ locations+ args {+ ...InputValue+ }+ }+ }+ }+ fragment FullType on __Type {+ kind+ name+ description+ fields(includeDeprecated: true) {+ name+ description+ args {+ ...InputValue+ }+ type {+ ...TypeRef+ }+ isDeprecated+ deprecationReason+ }+ inputFields {+ ...InputValue+ }+ interfaces {+ ...TypeRef+ }+ enumValues(includeDeprecated: true) {+ name+ description+ isDeprecated+ deprecationReason+ }+ possibleTypes {+ ...TypeRef+ }+ }+ fragment InputValue on __InputValue {+ name+ description+ type { ...TypeRef }+ defaultValue+ }+ fragment TypeRef on __Type {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ ofType {+ kind+ name+ }+ }+ }+ }+ }+ }+ }+ }+ }+ }+ """+ document = backend.document_from_string(schema, query)++ # when+ result = check_if_query_contains_only_schema(document)++ # then+ assert result is Truediff --git a/saleor/graphql/utils/validators.py b/saleor/graphql/utils/validators.pyindex 248797f49f..ee9a6ac512 100644--- a/saleor/graphql/utils/validators.py+++ b/saleor/graphql/utils/validators.py@@ -78,8 +78,11 @@ def __queries_or_introspection_in_operation_definition(definition: OperationDefidef __queries_or_introspection_in_fragment_definition(definition: FragmentDefinition):selections = definition.selection_set.selections- if definition.type_condition and definition.type_condition.name.value == "Query":- return __queries_or_introspection_in_selections(selections, is_query=True)+ if definition.type_condition:+ if definition.type_condition.name.value == "Query":+ return __queries_or_introspection_in_selections(selections, is_query=True)+ if definition.type_condition.name.value.startswith("__"):+ return False, Truereturn __queries_or_introspection_in_selections(selections, is_query=False)