@@ -57,8 +57,8 @@ so the first argument to the resolver method ``self`` (or ``root``) need
57
57
not be an actual instance of the ``ObjectType ``.
58
58
59
59
If an explicit resolver is not defined on the ``ObjectType `` then Graphene will
60
- attempt to use a property with the same name on the object that is passed to the
61
- ``ObjectType ``.
60
+ attempt to use a property with the same name on the object or dict that is
61
+ passed to the ``ObjectType ``.
62
62
63
63
.. code :: python
64
64
@@ -70,53 +70,17 @@ attempt to use a property with the same name on the object that is passed to the
70
70
71
71
class Query (graphene .ObjectType ):
72
72
me = graphene.Field(Person)
73
+ best_friend = graphene.Field(Person)
73
74
74
75
def resolve_me (_ , info ):
75
76
# returns an object that represents a Person
76
77
return get_human(name = ' Luke Skywalker' )
77
78
78
- If you are passing a dict instead of an object to your ``ObjectType `` you can
79
- change the default resolver in the ``Meta `` class like this:
80
-
81
- .. code :: python
82
-
83
- import graphene
84
- from graphene.types.resolver import dict_resolver
85
-
86
- class Person (graphene .ObjectType ):
87
- class Meta :
88
- default_resolver = dict_resolver
89
-
90
- first_name = graphene.String()
91
- last_name = graphene.String()
92
-
93
- class Query (graphene .ObjectType ):
94
- me = graphene.Field(Person)
95
-
96
- def resolve_me (_ , info ):
79
+ def resolve_best_friend (_ , info ):
97
80
return {
98
- " first_name" : " Luke" ,
99
- " last_name" : " Skywalker" ,
100
- }
101
-
102
- Or you can change the default resolver globally by calling ``set_default_resolver ``
103
- before executing a query.
104
-
105
- .. code :: python
106
-
107
- import graphene
108
- from graphene.types.resolver import dict_resolver, set_default_resolver
109
-
110
- set_default_resolver(dict_resolver)
111
-
112
- schema = graphene.Schema(query = Query)
113
- result = schema.execute('''
114
- query {
115
- me {
116
- firstName
81
+ " first_name" : " R2" ,
82
+ " last_name" : " D2" ,
117
83
}
118
- }
119
- ''' )
120
84
121
85
122
86
Resolvers with arguments
0 commit comments