@@ -112,7 +112,8 @@ def deeper(self):
112
112
113
113
schema = GraphQLSchema (query = DataType )
114
114
115
- result = execute (schema , ast , Data (), operation_name = 'Example' , variable_values = {'size' : 100 })
115
+ result = execute (schema , ast , Data (),
116
+ operation_name = 'Example' , variable_values = {'size' : 100 })
116
117
assert not result .errors
117
118
assert result .data == expected
118
119
@@ -178,7 +179,8 @@ def resolver(root_value, *_):
178
179
'a' : GraphQLField (GraphQLString , resolver = resolver )
179
180
})
180
181
181
- result = execute (GraphQLSchema (Type ), ast , Data (), operation_name = 'Example' )
182
+ result = execute (GraphQLSchema (Type ), ast ,
183
+ Data (), operation_name = 'Example' )
182
184
assert not result .errors
183
185
assert resolver .got_here
184
186
@@ -209,7 +211,8 @@ def resolver(source, info, numArg, stringArg):
209
211
resolver = resolver ),
210
212
})
211
213
212
- result = execute (GraphQLSchema (Type ), doc_ast , None , operation_name = 'Example' )
214
+ result = execute (GraphQLSchema (Type ), doc_ast ,
215
+ None , operation_name = 'Example' )
213
216
assert not result .errors
214
217
assert resolver .got_here
215
218
@@ -282,7 +285,8 @@ class Data(object):
282
285
Type = GraphQLObjectType ('Type' , {
283
286
'a' : GraphQLField (GraphQLString )
284
287
})
285
- result = execute (GraphQLSchema (Type ), ast , Data (), operation_name = 'OtherExample' )
288
+ result = execute (GraphQLSchema (Type ), ast , Data (),
289
+ operation_name = 'OtherExample' )
286
290
assert not result .errors
287
291
assert result .data == {'second' : 'b' }
288
292
@@ -313,7 +317,8 @@ class Data(object):
313
317
'a' : GraphQLField (GraphQLString )
314
318
})
315
319
with raises (GraphQLError ) as excinfo :
316
- execute (GraphQLSchema (Type ), ast , Data (), operation_name = "UnknownExample" )
320
+ execute (GraphQLSchema (Type ), ast , Data (),
321
+ operation_name = "UnknownExample" )
317
322
assert 'Unknown operation named "UnknownExample".' == str (excinfo .value )
318
323
319
324
@@ -329,7 +334,8 @@ class Data(object):
329
334
})
330
335
with raises (GraphQLError ) as excinfo :
331
336
execute (GraphQLSchema (Type ), ast , Data ())
332
- assert 'Must provide operation name if query contains multiple operations.' == str (excinfo .value )
337
+ assert 'Must provide operation name if query contains multiple operations.' == str (
338
+ excinfo .value )
333
339
334
340
335
341
def test_uses_the_query_schema_for_queries ():
@@ -374,6 +380,7 @@ class Data(object):
374
380
375
381
376
382
def test_uses_the_subscription_schema_for_subscriptions ():
383
+ from rx import Observable
377
384
doc = 'query Q { a } subscription S { a }'
378
385
379
386
class Data (object ):
@@ -385,9 +392,14 @@ class Data(object):
385
392
'a' : GraphQLField (GraphQLString )
386
393
})
387
394
S = GraphQLObjectType ('S' , {
388
- 'a' : GraphQLField (GraphQLString )
395
+ 'a' : GraphQLField (GraphQLString , resolver = lambda root , info : Observable . from_ ([ 'b' ]) )
389
396
})
390
- result = execute (GraphQLSchema (Q , subscription = S ), ast , Data (), operation_name = 'S' )
397
+ result = execute (GraphQLSchema (Q , subscription = S ),
398
+ ast , Data (), operation_name = 'S' )
399
+ assert isinstance (result , Observable )
400
+ l = []
401
+ result .subscribe (l .append )
402
+ result = l [0 ]
391
403
assert not result .errors
392
404
assert result .data == {'a' : 'b' }
393
405
@@ -437,7 +449,8 @@ def test_does_not_include_arguments_that_were_not_set():
437
449
{
438
450
'field' : GraphQLField (
439
451
GraphQLString ,
440
- resolver = lambda source , info , ** args : args and json .dumps (args , sort_keys = True , separators = (',' , ':' )),
452
+ resolver = lambda source , info , ** args : args and json .dumps (
453
+ args , sort_keys = True , separators = (',' , ':' )),
441
454
args = {
442
455
'a' : GraphQLArgument (GraphQLBoolean ),
443
456
'b' : GraphQLArgument (GraphQLBoolean ),
@@ -501,7 +514,8 @@ def __init__(self, value):
501
514
]
502
515
}
503
516
504
- assert 'Expected value of type "SpecialType" but got: NotSpecial.' in [str (e ) for e in result .errors ]
517
+ assert 'Expected value of type "SpecialType" but got: NotSpecial.' in [
518
+ str (e ) for e in result .errors ]
505
519
506
520
507
521
def test_fails_to_execute_a_query_containing_a_type_definition ():
@@ -547,7 +561,8 @@ def resolver(*_):
547
561
)
548
562
549
563
execute (schema , query )
550
- logger .exception .assert_called_with ("An error occurred while resolving field Query.foo" )
564
+ logger .exception .assert_called_with (
565
+ "An error occurred while resolving field Query.foo" )
551
566
552
567
553
568
def test_middleware ():
@@ -576,7 +591,8 @@ def reversed_middleware(next, *args, **kwargs):
576
591
return p .then (lambda x : x [::- 1 ])
577
592
578
593
middlewares = MiddlewareManager (reversed_middleware )
579
- result = execute (GraphQLSchema (Type ), doc_ast , Data (), middleware = middlewares )
594
+ result = execute (GraphQLSchema (Type ), doc_ast ,
595
+ Data (), middleware = middlewares )
580
596
assert result .data == {'ok' : 'ko' , 'not_ok' : 'ko_ton' }
581
597
582
598
@@ -607,7 +623,8 @@ def resolve(self, next, *args, **kwargs):
607
623
return p .then (lambda x : x [::- 1 ])
608
624
609
625
middlewares = MiddlewareManager (MyMiddleware ())
610
- result = execute (GraphQLSchema (Type ), doc_ast , Data (), middleware = middlewares )
626
+ result = execute (GraphQLSchema (Type ), doc_ast ,
627
+ Data (), middleware = middlewares )
611
628
assert result .data == {'ok' : 'ko' , 'not_ok' : 'ko_ton' }
612
629
613
630
@@ -640,9 +657,14 @@ class MyEmptyMiddleware(object):
640
657
def resolve (self , next , * args , ** kwargs ):
641
658
return next (* args , ** kwargs )
642
659
643
- middlewares_with_promise = MiddlewareManager (MyPromiseMiddleware (), wrap_in_promise = False )
644
- middlewares_without_promise = MiddlewareManager (MyEmptyMiddleware (), wrap_in_promise = False )
645
-
646
- result1 = execute (GraphQLSchema (Type ), doc_ast , Data (), middleware = middlewares_with_promise )
647
- result2 = execute (GraphQLSchema (Type ), doc_ast , Data (), middleware = middlewares_without_promise )
648
- assert result1 .data == result2 .data and result1 .data == {'ok' : 'ok' , 'not_ok' : 'not_ok' }
660
+ middlewares_with_promise = MiddlewareManager (
661
+ MyPromiseMiddleware (), wrap_in_promise = False )
662
+ middlewares_without_promise = MiddlewareManager (
663
+ MyEmptyMiddleware (), wrap_in_promise = False )
664
+
665
+ result1 = execute (GraphQLSchema (Type ), doc_ast , Data (),
666
+ middleware = middlewares_with_promise )
667
+ result2 = execute (GraphQLSchema (Type ), doc_ast , Data (),
668
+ middleware = middlewares_without_promise )
669
+ assert result1 .data == result2 .data and result1 .data == {
670
+ 'ok' : 'ok' , 'not_ok' : 'not_ok' }
0 commit comments