1
+ import pytest
1
2
from graphql .core .type import GraphQLID , GraphQLNonNull
2
3
3
4
import graphene
@@ -15,12 +16,22 @@ class MyNode(relay.Node):
15
16
name = graphene .String ()
16
17
17
18
@classmethod
18
- def get_node (cls , id ):
19
+ def get_node (cls , id , info ):
19
20
return MyNode (id = id , name = 'mo' )
20
21
21
22
23
+ class SpecialNode (relay .Node ):
24
+ value = graphene .String ()
25
+
26
+ @classmethod
27
+ def get_node (cls , id , info ):
28
+ value = "!!!" if info .request_context .get ('is_special' ) else "???"
29
+ return SpecialNode (id = id , value = value )
30
+
31
+
22
32
class Query (graphene .ObjectType ):
23
33
my_node = relay .NodeField (MyNode )
34
+ special_node = relay .NodeField (SpecialNode )
24
35
all_my_nodes = relay .ConnectionField (
25
36
MyNode , connection_type = MyConnection , customArg = graphene .String ())
26
37
@@ -79,6 +90,28 @@ def test_nodefield_query():
79
90
assert result .data == expected
80
91
81
92
93
+ @pytest .mark .parametrize ('specialness,value' , [(True , '!!!' ), (False , '???' )])
94
+ def test_get_node_info (specialness , value ):
95
+ query = '''
96
+ query ValueQuery {
97
+ specialNode(id:"U3BlY2lhbE5vZGU6Mg==") {
98
+ id
99
+ value
100
+ }
101
+ }
102
+ '''
103
+
104
+ expected = {
105
+ 'specialNode' : {
106
+ 'id' : 'U3BlY2lhbE5vZGU6Mg==' ,
107
+ 'value' : value ,
108
+ },
109
+ }
110
+ result = schema .execute (query , request_context = {'is_special' : specialness })
111
+ assert not result .errors
112
+ assert result .data == expected
113
+
114
+
82
115
def test_nodeidfield ():
83
116
id_field = MyNode ._meta .fields_map ['id' ]
84
117
id_field_type = schema .T (id_field )
0 commit comments