Skip to content

Commit 21cccf4

Browse files
jkimboekampf
authored andcommitted
Update object type docs (#921)
Now that the default resolver handles both objects and dicts
1 parent 0805436 commit 21cccf4

File tree

1 file changed

+6
-42
lines changed

1 file changed

+6
-42
lines changed

docs/types/objecttypes.rst

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ so the first argument to the resolver method ``self`` (or ``root``) need
5757
not be an actual instance of the ``ObjectType``.
5858

5959
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``.
6262

6363
.. code:: python
6464
@@ -70,53 +70,17 @@ attempt to use a property with the same name on the object that is passed to the
7070
7171
class Query(graphene.ObjectType):
7272
me = graphene.Field(Person)
73+
best_friend = graphene.Field(Person)
7374
7475
def resolve_me(_, info):
7576
# returns an object that represents a Person
7677
return get_human(name='Luke Skywalker')
7778
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):
9780
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",
11783
}
118-
}
119-
''')
12084
12185
12286
Resolvers with arguments

0 commit comments

Comments
 (0)