Lets say I got a user Type
class UserType(DjangoObjectType):
class Meta:
model = User
fields = [
"fieldA",
"fieldB",
"relationshipA",
"relationshipB"
]
And I want fieldB and relationshipB to be visible only to the owner (user).
What is the best strategy to do this?
Initially Ive created a PublicUserType excluding private fields, but quickly I realized that it might not be scalable because not only I'll have to create private representation for UserType I'll might also create private representation for any relationship (relationshipA etc), and proper resolvers, and duplicate fragments etc.
Is there a best practice here?
My solution is:
Create
decorators.pyfilesnake_to_camel_case func:
and finally on my schema file resolver:
Response should look something like that:
Now obviously this solution is super specific for my needs atm but it should be easy enough to make it more generic and scalable for any scenario.