Skip to content

Returning list of DjangoObjectTypes as opposed to list of Models causes client to override previous results #938

Open
@bitofbreeze

Description

@bitofbreeze

This is truly a complicated one.

I have this graphene node

class TripNode(DjangoObjectType):
    legs = List(LegNode)

    # Need explicit pk when forming TripNode manually and querying for id
    pk = String(source="id")

    class Meta:
        model = Trip
        interfaces = (relay.Node,)

The resolver fetches some remote data and resolves legs there since legs is derived from that remote data as well.

def resolve_trips(root, info, **kwargs):
        response = requests.get("")

        return [
            TripNode(
                **{
                    "id": uuid.uuid4(),
                    "origin": trip["origin"],
                    "legs": [
                        TripLeg(
                            origin_hub=leg["flyFrom"],
                            id=uuid.uuid4(),
                        )
                        for leg in trip["route"]
                    ],
                }
            )
            for trip in response.json()["data"]
        ]

Usually I would instead return a list of Trips but I can't use the Django model here because I am resolving the extra field legs that does not exist in the model. One reason it doesn't is that it must be ordered so a one-to-many field would not suffice without some addition.

If I do return a list of Trips without legs, it works fine and the client doesn't overwrite the previous query results with the new ones. But that weird overwrite behavior does occur when I use TripNode instead, and that's the only difference. Therefore I am making the issue here instead of in the client repo (relay) because I think it has to do with some graphQL standard not being respected in this case.

I'm pretty much at a loss for what's going on and would appreciate any thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions