This is specifically for graphene-django (not just graphene) when performing a node(id: ...) {}
query.
Assume a fixed schema with 2 (or more) different GraphQL object types using graphene_django.DjangoObjectType
linked to the same django model:
import graphene_django
from .models import Org as OrgModel
class Org(graphene_django.DjangoObjectType):
class Meta:
model = OrgModel
fields = (
"id",
"name",
"billing"
)
class AnonymousOrg(graphene_django.DjangoObjectType):
class Meta:
model = OrgModel
fields = (
"id",
"name",
)
Let's assume a query to Org
of ID 7eca71ed-ff04-4473-9fd1-0a587705f885
.
btoa('Org:7eca71ed-ff04-4473-9fd1-0a587705f885')
'T3JnOjdlY2E3MWVkLWZmMDQtNDQ3My05ZmQxLTBhNTg3NzA1Zjg4NQ=='
{
node(id: "T3JnOjdlY2E3MWVkLWZmMDQtNDQ3My05ZmQxLTBhNTg3NzA1Zjg4NQ==") {
id
__typename
... on Org {
id
}
}
}
Return:
{
"data": {
"node": {
"id": "QW5vbnltb3VzT3JnOjdlY2E3MWVkLWZmMDQtNDQ3My05ZmQxLTBhNTg3NzA1Zjg4NQ==",
"__typename": "AnonymousOrg"
}
}
}
It returns the other object type 'AnonymousOrg:7eca71ed-ff04-4473-9fd1-0a587705f885'
, despite the relay ID specifying it was an Org
object.
Is there a way in graphene-django to "hint" or provide detail to assure the return type if what's specified in the ID and its fragment?
Clarification on question
Other questions were discussing graphene, not specifically graphene-django, which is doing the type determinations in this case.
This is different from Django-graphene multiple types for the same model, as that one asked about how to handle field permissions and opened possibility to reconsidering schema structure (e.g. splitting between Public and Private API schemas) - that isn't a choice in this question.
Credit: This is graphene django models are based on the ones from the question at Django-graphene multiple types for the same model.
P.S. I created a bug issue on the tracker here: graphene-django#1291 named "DjangoObjectType
using the same django model do not resolve to correct relay object". Supposedly this issue was resolved years ago, but communication lines got crossed.