Skip to content

Commit 7155603

Browse files
committed
Removing is_type_of from docs
1 parent 8030fea commit 7155603

File tree

1 file changed

+1
-50
lines changed

1 file changed

+1
-50
lines changed

docs/types/objecttypes.rst

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ arguments.
5757

5858
NOTE: The class resolvers in a ``ObjectType`` are treated as ``staticmethod``s
5959
always, so the first argument in the resolver: ``self`` (or ``root``) doesn't
60-
need to be an actual instance of the ``ObjectType``. In the case this happens, please
61-
overwrite the ``is_type_of`` method.
60+
need to be an actual instance of the ``ObjectType``.
6261

6362

6463
Quick example
@@ -96,54 +95,6 @@ A field could also specify a custom resolver outside the class:
9695
reverse = graphene.String(word=graphene.String(), resolver=reverse)
9796
9897
99-
Is Type Of
100-
----------
101-
102-
An ``ObjectType`` could be resolved within a object that is not an instance of this
103-
``ObjectType``. That means that the resolver of a ``Field`` could return any object.
104-
105-
Let's see an example:
106-
107-
.. code:: python
108-
109-
import graphene
110-
111-
class Ship:
112-
def __init__(self, name):
113-
self.name = name
114-
115-
class ShipType(graphene.ObjectType):
116-
name = graphene.String(description="Ship name", required=True)
117-
118-
@resolve_only_args
119-
def resolve_name(self):
120-
# Here self will be the Ship instance returned in resolve_ship
121-
return self.name
122-
123-
class Query(graphene.ObjectType):
124-
ship = graphene.Field(ShipType)
125-
126-
def resolve_ship(self, context, args, info):
127-
return Ship(name='xwing')
128-
129-
schema = graphene.Schema(query=Query)
130-
131-
132-
In this example, we are returning a ``Ship`` which is not an instance of ``ShipType``.
133-
If we execute a query on the ship, we would see this error:
134-
`"Expected value of type \"ShipType\" but got: instance."`
135-
136-
That's happening because GraphQL have no idea what type ``Ship`` is. For solving this,
137-
we only have to add a ``is_type_of`` method in ``ShipType``
138-
139-
.. code:: python
140-
141-
class ShipType(graphene.ObjectType):
142-
@classmethod
143-
def is_type_of(cls, root, context, info):
144-
return isinstance(root, (Ship, ShipType))
145-
146-
14798
Instances as data containers
14899
----------------------------
149100

0 commit comments

Comments
 (0)