eamigo86 / graphene-django-extras

Extras functionalities for Graphene-Django
MIT License
417 stars 107 forks source link

Reverse foreign_key Input problem #164

Open miliakhaled opened 3 years ago

miliakhaled commented 3 years ago

Hello, I have the following code

Class OurLivraison(models.Model):
      ......
class Mouvement(models.Model):
     livraison =    livraison = models.ForeignKey("livraison.Livraison", on_delete=models.CASCADE) 

class OurLivraisonMutation(CustomDjangoSerializerMutation):
    class Meta:
        serializer_class = serializers.OurLivraisonSerializer
        nested_fields = {"mouvements": MouvementSerializer}

class MouvementSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Mouvement
        # exclude = ('livraison',)
        # fields = '__all__'
        exclude = ('livraison',)

The problem is when generating types for inputs, especially for nested fields, you have to define the the reverse relation.

mutation {
  create_ourlivraison(input: 
    {
      mouvements: [
        {
          wilaya:12,
          operation_type:CHARGEMENT
          # livraison:"1" This field should not berequired, although the create function doesn't take in consideration
        }
      ], 
    }){
    ok  
  }
}

So as you can see, The input object type force me to define the reverse foreign key 'livraison', although the result of the creation is correct, whatever value I put in 'livraison'.