Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested fields doens't work #163

Open
miliakhaled opened this issue Dec 8, 2020 · 2 comments
Open

Nested fields doens't work #163

miliakhaled opened this issue Dec 8, 2020 · 2 comments

Comments

@miliakhaled
Copy link

miliakhaled commented Dec 8, 2020

Hello
I need to create a mutation with nested fields and i couldn't find any example to follow, so my code is :

class CharteredLivraisonMutation(CustomDjangoSerializerMutation):
    class Meta:
        serializer_class = serializers.CharteredLivraisonSerializer
        nested_fields = ("ressources", )

When i run this mutation, i get the following error:

{
          "field": "ressources",
          "messages": [
            "Incorrect type. Expected pk value, received GenericInputType."
          ]
        }

I debugged the code a little bit, I found that the type of the nested_fields must be a dict,
so i tried a dict {"ressources":?????} but whatever i wrote as a value for ressources (serializer model, graphql types, django model ...) , it does not work.

@miliakhaled
Copy link
Author

miliakhaled commented Dec 9, 2020

Hello, I'm sorry i found the solution.
for those who encountered this problem, the solution is passing the serializer that matchs the nested fields.

class AffretementRessourcesSerializer(serializers.ModelSerializer):
	class Meta:
		model = models.AffretementRessources
		fields = '__all__'

class CharteredLivraisonMutation(CustomDjangoSerializerMutation):
    class Meta:
        serializer_class = serializers.CharteredLivraisonSerializer
        nested_fields = {"ressources": AffretementRessourcesSerializer}

@briggySmalls
Copy link

Just as a reference to anyone else encountering a similar issue. I too had this issue, whilst using the DjangoInputObjectType (rather than using DRF serializers).

I had specified a field inside nested_fields but never defined a subclass of DjangoInputObjectType that would be used for populating that model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants