mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Added test for with_context on connectionfield
This commit is contained in:
parent
7a5ad21b98
commit
e897efb79f
|
@ -36,16 +36,58 @@ class Query(graphene.ObjectType):
|
||||||
special_node = relay.NodeField(SpecialNode)
|
special_node = relay.NodeField(SpecialNode)
|
||||||
all_my_nodes = relay.ConnectionField(
|
all_my_nodes = relay.ConnectionField(
|
||||||
MyNode, connection_type=MyConnection, customArg=graphene.String())
|
MyNode, connection_type=MyConnection, customArg=graphene.String())
|
||||||
|
|
||||||
|
context_nodes = relay.ConnectionField(
|
||||||
|
MyNode, connection_type=MyConnection, customArg=graphene.String())
|
||||||
|
|
||||||
def resolve_all_my_nodes(self, args, info):
|
def resolve_all_my_nodes(self, args, info):
|
||||||
custom_arg = args.get('customArg')
|
custom_arg = args.get('customArg')
|
||||||
assert custom_arg == "1"
|
assert custom_arg == "1"
|
||||||
return [MyNode(name='my')]
|
return [MyNode(name='my')]
|
||||||
|
|
||||||
|
@with_context
|
||||||
|
def resolve_context_nodes(self, args, context, info):
|
||||||
|
custom_arg = args.get('customArg')
|
||||||
|
assert custom_arg == "1"
|
||||||
|
return [MyNode(name='my')]
|
||||||
|
|
||||||
schema.query = Query
|
schema.query = Query
|
||||||
|
|
||||||
|
|
||||||
def test_nodefield_query():
|
def test_nodefield_query():
|
||||||
|
query = '''
|
||||||
|
query RebelsShipsQuery {
|
||||||
|
contextNodes (customArg:"1") {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
},
|
||||||
|
myCustomField
|
||||||
|
pageInfo {
|
||||||
|
hasNextPage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
expected = {
|
||||||
|
'allMyNodes': {
|
||||||
|
'edges': [{
|
||||||
|
'node': {
|
||||||
|
'name': 'my'
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
'myCustomField': 'Custom',
|
||||||
|
'pageInfo': {
|
||||||
|
'hasNextPage': False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = schema.execute(query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == expected
|
||||||
|
|
||||||
|
def test_connectionfield_context_query():
|
||||||
query = '''
|
query = '''
|
||||||
query RebelsShipsQuery {
|
query RebelsShipsQuery {
|
||||||
myNode(id:"TXlOb2RlOjE=") {
|
myNode(id:"TXlOb2RlOjE=") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user