-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompiled.py
More file actions
36 lines (32 loc) · 1.23 KB
/
compiled.py
File metadata and controls
36 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class GraphQLCompiledDocument(object):
@classmethod
def from_code(cls, schema, code, uptodate=None, extra_namespace=None):
"""Creates a GraphQLQuery object from compiled code and the globals. This
is used by the loaders and schema to create a template object.
"""
namespace = {"__file__": code.co_filename}
exec(code, namespace)
if extra_namespace:
namespace.update(extra_namespace)
rv = cls._from_namespace(schema, namespace)
rv._uptodate = uptodate
return rv
@classmethod
def from_module_dict(cls, schema, module_dict):
"""Creates a template object from a module. This is used by the
module loader to create a template object.
"""
return cls._from_namespace(schema, module_dict)
@classmethod
def _from_namespace(cls, schema, namespace):
t = object.__new__(cls)
t.schema = schema
t.execute_func = namespace["execute"]
t._module = None
t._uptodate = None
# store the reference
namespace["schema"] = schema
namespace["__graphql_query__"] = t
return t
def execute(self, *args, **kwargs):
return self.execute_func(*args, **kwargs)