|
6 | 6 | from .field import Field |
7 | 7 | from .objecttype import ObjectType, ObjectTypeOptions |
8 | 8 | from .utils import yank_fields_from_attrs |
| 9 | +from .interface import Interface |
9 | 10 |
|
10 | 11 | # For static type checking with Mypy |
11 | 12 | MYPY = False |
12 | 13 | if MYPY: |
13 | 14 | from .argument import Argument # NOQA |
14 | | - from typing import Dict, Type, Callable # NOQA |
| 15 | + from typing import Dict, Type, Callable, Iterable # NOQA |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class MutationOptions(ObjectTypeOptions): |
18 | 19 | arguments = None # type: Dict[str, Argument] |
19 | 20 | output = None # type: Type[ObjectType] |
20 | 21 | resolver = None # type: Callable |
| 22 | + interfaces = () # type: Iterable[Type[Interface]] |
21 | 23 |
|
22 | 24 |
|
23 | 25 | class Mutation(ObjectType): |
@@ -58,22 +60,34 @@ class Mutation(ObjectType): |
58 | 60 | name. |
59 | 61 | description (str): Description of the GraphQL type in the schema. Defaults to class |
60 | 62 | docstring. |
61 | | - interfaces (Iterable[graphene.Interface]): NOT IMPLEMENTED (use ``output`` to define a |
62 | | - payload implementing interfaces). GraphQL interfaces to extend with the payload |
| 63 | + interfaces (Iterable[graphene.Interface]): GraphQL interfaces to extend with the payload |
63 | 64 | object. All fields from interface will be included in this object's schema. |
64 | 65 | fields (Dict[str, graphene.Field]): Dictionary of field name to Field. Not recommended to |
65 | 66 | use (prefer class attributes or ``Meta.output``). |
66 | 67 | """ |
67 | 68 |
|
68 | 69 | @classmethod |
69 | 70 | def __init_subclass_with_meta__( |
70 | | - cls, resolver=None, output=None, arguments=None, _meta=None, **options |
| 71 | + cls, |
| 72 | + interfaces=(), |
| 73 | + resolver=None, |
| 74 | + output=None, |
| 75 | + arguments=None, |
| 76 | + _meta=None, |
| 77 | + **options |
71 | 78 | ): |
72 | 79 | if not _meta: |
73 | 80 | _meta = MutationOptions(cls) |
74 | 81 |
|
75 | 82 | output = output or getattr(cls, "Output", None) |
76 | 83 | fields = {} |
| 84 | + |
| 85 | + for interface in interfaces: |
| 86 | + assert issubclass(interface, Interface), ( |
| 87 | + 'All interfaces of {} must be a subclass of Interface. Received "{}".' |
| 88 | + ).format(cls.__name__, interface) |
| 89 | + fields.update(interface._meta.fields) |
| 90 | + |
77 | 91 | if not output: |
78 | 92 | # If output is defined, we don't need to get the fields |
79 | 93 | fields = OrderedDict() |
@@ -110,6 +124,7 @@ def __init_subclass_with_meta__( |
110 | 124 | else: |
111 | 125 | _meta.fields = fields |
112 | 126 |
|
| 127 | + _meta.interfaces = interfaces |
113 | 128 | _meta.output = output |
114 | 129 | _meta.resolver = resolver |
115 | 130 | _meta.arguments = arguments |
|
0 commit comments