2016-09-12 07:47:34 +03:00
|
|
|
AbstractTypes
|
|
|
|
=============
|
|
|
|
|
2016-10-07 11:56:01 +03:00
|
|
|
An AbstractType contains fields that can be shared among
|
2016-09-12 07:47:34 +03:00
|
|
|
``graphene.ObjectType``, ``graphene.Interface``,
|
|
|
|
``graphene.InputObjectType`` or other ``graphene.AbstractType``.
|
|
|
|
|
|
|
|
The basics:
|
|
|
|
|
|
|
|
- Each AbstractType is a Python class that inherits from ``graphene.AbstractType``.
|
2016-10-07 11:56:01 +03:00
|
|
|
- Each attribute of the AbstractType represents a field (a ``graphene.Field`` or
|
|
|
|
``graphene.InputField`` depending on where it is mounted)
|
2016-09-12 07:47:34 +03:00
|
|
|
|
|
|
|
Quick example
|
|
|
|
-------------
|
|
|
|
|
|
|
|
In this example UserFields is an ``AbstractType`` with a name. ``User`` and
|
2016-10-07 11:56:01 +03:00
|
|
|
``UserInput`` are two types that have their own fields
|
2016-09-12 07:47:34 +03:00
|
|
|
plus the ones defined in ``UserFields``.
|
|
|
|
|
|
|
|
.. code:: python
|
|
|
|
|
|
|
|
import graphene
|
|
|
|
|
|
|
|
class UserFields(graphene.AbstractType):
|
|
|
|
name = graphene.String()
|
|
|
|
|
|
|
|
class User(graphene.ObjectType, UserFields):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class UserInput(graphene.InputObjectType, UserFields):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-09-25 15:01:12 +03:00
|
|
|
.. code::
|
2016-09-12 07:47:34 +03:00
|
|
|
|
|
|
|
type User {
|
|
|
|
name: String
|
|
|
|
}
|
|
|
|
|
|
|
|
inputtype UserInput {
|
|
|
|
name: String
|
|
|
|
}
|