Skip to content

Commit 17bde14

Browse files
author
Thomas Leonard
committed
feat: enable to use a _resolve_reference method name
1 parent ec4506e commit 17bde14

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ At the moment it supports:
3131

3232
Each type which is decorated with `@key` or `@extend` is added to the `_Entity` union.
3333
The [`__resolve_reference` method](https://www.apollographql.com/docs/federation/api/apollo-federation/#__resolvereference) can be defined for each type that is an entity.
34+
Note that since the notation with double underscores can be problematic in Python for model inheritance this resolver method can also be named `_resolve_reference` (the `__resolve_reference` method will take precedence if both are declared).
35+
3436
This method is called whenever an entity is requested as part of the fulfilling a query plan.
3537
If not explicitly defined, the default resolver is used.
3638
The default resolver just creates instance of type with passed fieldset as kwargs, see [`entity.get_entity_query`](graphene_federation/entity.py) for more details

graphene_federation/entity.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ def resolve_entities(self, info, representations):
6464
}
6565
model_instance = model(**model_arguments)
6666

67-
try:
68-
resolver = getattr(model, "_%s__resolve_reference" % model.__name__)
69-
except AttributeError:
70-
pass
71-
else:
67+
resolver = getattr(model, "_%s__resolve_reference" % model.__name__, None) or \
68+
getattr(model, "_resolve_reference", None)
69+
if resolver:
7270
model_instance = resolver(model_instance, info)
7371

7472
entities.append(model_instance)

0 commit comments

Comments
 (0)