Skip to content

Commit 7a27a9e

Browse files
committed
Fixed get_node
1 parent 3797689 commit 7a27a9e

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

graphene/relay/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def id_fetcher(self, global_id, context, info):
8080
if not is_node(object_type) or (self.field_object_type and object_type != field_object_type):
8181
return
8282

83-
return object_type.get_node(_id, info)
83+
return object_type.get_node(_id, context, info)
8484

8585
@with_context
8686
def resolver(self, instance, args, context, info):

graphene/relay/tests/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MyNode(relay.Node):
1616
name = graphene.String()
1717

1818
@classmethod
19-
def get_node(cls, id, context, info):
19+
def get_node(cls, id, info):
2020
return MyNode(id=id, name='mo')
2121

2222

graphene/relay/types.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ..core.types.argument import ArgumentsGroup
1515
from ..core.types.definitions import NonNull
1616
from ..utils import memoize
17-
from ..utils.wrap_resolver_function import wrap_resolver_function
17+
from ..utils.wrap_resolver_function import has_context
1818
from .fields import GlobalIDField
1919

2020

@@ -108,7 +108,7 @@ def construct_get_node(cls):
108108
get_node = getattr(cls, 'get_node', None)
109109
assert get_node, 'get_node classmethod not found in %s Node' % cls
110110
assert callable(get_node), 'get_node have to be callable'
111-
args = 3
111+
args = 4
112112
if isinstance(get_node, staticmethod):
113113
args -= 1
114114

@@ -120,12 +120,15 @@ def construct_get_node(cls):
120120

121121
@staticmethod
122122
@wraps(get_node)
123-
def wrapped_node(*node_args):
124-
if len(node_args) < args:
125-
node_args += (None, )
126-
return get_node(*node_args[:-1])
127-
128-
setattr(cls, 'get_node', wrapped_node)
123+
def wrapped_node(id, context=None, info=None):
124+
node_args = [id, info, context]
125+
if has_context(get_node):
126+
return get_node(*node_args[:get_node_num_args-1], context=context)
127+
if get_node_num_args-1 == 0:
128+
return get_node(id)
129+
return get_node(*node_args[:get_node_num_args-1])
130+
node_func = wrapped_node
131+
setattr(cls, 'get_node', node_func)
129132

130133
def construct(cls, *args, **kwargs):
131134
cls = super(NodeMeta, cls).construct(*args, **kwargs)

graphene/utils/wrap_resolver_function.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ def with_context(func):
66
return func
77

88

9+
def has_context(func):
10+
return getattr(func, 'with_context', None)
11+
12+
913
def wrap_resolver_function(func):
1014
@wraps(func)
1115
def inner(self, args, context, info):
12-
with_context = getattr(func, 'with_context', None)
13-
if with_context:
16+
if has_context(func):
1417
return func(self, args, context, info)
1518
# For old compatibility
1619
return func(self, args, info)

0 commit comments

Comments
 (0)