带中继的Django-Graphene要求获得一个对象需要ID,我想在Node上使required = False,因此我可以由登录用户而不是用户ID来获得节点
class Customer(models.Model):
user = models.OneToOneField(User)
class CustomerNode(DjangoObjectType):
class Meta:
model = Customer
interfaces = (graphene.relay.Node,)
@classmethod
@login_required
def get_queryset(cls, queryset, info): # This should work
return queryset.get(user=info.context.user)
class Query(graphene.ObjectType):
customer = graphene.relay.Node.Field(CustomerNode)
all_customers = DjangoFilterConnectionField(CustomerNode)
query getCustomer {
customer(id: "XXX") { # I don't want to pass this parameter!
id
}
}
如果我不传递任何参数,这是错误:
"message": "Field \"customer\" argument \"id\" of type \"ID!\" is required but not provided."