1
- from functools import reduce
2
1
from .definition import (
3
2
GraphQLInputObjectType ,
4
3
GraphQLInterfaceType ,
@@ -24,6 +23,7 @@ class GraphQLSchema(object):
24
23
mutation=MyAppMutationRootType
25
24
)
26
25
"""
26
+
27
27
def __init__ (self , query , mutation = None ):
28
28
self .query = query
29
29
self .mutation = mutation
@@ -56,15 +56,15 @@ def get_directive(self, name):
56
56
for directive in self .get_directives ():
57
57
if directive .name == name :
58
58
return directive
59
+
59
60
return None
60
61
61
62
def _build_type_map (self ):
62
- # TODO: make pythonic
63
- return reduce (type_map_reducer , [
64
- self .get_query_type (),
65
- self .get_mutation_type (),
66
- IntrospectionSchema ,
67
- ], {})
63
+ type_map = {}
64
+ for type in (self .get_query_type (), self .get_mutation_type (), IntrospectionSchema ):
65
+ type_map = type_map_reducer (type_map , type )
66
+
67
+ return type_map
68
68
69
69
70
70
def type_map_reducer (map , type ):
@@ -80,28 +80,26 @@ def type_map_reducer(map, type):
80
80
.format (type .name )
81
81
)
82
82
return map
83
+
83
84
map [type .name ] = type
84
85
85
86
reduced_map = map
86
87
87
88
if isinstance (type , (GraphQLUnionType , GraphQLInterfaceType )):
88
- reduced_map = reduce (
89
- type_map_reducer , type .get_possible_types (), reduced_map
90
- )
89
+ for t in type .get_possible_types ():
90
+ reduced_map = type_map_reducer (reduced_map , t )
91
91
92
92
if isinstance (type , GraphQLObjectType ):
93
- reduced_map = reduce (
94
- type_map_reducer , type .get_interfaces (), reduced_map
95
- )
93
+ for t in type .get_interfaces ():
94
+ reduced_map = type_map_reducer (reduced_map , t )
96
95
97
96
if isinstance (type , (GraphQLObjectType , GraphQLInterfaceType , GraphQLInputObjectType )):
98
97
field_map = type .get_fields ()
99
- for field_name , field in field_map .items ():
98
+ for field in field_map .values ():
100
99
if hasattr (field , 'args' ):
101
100
field_arg_types = [arg .type for arg in field .args ]
102
- reduced_map = reduce (
103
- type_map_reducer , field_arg_types , reduced_map
104
- )
101
+ for t in field_arg_types :
102
+ reduced_map = type_map_reducer (reduced_map , t )
105
103
106
104
reduced_map = type_map_reducer (reduced_map , getattr (field , 'type' , None ))
107
105
0 commit comments