Skip to content

Commit e5f52ab

Browse files
committed
Removed tracing middleware which should be in graphql-server-core
1 parent 9ac6bee commit e5f52ab

File tree

4 files changed

+149
-236
lines changed

4 files changed

+149
-236
lines changed

graphql/execution/executor.py

+3-21
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
get_operation_root_type, SubscriberExecutionContext)
2020
from .executors.sync import SyncExecutor
2121
from .middleware import MiddlewareManager
22-
from .tracing import TracingMiddleware
2322

2423
logger = logging.getLogger(__name__)
2524

@@ -31,8 +30,7 @@ def subscribe(*args, **kwargs):
3130

3231
def execute(schema, document_ast, root_value=None, context_value=None,
3332
variable_values=None, operation_name=None, executor=None,
34-
return_promise=False, middleware=None, allow_subscriptions=False,
35-
tracing=False):
33+
return_promise=False, middleware=None, allow_subscriptions=False):
3634
assert schema, 'Must provide schema'
3735
assert isinstance(schema, GraphQLSchema), (
3836
'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
@@ -48,17 +46,6 @@ def execute(schema, document_ast, root_value=None, context_value=None,
4846
' of MiddlewareManager. Received "{}".'.format(middleware)
4947
)
5048

51-
tracing_middleware = None
52-
if tracing:
53-
tracing_middleware = TracingMiddleware()
54-
tracing_middleware.start()
55-
56-
if middleware:
57-
middleware.middlewares.insert(0, tracing_middleware)
58-
else:
59-
middleware = MiddlewareManager(tracing_middleware)
60-
61-
6249
if executor is None:
6350
executor = SyncExecutor()
6451

@@ -85,15 +72,10 @@ def on_resolve(data):
8572
if isinstance(data, Observable):
8673
return data
8774

88-
extensions = dict()
89-
if tracing_middleware:
90-
tracing_middleware.end()
91-
extensions['tracing'] = tracing_middleware.tracing_dict
92-
9375
if not context.errors:
94-
return ExecutionResult(data=data, extensions=extensions)
76+
return ExecutionResult(data=data)
9577

96-
return ExecutionResult(data=data, extensions=extensions, errors=context.errors)
78+
return ExecutionResult(data=data, errors=context.errors)
9779

9880
promise = Promise.resolve(None).then(executor).catch(on_rejected).then(on_resolve)
9981

graphql/execution/tests/test_executor.py

+146-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from graphql.language.parser import parse
88
from graphql.type import (GraphQLArgument, GraphQLBoolean, GraphQLField,
99
GraphQLInt, GraphQLList, GraphQLObjectType,
10-
GraphQLSchema, GraphQLString)
10+
GraphQLSchema, GraphQLString, GraphQLNonNull)
1111
from promise import Promise
1212

1313

@@ -668,3 +668,148 @@ def resolve(self, next, *args, **kwargs):
668668
middleware=middlewares_without_promise)
669669
assert result1.data == result2.data and result1.data == {
670670
'ok': 'ok', 'not_ok': 'not_ok'}
671+
672+
673+
def test_executor_properly_propogates_path_data(mocker):
674+
time_mock = mocker.patch('time.time')
675+
time_mock.side_effect = range(0, 10000)
676+
677+
BlogImage = GraphQLObjectType('BlogImage', {
678+
'url': GraphQLField(GraphQLString),
679+
'width': GraphQLField(GraphQLInt),
680+
'height': GraphQLField(GraphQLInt),
681+
})
682+
683+
BlogAuthor = GraphQLObjectType('Author', lambda: {
684+
'id': GraphQLField(GraphQLString),
685+
'name': GraphQLField(GraphQLString),
686+
'pic': GraphQLField(BlogImage,
687+
args={
688+
'width': GraphQLArgument(GraphQLInt),
689+
'height': GraphQLArgument(GraphQLInt),
690+
},
691+
resolver=lambda obj, info, **args:
692+
obj.pic(args['width'], args['height'])
693+
),
694+
'recentArticle': GraphQLField(BlogArticle),
695+
})
696+
697+
BlogArticle = GraphQLObjectType('Article', {
698+
'id': GraphQLField(GraphQLNonNull(GraphQLString)),
699+
'isPublished': GraphQLField(GraphQLBoolean),
700+
'author': GraphQLField(BlogAuthor),
701+
'title': GraphQLField(GraphQLString),
702+
'body': GraphQLField(GraphQLString),
703+
'keywords': GraphQLField(GraphQLList(GraphQLString)),
704+
})
705+
706+
BlogQuery = GraphQLObjectType('Query', {
707+
'article': GraphQLField(
708+
BlogArticle,
709+
args={'id': GraphQLArgument(GraphQLID)},
710+
resolver=lambda obj, info, **args: Article(args['id'])),
711+
'feed': GraphQLField(
712+
GraphQLList(BlogArticle),
713+
resolver=lambda *_: map(Article, range(1, 2 + 1))),
714+
})
715+
716+
BlogSchema = GraphQLSchema(BlogQuery)
717+
718+
class Article(object):
719+
720+
def __init__(self, id):
721+
self.id = id
722+
self.isPublished = True
723+
self.author = Author()
724+
self.title = 'My Article {}'.format(id)
725+
self.body = 'This is a post'
726+
self.hidden = 'This data is not exposed in the schema'
727+
self.keywords = ['foo', 'bar', 1, True, None]
728+
729+
class Author(object):
730+
id = 123
731+
name = 'John Smith'
732+
733+
def pic(self, width, height):
734+
return Pic(123, width, height)
735+
736+
@property
737+
def recentArticle(self): return Article(1)
738+
739+
class Pic(object):
740+
def __init__(self, uid, width, height):
741+
self.url = 'cdn://{}'.format(uid)
742+
self.width = str(width)
743+
self.height = str(height)
744+
745+
class PathCollectorMiddleware(object):
746+
def __init__(self):
747+
self.paths = []
748+
749+
def resolve(self, _next, root, info, *args, **kwargs):
750+
self.paths.append(info.path)
751+
return _next(root, info, *args, **kwargs)
752+
753+
request = '''
754+
{
755+
feed {
756+
id
757+
...articleFields
758+
author {
759+
id
760+
name
761+
}
762+
},
763+
}
764+
fragment articleFields on Article {
765+
title,
766+
body,
767+
hidden,
768+
}
769+
'''
770+
771+
paths_middleware = PathCollectorMiddleware()
772+
773+
result = execute(BlogSchema, parse(request), middleware=(paths_middleware, ))
774+
assert not result.errors
775+
assert result.data == \
776+
{
777+
"feed": [
778+
{
779+
"id": "1",
780+
"title": "My Article 1",
781+
"body": "This is a post",
782+
"author": {
783+
"id": "123",
784+
"name": "John Smith"
785+
}
786+
},
787+
{
788+
"id": "2",
789+
"title": "My Article 2",
790+
"body": "This is a post",
791+
"author": {
792+
"id": "123",
793+
"name": "John Smith"
794+
}
795+
},
796+
],
797+
}
798+
799+
traversed_paths = paths_middleware.paths
800+
assert traversed_paths == [
801+
['feed'],
802+
['feed', 0, 'id'],
803+
['feed', 0, 'title'],
804+
['feed', 0, 'body'],
805+
['feed', 0, 'author'],
806+
['feed', 1, 'id'],
807+
['feed', 1, 'title'],
808+
['feed', 1, 'body'],
809+
['feed', 1, 'author'],
810+
['feed', 0, 'author', 'id'],
811+
['feed', 0, 'author', 'name'],
812+
['feed', 1, 'author', 'id'],
813+
['feed', 1, 'author', 'name']
814+
]
815+

graphql/execution/tests/test_tracing.py

-153
This file was deleted.

0 commit comments

Comments
 (0)