graphql-python / graphql-python/graphene-django

Possible Id field for Connections?

Open
#1,251 0 comments 0 reactions 0 assignees View on GitHub
✨enhancement
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

Hi Folks
For caching in Apollo (at least) it needs to generate a unique identifier per object.
A connection using the FilterBackends, graphene.Connection, etc. will have a number of filtering and ordering parameters along with the first/last limit arguments. and returns only the resulting node objects and a bit of pageInfo, and those two alone wont reasonably identify the args that were provided.

So.

Im wondering...is there a moment there in Connection where I have access to the ultimate queryset and parameters so that I can produce a hash that is unique to those args and then that can be used to separate responses in the cache?

The example I have made so far was

```
class ConnectionWithCountsNonNullEdges(graphene.Connection):
id = graphene.NonNull(graphene.ID)
def resolve_id(root, info, **kwargs):
print("ID")
sql, params = root.iterable.query.sql_with_params()
print(sql)
print(params)
hash_object = hashlib.md5((sql.__str__() + params.__str__()).encode())
print(hash_object.hexdigest())
return hash_object.hexdigest()
```

Which is close! but it doesnt look like the sql includes the page boundaries and the params doesnt include the constants?

Excuse me if this is the wrong audience

Thanks
Alex Mouton

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.