|
11 | 11 | from graphene.relay import Connection, Node
|
12 | 12 | from graphene.types.objecttype import ObjectType, ObjectTypeOptions
|
13 | 13 | from graphene.types.utils import yank_fields_from_attrs
|
| 14 | +from graphene.utils.orderedtype import OrderedType |
14 | 15 |
|
15 | 16 | from .converter import (convert_sqlalchemy_column,
|
16 | 17 | convert_sqlalchemy_composite,
|
|
23 | 24 | from .utils import get_query, is_mapped_class, is_mapped_instance
|
24 | 25 |
|
25 | 26 |
|
26 |
| -class ORMField(object): |
| 27 | +class ORMField(OrderedType): |
27 | 28 | def __init__(
|
28 | 29 | self,
|
29 | 30 | type=None,
|
30 | 31 | prop_name=None,
|
31 | 32 | description=None,
|
32 | 33 | deprecation_reason=None,
|
33 | 34 | required=None,
|
| 35 | + _creation_counter=None, |
34 | 36 | **field_kwargs
|
35 | 37 | ):
|
| 38 | + super(ORMField, self).__init__(_creation_counter=_creation_counter) |
36 | 39 | # The is only useful for documentation and auto-completion
|
37 | 40 | common_kwargs = {
|
38 | 41 | 'type': type,
|
@@ -65,18 +68,19 @@ def construct_fields(
|
65 | 68 | auto_orm_field_names.append(prop_name)
|
66 | 69 |
|
67 | 70 | # TODO Get ORMField fields defined on parent classes
|
68 |
| - custom_orm_fields = OrderedDict() |
| 71 | + custom_orm_fields_items = [] |
69 | 72 | for attname, value in list(obj_type.__dict__.items()):
|
70 | 73 | if isinstance(value, ORMField):
|
71 |
| - custom_orm_fields[attname] = value |
| 74 | + custom_orm_fields_items.append((attname, value)) |
| 75 | + custom_orm_fields_items = sorted(custom_orm_fields_items, key=lambda item: item[1]) |
72 | 76 |
|
73 |
| - for orm_field_name, orm_field in custom_orm_fields.items(): |
| 77 | + for orm_field_name, orm_field in custom_orm_fields_items: |
74 | 78 | prop_name = orm_field.kwargs.get('prop_name', orm_field_name)
|
75 | 79 | if prop_name not in all_model_props:
|
76 | 80 | raise Exception('Cannot map ORMField "{}" to SQLAlchemy model property'.format(orm_field_name))
|
77 | 81 | orm_field.kwargs['prop_name'] = prop_name
|
78 | 82 |
|
79 |
| - orm_fields = custom_orm_fields.copy() |
| 83 | + orm_fields = OrderedDict(custom_orm_fields_items) |
80 | 84 | for orm_field_name in auto_orm_field_names:
|
81 | 85 | if orm_field_name in orm_fields:
|
82 | 86 | continue
|
@@ -159,6 +163,7 @@ def __init_subclass_with_meta__(
|
159 | 163 | connection_field_factory=connection_field_factory,
|
160 | 164 | ),
|
161 | 165 | _as=Field,
|
| 166 | + sort=False, |
162 | 167 | )
|
163 | 168 |
|
164 | 169 | if use_connection is None and interfaces:
|
|
0 commit comments