12
12
13
13
from .classtypes .base import ClassType
14
14
from .types .base import BaseType
15
+ from ..plugins import Plugin , CamelCase
15
16
16
17
17
18
class GraphQLSchema (_GraphQLSchema ):
@@ -25,20 +26,33 @@ class Schema(object):
25
26
_executor = None
26
27
27
28
def __init__ (self , query = None , mutation = None , subscription = None ,
28
- name = 'Schema' , executor = None ):
29
+ name = 'Schema' , executor = None , plugins = None , auto_camelcase = True ):
29
30
self ._types_names = {}
30
31
self ._types = {}
31
32
self .mutation = mutation
32
33
self .query = query
33
34
self .subscription = subscription
34
35
self .name = name
35
36
self .executor = executor
37
+ self .plugins = []
38
+ plugins = plugins or []
39
+ if auto_camelcase :
40
+ plugins .append (CamelCase ())
41
+ for plugin in plugins :
42
+ self .add_plugin (plugin )
36
43
signals .init_schema .send (self )
37
44
38
45
def __repr__ (self ):
39
46
return '<Schema: %s (%s)>' % (str (self .name ), hash (self ))
40
47
48
+ def add_plugin (self , plugin ):
49
+ assert isinstance (plugin , Plugin ), 'A plugin need to subclass graphene.Plugin and be instantiated'
50
+ plugin .contribute_to_schema (self )
51
+ self .plugins .append (plugin )
52
+
41
53
def get_internal_type (self , objecttype ):
54
+ for plugin in self .plugins :
55
+ objecttype = plugin .transform_type (objecttype )
42
56
return objecttype .internal_type (self )
43
57
44
58
def T (self , object_type ):
0 commit comments