1212from hypothesis .strategies ._internal .utils import cacheable
1313
1414from .. import nodes
15- from ..types import AstPrinter , CustomScalarStrategies , Field , InputTypeNode , InterfaceOrObject , SelectionNodes
15+ from ..types import (
16+ AstPrinter ,
17+ CustomScalarStrategies ,
18+ Field ,
19+ InputTypeNode ,
20+ InterfaceOrObject ,
21+ SelectionNodes ,
22+ )
1623from . import factories , primitives , validation
1724from .ast import make_mutation , make_query
1825from .containers import flatten
@@ -51,7 +58,9 @@ class GraphQLStrategy:
5158 _cache : Dict [str , Dict ] = dataclasses .field (default_factory = dict )
5259
5360 def values (
54- self , type_ : graphql .GraphQLInputType , default : Optional [graphql .ValueNode ] = None
61+ self ,
62+ type_ : graphql .GraphQLInputType ,
63+ default : Optional [graphql .ValueNode ] = None ,
5564 ) -> st .SearchStrategy [InputTypeNode ]:
5665 """Generate value nodes of a type, that corresponds to the input type.
5766
@@ -81,9 +90,18 @@ def values(
8190 return self .objects (type_ , nullable )
8291 raise TypeError (f"Type { type_ .__class__ .__name__ } is not supported." )
8392
84- @instance_cache (lambda type_ , nullable = True , default = None : (make_type_name (type_ ), nullable , default ))
93+ @instance_cache (
94+ lambda type_ , nullable = True , default = None : (
95+ make_type_name (type_ ),
96+ nullable ,
97+ default ,
98+ )
99+ )
85100 def lists (
86- self , type_ : graphql .GraphQLList , nullable : bool = True , default : Optional [graphql .ValueNode ] = None
101+ self ,
102+ type_ : graphql .GraphQLList ,
103+ nullable : bool = True ,
104+ default : Optional [graphql .ValueNode ] = None ,
87105 ) -> st .SearchStrategy [graphql .ListValueNode ]:
88106 """Generate a `graphql.ListValueNode`."""
89107 strategy = st .lists (self .values (type_ .of_type ))
@@ -121,16 +139,24 @@ def lists_of_object_fields(
121139 ) -> st .SearchStrategy [List [graphql .ObjectFieldNode ]]:
122140 return st .tuples (
123141 * (
124- self .values (field .type , field .ast_node .default_value if field .ast_node is not None else None ).map (
125- factories .object_field (name )
126- )
142+ self .values (
143+ field .type ,
144+ field .ast_node .default_value if field .ast_node is not None else None ,
145+ ).map (factories .object_field (name ))
127146 for name , field in items
128147 )
129148 ).map (list )
130149
131- @instance_cache (lambda interface , implementations : (interface .name , tuple (impl .name for impl in implementations )))
150+ @instance_cache (
151+ lambda interface , implementations : (
152+ interface .name ,
153+ tuple (impl .name for impl in implementations ),
154+ )
155+ )
132156 def interfaces (
133- self , interface : graphql .GraphQLInterfaceType , implementations : List [InterfaceOrObject ]
157+ self ,
158+ interface : graphql .GraphQLInterfaceType ,
159+ implementations : List [InterfaceOrObject ],
134160 ) -> st .SearchStrategy [SelectionNodes ]:
135161 """Build query for GraphQL interface type."""
136162 # If there are implementations that have fields with the same name but different types
@@ -376,7 +402,12 @@ def queries(
376402 if parsed_schema .query_type is None :
377403 raise InvalidArgument ("Query type is not defined in the schema" )
378404 return (
379- _make_strategy (parsed_schema , type_ = parsed_schema .query_type , fields = fields , custom_scalars = custom_scalars )
405+ _make_strategy (
406+ parsed_schema ,
407+ type_ = parsed_schema .query_type ,
408+ fields = fields ,
409+ custom_scalars = custom_scalars ,
410+ )
380411 .map (make_query )
381412 .map (print_ast )
382413 )
@@ -403,7 +434,12 @@ def mutations(
403434 if parsed_schema .mutation_type is None :
404435 raise InvalidArgument ("Mutation type is not defined in the schema" )
405436 return (
406- _make_strategy (parsed_schema , type_ = parsed_schema .mutation_type , fields = fields , custom_scalars = custom_scalars )
437+ _make_strategy (
438+ parsed_schema ,
439+ type_ = parsed_schema .mutation_type ,
440+ fields = fields ,
441+ custom_scalars = custom_scalars ,
442+ )
407443 .map (make_mutation )
408444 .map (print_ast )
409445 )
0 commit comments