|
1 | | -import redis |
2 | | -import gevent |
3 | 1 | import cPickle |
4 | 2 | from types import FunctionType |
5 | | -from promise import Promise |
| 3 | + |
6 | 4 | from graphql import parse, validate, specified_rules, value_from_ast, execute |
7 | 5 | 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 |
11 | 12 |
|
12 | 13 |
|
13 | 14 | class RedisPubsub(object): |
@@ -81,15 +82,11 @@ def publish(self, trigger_name, payload): |
81 | 82 | def subscribe(self, query, operation_name, callback, variables, context, |
82 | 83 | format_error, format_response): |
83 | 84 | 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) |
90 | 87 |
|
91 | 88 | if errors: |
92 | | - return Promise.reject(ValidationError(errors)) |
| 89 | + return Promise.rejected(ValidationError(errors)) |
93 | 90 |
|
94 | 91 | args = {} |
95 | 92 |
|
@@ -140,14 +137,16 @@ def subscribe(self, query, operation_name, callback, variables, context, |
140 | 137 | 'channel_options', {}) |
141 | 138 | filter = trigger_map[trigger_name].get('filter', |
142 | 139 | lambda arg1, arg2: True) |
143 | | - # TODO: Think about this some more...Apollo library |
| 140 | + # TODO: Think about this some more...the Apollo library |
144 | 141 | # 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 |
146 | 143 | # use 'filter' or 'channel_options' keys); I think it |
147 | 144 | # would be better to raise an exception here |
148 | 145 | except AttributeError: |
149 | 146 | channel_options = {} |
150 | | - filter = lambda arg1, arg2: True |
| 147 | + |
| 148 | + def filter(arg1, arg2): |
| 149 | + return True |
151 | 150 |
|
152 | 151 | def on_message(root_value): |
153 | 152 | def context_promise_handler(result): |
|
0 commit comments