File tree Expand file tree Collapse file tree 6 files changed +34
-0
lines changed
Expand file tree Collapse file tree 6 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -335,3 +335,17 @@ def format_execution_result(
335335 response = {"data" : execution_result .data }
336336
337337 return FormattedResult (response , status_code )
338+
339+
340+ def _check_jinja (jinja_env : Any ) -> None :
341+ try :
342+ from jinja2 import Environment
343+ except ImportError :
344+ raise RuntimeError (
345+ "Attempt to set 'jinja_env' to a value other than None while Jinja2 is not installed.\n "
346+ "Please install Jinja2 to render GraphiQL with Jinja2.\n "
347+ "Otherwise set 'jinja_env' to None to use the simple regex renderer."
348+ )
349+
350+ if not isinstance (jinja_env , Environment ):
351+ raise TypeError ("'jinja_env' has to be of type jinja2.Environment." )
Original file line number Diff line number Diff line change 1010from graphql_server import (
1111 GraphQLParams ,
1212 HttpQueryError ,
13+ _check_jinja ,
1314 encode_execution_results ,
1415 format_error_default ,
1516 json_encode ,
@@ -63,6 +64,9 @@ def __init__(self, **kwargs):
6364 if not isinstance (self .schema , GraphQLSchema ):
6465 raise TypeError ("A Schema is required to be provided to GraphQLView." )
6566
67+ if self .jinja_env is not None :
68+ _check_jinja (self .jinja_env )
69+
6670 def get_root_value (self ):
6771 return self .root_value
6872
Original file line number Diff line number Diff line change 1212from graphql_server import (
1313 GraphQLParams ,
1414 HttpQueryError ,
15+ _check_jinja ,
1516 encode_execution_results ,
1617 format_error_default ,
1718 json_encode ,
@@ -63,6 +64,9 @@ def __init__(self, **kwargs):
6364 if not isinstance (self .schema , GraphQLSchema ):
6465 raise TypeError ("A Schema is required to be provided to GraphQLView." )
6566
67+ if self .jinja_env is not None :
68+ _check_jinja (self .jinja_env )
69+
6670 def get_root_value (self ):
6771 return self .root_value
6872
Original file line number Diff line number Diff line change 1212from graphql_server import (
1313 GraphQLParams ,
1414 HttpQueryError ,
15+ _check_jinja ,
1516 encode_execution_results ,
1617 format_error_default ,
1718 json_encode ,
@@ -64,6 +65,9 @@ def __init__(self, **kwargs):
6465 if not isinstance (self .schema , GraphQLSchema ):
6566 raise TypeError ("A Schema is required to be provided to GraphQLView." )
6667
68+ if self .jinja_env is not None :
69+ _check_jinja (self .jinja_env )
70+
6771 def get_root_value (self ):
6872 return self .root_value
6973
Original file line number Diff line number Diff line change 1212from graphql_server import (
1313 GraphQLParams ,
1414 HttpQueryError ,
15+ _check_jinja ,
1516 encode_execution_results ,
1617 format_error_default ,
1718 json_encode ,
@@ -65,6 +66,9 @@ def __init__(self, **kwargs):
6566 if not isinstance (self .schema , GraphQLSchema ):
6667 raise TypeError ("A Schema is required to be provided to GraphQLView." )
6768
69+ if self .jinja_env is not None :
70+ _check_jinja (self .jinja_env )
71+
6872 def get_root_value (self ):
6973 return self .root_value
7074
Original file line number Diff line number Diff line change 1111from graphql_server import (
1212 GraphQLParams ,
1313 HttpQueryError ,
14+ _check_jinja ,
1415 encode_execution_results ,
1516 format_error_default ,
1617 json_encode ,
@@ -62,6 +63,9 @@ def __init__(self, **kwargs):
6263 if not isinstance (self .schema , GraphQLSchema ):
6364 raise TypeError ("A Schema is required to be provided to GraphQLView." )
6465
66+ if self .jinja_env is not None :
67+ _check_jinja (self .jinja_env )
68+
6569 def get_root_value (self ):
6670 return self .root_value
6771
You can’t perform that action at this time.
0 commit comments