mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-23 15:10:48 +03:00
Added test for sliced list support
This commit is contained in:
parent
40705d3924
commit
6734a603f2
|
@ -40,6 +40,8 @@ class Query(graphene.ObjectType):
|
|||
context_nodes = relay.ConnectionField(
|
||||
MyNode, connection_type=MyConnection, customArg=graphene.String())
|
||||
|
||||
sliced_nodes = relay.ConnectionField(MyNode)
|
||||
|
||||
def resolve_all_my_nodes(self, args, info):
|
||||
custom_arg = args.get('customArg')
|
||||
assert custom_arg == "1"
|
||||
|
@ -51,6 +53,11 @@ class Query(graphene.ObjectType):
|
|||
assert custom_arg == "1"
|
||||
return [MyNode(name='my')]
|
||||
|
||||
def resolve_sliced_nodes(self, args, info):
|
||||
sliced_list = [MyNode(name='my1'), MyNode(name='my2'), MyNode(name='my3')]
|
||||
total_count = 10
|
||||
return Connection.for_node(MyNode).from_list(sliced_list, args, None, info, total_count)
|
||||
|
||||
schema.query = Query
|
||||
|
||||
|
||||
|
@ -135,6 +142,47 @@ def test_connectionfield_context_query():
|
|||
assert result.data == expected
|
||||
|
||||
|
||||
def test_slice_connectionfield_query():
|
||||
query = '''
|
||||
query RebelsShipsQuery {
|
||||
slicedNodes (first: 3) {
|
||||
edges {
|
||||
node {
|
||||
name
|
||||
}
|
||||
},
|
||||
myCustomField
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
expected = {
|
||||
'slicedNodes': {
|
||||
'edges': [{
|
||||
'node': {
|
||||
'name': 'my1'
|
||||
}
|
||||
},{
|
||||
'node': {
|
||||
'name': 'my2'
|
||||
}
|
||||
},{
|
||||
'node': {
|
||||
'name': 'my3'
|
||||
}
|
||||
}],
|
||||
'pageInfo': {
|
||||
'hasNextPage': True,
|
||||
}
|
||||
}
|
||||
}
|
||||
result = schema.execute(query)
|
||||
assert not result.errors
|
||||
assert result.data == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('specialness,value', [(True, '!!!'), (False, '???')])
|
||||
def test_get_node_info(specialness, value):
|
||||
query = '''
|
||||
|
|
Loading…
Reference in New Issue
Block a user