@@ -36,12 +36,18 @@ def get_introspection_query(
3636 input_value_deprecation : bool = False ,
3737 experimental_directive_deprecation : bool = False ,
3838 input_object_one_of : bool = False ,
39+ type_depth : int = 9 ,
3940) -> str :
4041 """Get a query for introspection.
4142
4243 Optionally, you can exclude descriptions, include specification URLs,
4344 include repeatability of directives, and specify whether to include
4445 the schema description as well.
46+
47+ The ``type_depth`` argument controls how deep to recurse into nested types.
48+ Larger values will result in more accurate results, but have a higher load
49+ on the server. Some servers might restrict the maximum query depth or
50+ complexity. If that's the case, try decreasing this value. The default is 9.
4551 """
4652 maybe_description = "description" if descriptions else ""
4753 maybe_specified_by_url = "specifiedByURL" if specified_by_url else ""
@@ -55,6 +61,22 @@ def input_deprecation(string: str) -> Optional[str]:
5561 def directive_deprecation (string : str ) -> Optional [str ]:
5662 return string if experimental_directive_deprecation else ""
5763
64+ def of_type (level : int , indent : str ) -> str :
65+ if level <= 0 :
66+ return ""
67+ if level > 100 :
68+ msg = (
69+ "Please set type_depth to a reasonable value"
70+ " between 0 and 100; the default is 9."
71+ )
72+ raise ValueError (msg )
73+ return (
74+ f"\n { indent } ofType {{"
75+ f"\n { indent } name"
76+ f"\n { indent } kind{ of_type (level - 1 , indent + ' ' )} "
77+ f"\n { indent } }}"
78+ )
79+
5880 return dedent (f"""
5981 query IntrospectionQuery {{
6082 __schema {{
@@ -125,43 +147,7 @@ def directive_deprecation(string: str) -> Optional[str]:
125147
126148 fragment TypeRef on __Type {{
127149 kind
128- name
129- ofType {{
130- kind
131- name
132- ofType {{
133- kind
134- name
135- ofType {{
136- kind
137- name
138- ofType {{
139- kind
140- name
141- ofType {{
142- kind
143- name
144- ofType {{
145- kind
146- name
147- ofType {{
148- kind
149- name
150- ofType {{
151- kind
152- name
153- ofType {{
154- kind
155- name
156- }}
157- }}
158- }}
159- }}
160- }}
161- }}
162- }}
163- }}
164- }}
150+ name{ of_type (type_depth , " " )}
165151 }}
166152 """ )
167153
0 commit comments