Skip to content

Commit e897efb

Browse files
committed
Added test for with_context on connectionfield
1 parent 7a5ad21 commit e897efb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

graphene/relay/tests/test_query.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,58 @@ class Query(graphene.ObjectType):
3636
special_node = relay.NodeField(SpecialNode)
3737
all_my_nodes = relay.ConnectionField(
3838
MyNode, connection_type=MyConnection, customArg=graphene.String())
39+
40+
context_nodes = relay.ConnectionField(
41+
MyNode, connection_type=MyConnection, customArg=graphene.String())
3942

4043
def resolve_all_my_nodes(self, args, info):
4144
custom_arg = args.get('customArg')
4245
assert custom_arg == "1"
4346
return [MyNode(name='my')]
47+
48+
@with_context
49+
def resolve_context_nodes(self, args, context, info):
50+
custom_arg = args.get('customArg')
51+
assert custom_arg == "1"
52+
return [MyNode(name='my')]
4453

4554
schema.query = Query
4655

4756

4857
def test_nodefield_query():
58+
query = '''
59+
query RebelsShipsQuery {
60+
contextNodes (customArg:"1") {
61+
edges {
62+
node {
63+
name
64+
}
65+
},
66+
myCustomField
67+
pageInfo {
68+
hasNextPage
69+
}
70+
}
71+
}
72+
'''
73+
expected = {
74+
'allMyNodes': {
75+
'edges': [{
76+
'node': {
77+
'name': 'my'
78+
}
79+
}],
80+
'myCustomField': 'Custom',
81+
'pageInfo': {
82+
'hasNextPage': False,
83+
}
84+
}
85+
}
86+
result = schema.execute(query)
87+
assert not result.errors
88+
assert result.data == expected
89+
90+
def test_connectionfield_context_query():
4991
query = '''
5092
query RebelsShipsQuery {
5193
myNode(id:"TXlOb2RlOjE=") {

0 commit comments

Comments
 (0)