def test_executor_can_enforce_strict_ordering():
    Type = GraphQLObjectType('Type', lambda: {
        'a': GraphQLField(GraphQLString,
                          resolver=lambda *_: succeed('Apple')),
        'b': GraphQLField(GraphQLString,
                          resolver=lambda *_: succeed('Banana')),
        'c': GraphQLField(GraphQLString,
                          resolver=lambda *_: succeed('Cherry')),
        'deep': GraphQLField(Type, resolver=lambda *_: succeed({})),
    })
    schema = GraphQLSchema(query=Type)
    executor = Executor(map_type=OrderedDict)

    query = '{ a b c aa: c cc: c bb: b aaz: a bbz: b deep { b a c deeper: deep { c a b } } ' \
            'ccz: c zzz: c aaa: a }'

    def handle_results(result):
        assert not result.errors

        data = result.data
        assert isinstance(data, OrderedDict)
        assert list(data.keys()) == ['a', 'b', 'c', 'aa', 'cc', 'bb', 'aaz', 'bbz', 'deep', 'ccz', 'zzz', 'aaa']
        deep = data['deep']
        assert isinstance(deep, OrderedDict)
        assert list(deep.keys()) == ['b', 'a', 'c', 'deeper']
        deeper = deep['deeper']
        assert isinstance(deeper, OrderedDict)
        assert list(deeper.keys()) == ['c', 'a', 'b']

    raise_callback_results(executor.execute(schema, query), handle_results)
    raise_callback_results(executor.execute(schema, query, execute_serially=True), handle_results)
def test_executor_can_enforce_strict_ordering():
    Type = GraphQLObjectType('Type', lambda: {
        'a': GraphQLField(GraphQLString,
                          resolver=lambda *_: succeed('Apple')),
        'b': GraphQLField(GraphQLString,
                          resolver=lambda *_: succeed('Banana')),
        'c': GraphQLField(GraphQLString,
                          resolver=lambda *_: succeed('Cherry')),
        'deep': GraphQLField(Type, resolver=lambda *_: succeed({})),
    })
    schema = GraphQLSchema(query=Type)
    executor = Executor(map_type=OrderedDict)

    query = '{ a b c aa: c cc: c bb: b aaz: a bbz: b deep { b a c deeper: deep { c a b } } ' \
            'ccz: c zzz: c aaa: a }'

    def handle_results(result):
        assert not result.errors

        data = result.data
        assert isinstance(data, OrderedDict)
        assert list(data.keys()) == ['a', 'b', 'c', 'aa', 'cc', 'bb', 'aaz', 'bbz', 'deep', 'ccz', 'zzz', 'aaa']
        deep = data['deep']
        assert isinstance(deep, OrderedDict)
        assert list(deep.keys()) == ['b', 'a', 'c', 'deeper']
        deeper = deep['deeper']
        assert isinstance(deeper, OrderedDict)
        assert list(deeper.keys()) == ['c', 'a', 'b']

    raise_callback_results(executor.execute(schema, query), handle_results)
    raise_callback_results(executor.execute(schema, query, execute_serially=True), handle_results)
class Test_NotNullListOfT_Array_T:  # [T]! Array<T>
    type = GraphQLNonNull(GraphQLList(GraphQLInt))

    test_contains_values = check(succeed([1, 2]),
                                 {'data': {
                                     'nest': {
                                         'test': [1, 2]
                                     }
                                 }})
    test_contains_null = check(succeed([1, None, 2]),
                               {'data': {
                                   'nest': {
                                       'test': [1, None, 2]
                                   }
                               }})
    test_returns_null = check(
        succeed(None), {
            'data': {
                'nest': None
            },
            'errors': [{
                'locations': [{
                    'column': 10,
                    'line': 1
                }],
                'message':
                'Cannot return null for non-nullable field DataType.test.'
            }]
        })
示例#4
0
def test_callback_result_transformation():
    d = succeed(5)
    d.add_callback(lambda r: r + 5)
    assert d.result == 10

    d.add_callback(lambda r: succeed(r + 5))

    assert d.result == 15
def test_callback_result_transformation():
    d = succeed(5)
    d.add_callback(lambda r: r + 5)
    assert d.result == 10

    d.add_callback(lambda r: succeed(r + 5))

    assert d.result == 15
def test_deferred_list_with_already_resolved_deferred_values():
    dl = DeferredList([
        1,
        succeed(2),
        succeed(3)
    ])

    assert dl.called
    assert dl.result == [1, 2, 3]
def test_nested_succeed():
    d = succeed(succeed('123'))
    assert d.result == "123"
    assert d.called
    assert not d.callbacks

    d = succeed(succeed(succeed('123')))
    assert d.result == "123"
    assert d.called
    assert not d.callbacks
示例#8
0
def test_nested_succeed():
    d = succeed(succeed('123'))
    assert d.result == "123"
    assert d.called
    assert not d.callbacks

    d = succeed(succeed(succeed('123')))
    assert d.result == "123"
    assert d.called
    assert not d.callbacks
class TestNotNullListOfNotNullT_Promise_Array_T:  # [T!]! Promise<Array<T>>
    type = GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLInt)))

    test_contains_value = check(succeed([1, 2]),
                                {'data': {
                                    'nest': {
                                        'test': [1, 2]
                                    }
                                }})
    test_contains_null = check(
        succeed([1, None, 2]), {
            'data': {
                'nest': None
            },
            'errors': [{
                'locations': [{
                    'column': 10,
                    'line': 1
                }],
                'message':
                'Cannot return null for non-nullable field DataType.test.'
            }]
        })

    test_returns_null = check(
        succeed(None), {
            'data': {
                'nest': None
            },
            'errors': [{
                'locations': [{
                    'column': 10,
                    'line': 1
                }],
                'message':
                'Cannot return null for non-nullable field DataType.test.'
            }]
        })

    test_rejected = check(
        lambda: fail(Exception('bad')), {
            'data': {
                'nest': None
            },
            'errors': [{
                'locations': [{
                    'column': 10,
                    'line': 1
                }],
                'message': 'bad'
            }]
        })
    class DeepData(object):
        a = 'Already Been Done'
        b = 'Boring'
        c = ['Contrived', None, succeed('Confusing')]

        def deeper(self):
            return [Data(), None, succeed(Data())]
class Test_ListOfT_Array_Promise_T:  # [T] Array<Promise<T>>
    type = GraphQLList(GraphQLInt)

    test_contains_values = check([succeed(1), succeed(2)],
                                 {'data': {
                                     'nest': {
                                         'test': [1, 2]
                                     }
                                 }})
    test_contains_null = check(
        [succeed(1), succeed(None), succeed(2)],
        {'data': {
            'nest': {
                'test': [1, None, 2]
            }
        }})
    test_contains_reject = check(
        lambda: [succeed(1), fail(Exception('bad')),
                 succeed(2)], {
                     'data': {
                         'nest': {
                             'test': [1, None, 2]
                         }
                     },
                     'errors': [{
                         'locations': [{
                             'column': 10,
                             'line': 1
                         }],
                         'message': 'bad'
                     }]
                 })
示例#12
0
def test_deferred_callback_returns_another_deferred():
    d = Deferred()
    d2 = Deferred()

    d.add_callback(lambda r: succeed(r + 5).add_callback(lambda v: v + 5))
    d.add_callback(lambda r: d2)
    d.callback(5)

    assert d.result is d2
    assert d.paused
    assert d.called

    d2.callback(7)
    assert d.result == 7
    assert d2.result == 7
def test_deferred_callback_returns_another_deferred():
    d = Deferred()
    d2 = Deferred()

    d.add_callback(lambda r: succeed(r + 5).add_callback(lambda v: v + 5))
    d.add_callback(lambda r: d2)
    d.callback(5)

    assert d.result is d2
    assert d.paused
    assert d.called

    d2.callback(7)
    assert d.result == 7
    assert d2.result == 7
class Test_ListOfT_Promise_Array_T:  # [T] Promise<Array<T>>
    type = GraphQLList(GraphQLInt)

    test_contains_values = check(succeed([1, 2]),
                                 {'data': {
                                     'nest': {
                                         'test': [1, 2]
                                     }
                                 }})
    test_contains_null = check(succeed([1, None, 2]),
                               {'data': {
                                   'nest': {
                                       'test': [1, None, 2]
                                   }
                               }})
    test_returns_null = check(succeed(None),
                              {'data': {
                                  'nest': {
                                      'test': None
                                  }
                              }})
    test_rejected = check(
        lambda: fail(Exception('bad')), {
            'data': {
                'nest': {
                    'test': None
                }
            },
            'errors': [{
                'locations': [{
                    'column': 10,
                    'line': 1
                }],
                'message': 'bad'
            }]
        })
示例#15
0
def test_deferred_list_fails():
    d1 = Deferred()
    d2 = Deferred()
    d3 = Deferred()

    dl = DeferredList([1, succeed(2), d1, d2, d3])

    assert not dl.called

    e1 = Exception('d1 failed')
    d1.errback(e1)
    d2.errback(Exception('d2 failed'))
    d3.callback('hello')

    assert dl.called
    assert isinstance(dl.result, DeferredException)
    assert dl.result.value == e1
class TestListOfNotNullT_Array_Promise_T:  # [T!] Array<Promise<T>>
    type = GraphQLList(GraphQLNonNull(GraphQLInt))

    test_contains_values = check([succeed(1), succeed(2)],
                                 {'data': {
                                     'nest': {
                                         'test': [1, 2]
                                     }
                                 }})
    test_contains_null = check(
        [succeed(1), succeed(None), succeed(2)], {
            'data': {
                'nest': {
                    'test': None
                }
            },
            'errors': [{
                'locations': [{
                    'column': 10,
                    'line': 1
                }],
                'message':
                'Cannot return null for non-nullable field DataType.test.'
            }]
        })
    test_contains_reject = check(
        lambda: [succeed(1), fail(Exception('bad')),
                 succeed(2)], {
                     'data': {
                         'nest': {
                             'test': None
                         }
                     },
                     'errors': [{
                         'locations': [{
                             'column': 10,
                             'line': 1
                         }],
                         'message': 'bad'
                     }]
                 })
def test_deferred_list_fails():
    d1 = Deferred()
    d2 = Deferred()
    d3 = Deferred()

    dl = DeferredList([
        1,
        succeed(2),
        d1,
        d2,
        d3
    ])

    assert not dl.called

    e1 = Exception('d1 failed')
    d1.errback(e1)
    d2.errback(Exception('d2 failed'))
    d3.callback('hello')

    assert dl.called
    assert isinstance(dl.result, DeferredException)
    assert dl.result.value == e1
 def promise(self):
     return succeed('i shouldn\'nt work')
 def nonNullPromiseNest(self):
     return succeed(NullingData())
 def async (self):
     return succeed('async')
示例#21
0
 def promise(self):
     return succeed(None)
示例#22
0
def test_succeed():
    d = succeed("123")
    assert d.result == "123"
    assert d.called
    assert not d.callbacks
 def f(self):
     return succeed('Fish')
 def promise(self):
     return succeed(None)
def test_succeed():
    d = succeed("123")
    assert d.result == "123"
    assert d.called
    assert not d.callbacks
 def deeper(self):
     return [Data(), None, succeed(Data())]
 def pic(self, size=50):
     return succeed('Pic of size: {}'.format(size))
 def asyncReturnError(self):
     return succeed(Exception('Error getting asyncReturnError'))
示例#29
0
def test_deferred_list_with_already_resolved_deferred_values():
    dl = DeferredList([1, succeed(2), succeed(3)])

    assert dl.called
    assert dl.result == [1, 2, 3]
示例#30
0
 def promiseNest(self):
     return succeed(ThrowingData())
 def promise(self):
     return succeed(Data())
示例#32
0
 def nonNullPromiseNest(self):
     return succeed(NullingData())
 def deeper(self):
     return [Data(), None, succeed(Data())]
 def pic(self, size=50):
     return succeed('Pic of size: {}'.format(size))
 def promise(self):
     return succeed(Data())
 def promise(self):
     return succeed('i shouldn\'nt work')
 def asyncReturnError(self):
     return succeed(Exception('Error getting asyncReturnError'))
 def f(self):
     return succeed('Fish')
 def promiseNest(self):
     return succeed(ThrowingData())