Skip to content

Commit a0a9ff0

Browse files
committed
Modify subscription_manager module to fix bugs
Found several minor bugs while completing tests for subscription_manager module. Fixed that module, as well as subscription_transport_ws module so that tests would pass.
1 parent 4fadf59 commit a0a9ff0

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

graphql_subscriptions/subscription_manager.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import redis
2-
import gevent
31
import cPickle
42
from types import FunctionType
5-
from promise import Promise
3+
64
from graphql import parse, validate, specified_rules, value_from_ast, execute
75
from graphql.language.ast import OperationDefinition
8-
# TODO: replace graphene dependency aith my own utils
9-
# folder and function
10-
from graphene.utils.str_converters import to_snake_case
6+
from promise import Promise
7+
import gevent
8+
import redis
9+
10+
from .utils import to_snake_case
11+
from .validation import SubscriptionHasSingleRootField
1112

1213

1314
class RedisPubsub(object):
@@ -81,15 +82,11 @@ def publish(self, trigger_name, payload):
8182
def subscribe(self, query, operation_name, callback, variables, context,
8283
format_error, format_response):
8384
parsed_query = parse(query)
84-
errors = validate(
85-
self.schema,
86-
parsed_query,
87-
# TODO: Need to create/add subscriptionHasSingleRootField
88-
# rule from apollo subscription manager package
89-
rules=specified_rules)
85+
rules = specified_rules + [SubscriptionHasSingleRootField]
86+
errors = validate(self.schema, parsed_query, rules=rules)
9087

9188
if errors:
92-
return Promise.reject(ValidationError(errors))
89+
return Promise.rejected(ValidationError(errors))
9390

9491
args = {}
9592

@@ -140,14 +137,16 @@ def subscribe(self, query, operation_name, callback, variables, context,
140137
'channel_options', {})
141138
filter = trigger_map[trigger_name].get('filter',
142139
lambda arg1, arg2: True)
143-
# TODO: Think about this some more...Apollo library
140+
# TODO: Think about this some more...the Apollo library
144141
# let's all messages through by default, even if
145-
# the users incorrectly uses the setup_funcs (do not
142+
# the users incorrectly uses the setup_funcs (does not
146143
# use 'filter' or 'channel_options' keys); I think it
147144
# would be better to raise an exception here
148145
except AttributeError:
149146
channel_options = {}
150-
filter = lambda arg1, arg2: True
147+
148+
def filter(arg1, arg2):
149+
return True
151150

152151
def on_message(root_value):
153152
def context_promise_handler(result):

graphql_subscriptions/subscription_transport_ws.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ def subscription_start_promise_handler(init_result):
132132
'operation_name': parsed_message.get('operation_name'),
133133
'callback': None,
134134
'variables': parsed_message.get('variables'),
135-
'context': init_result
136-
if isinstance(init_result, dict) else {},
135+
'context': init_result if isinstance(
136+
init_result, dict) else {},
137137
'format_error': None,
138-
'callback': None
138+
'format_response': None
139139
}
140140
promised_params = Promise.resolve(base_params)
141141

0 commit comments

Comments
 (0)