@@ -76,7 +76,29 @@ class Playground extends React.Component {
76
76
}
77
77
78
78
this . pypyjs = this . pypy_interpreter . ready ( ) . then ( ( ) => {
79
- return this . pypy_interpreter . exec ( "import graphene" ) ;
79
+ return this . pypy_interpreter . exec ( `
80
+ import graphene
81
+ import js
82
+ from collections import OrderedDict
83
+ from graphql.core.execution.executor import Executor
84
+ from graphql.core.execution.middlewares.sync import SynchronousExecutionMiddleware
85
+ from graphql.core.error import GraphQLError, format_error
86
+
87
+ def get_wrapped(f):
88
+ if hasattr(f, 'func_closure') and f.func_closure:
89
+ return get_wrapped(f.func_closure[0].cell_contents)
90
+ return f
91
+
92
+ class TrackResolver(SynchronousExecutionMiddleware):
93
+ @staticmethod
94
+ def run_resolve_fn(resolver, original_resolver):
95
+ if resolver.func.__module__ == '__main__':
96
+ line = get_wrapped(resolver.func).resolver.func_code.co_firstlineno
97
+ js.globals.markLine(line-3)
98
+ return SynchronousExecutionMiddleware.run_resolve_fn(resolver, original_resolver)
99
+
100
+ __graphene_executor = Executor([TrackResolver()], map_type=OrderedDict)
101
+ ` ) ;
80
102
} ) . then ( ( ) => {
81
103
this . createSchema ( baseCode ) ;
82
104
} ) . then ( ( ) => {
@@ -110,21 +132,21 @@ class Playground extends React.Component {
110
132
this . createSchema ( this . editor . getValue ( ) ) ;
111
133
}
112
134
createSchema ( code ) {
135
+ console . log ( 'createSchema' ) ;
113
136
this . validSchema = null ;
114
137
this . pypyjs . then ( ( ) => {
115
138
return this . pypy_interpreter . exec ( `
116
139
schema = None
117
140
${ code }
118
141
assert schema, 'You have to define a schema'
119
142
` )
143
+ } ) . then ( ( ) => {
144
+ console . log ( 'NO ERRORS' ) ;
145
+ this . validSchema = true ;
120
146
} , ( err ) => {
147
+ console . log ( 'ERROR' , err ) ;
121
148
this . validSchema = false ;
122
149
// this.editor.setGutterMarker(5, "breakpoints", syntaxError());
123
- console . log ( 'ERROR' , err ) ;
124
- } ) . then ( ( ) => {
125
- if ( this . validSchema === null ) {
126
- this . validSchema = true ;
127
- }
128
150
} ) . then ( this . updateGraphiQL . bind ( this ) ) ;
129
151
}
130
152
updateGraphiQL ( ) {
@@ -145,29 +167,8 @@ assert schema, 'You have to define a schema'
145
167
// console.log('execute', query);
146
168
return this . pypyjs . then ( ( ) => {
147
169
var x = `
148
- import js
149
170
import json
150
- from collections import OrderedDict
151
- from graphql.core.execution.executor import Executor
152
- from graphql.core.execution.middlewares.sync import SynchronousExecutionMiddleware
153
- from graphql.core.error import GraphQLError, format_error
154
-
155
- def get_wrapped(f):
156
- if hasattr(f, 'func_closure') and f.func_closure:
157
- return get_wrapped(f.func_closure[0].cell_contents)
158
- return f
159
-
160
- class TrackResolver(SynchronousExecutionMiddleware):
161
- @staticmethod
162
- def run_resolve_fn(resolver, original_resolver):
163
- if resolver.func.__module__ == '__main__':
164
- line = get_wrapped(resolver.func).resolver.func_code.co_firstlineno
165
- js.globals.markLine(line-3)
166
- return SynchronousExecutionMiddleware.run_resolve_fn(resolver, original_resolver)
167
-
168
- executor = Executor([TrackResolver()], map_type=OrderedDict)
169
-
170
- result = executor.execute(schema.schema, '''${ query } ''')
171
+ result = __graphene_executor.execute(schema.schema, '''${ query } ''')
171
172
result_dict = {};
172
173
if result.errors:
173
174
result_dict['errors'] = [format_error(e) for e in result.errors]
0 commit comments