|
5 | 5 | from graphene.relay import Connection, Node
|
6 | 6 | from graphene.types.objecttype import ObjectType, ObjectTypeOptions
|
7 | 7 | from graphene.types.utils import yank_fields_from_attrs
|
| 8 | +from graphene.utils.str_converters import to_snake_case |
8 | 9 |
|
9 | 10 | from graphene_mongo import MongoengineConnectionField
|
10 | 11 | from .converter import convert_mongoengine_field
|
11 | 12 | from .registry import Registry, get_global_registry
|
12 |
| -from .utils import get_model_fields, is_valid_mongoengine_model |
| 13 | +from .utils import get_model_fields, is_valid_mongoengine_model, get_query_fields |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def construct_fields(model, registry, only_fields, exclude_fields):
|
@@ -210,7 +211,15 @@ def is_type_of(cls, root, info):
|
210 | 211 |
|
211 | 212 | @classmethod
|
212 | 213 | def get_node(cls, info, id):
|
213 |
| - return cls._meta.model.objects.get(pk=id) |
| 214 | + only_fields = list() |
| 215 | + for field in cls._meta.only_fields: |
| 216 | + if field in cls._meta.model._fields_ordered: |
| 217 | + only_fields.append(field) |
| 218 | + for field in get_query_fields(info): |
| 219 | + if to_snake_case(field) in cls._meta.model._fields_ordered: |
| 220 | + only_fields.append(to_snake_case(field)) |
| 221 | + only_fields = list(set(only_fields)) |
| 222 | + return cls._meta.model.objects.no_dereference().only(*only_fields).get(pk=id) |
214 | 223 |
|
215 | 224 | def resolve_id(self, info):
|
216 | 225 | return str(self.id)
|
0 commit comments