tfoxy / graphene-django-optimizer

Optimize database access inside graphene queries
MIT License
428 stars 84 forks source link

The optimizer should optimize the query when using GlobalID #8

Closed hilmarhausmart closed 5 years ago

hilmarhausmart commented 5 years ago

The optimizer should optimize the query when using GlobalID from Relay.

The current behavior is to jump to abort_only_optimization because the ID resolver is a partial function from GlobalID.id_resolver instead of the expected DjangoObjectType.resolve_id. Changed the behavior to also allow for GlobalID.

The optimizer should defer the correct fields when using a CustomID with resolve_id

When using a custom id (for instance an uuid) from resolve_id the query would be optimized with incorrect only fields since id was hardcoded. Changed the behavior of QueryOptimizer to allow for a custom id_field in the constructor. Also added an export for QueryOptimizer to allow query to remain simple.

Added tests for both scenarios.

When passed an empty select_related list, a queryset will select all related fields

https://github.com/django/django/blob/2.1.3/django/db/models/query.py#L949

Added a condition for select_related and prefetch_related

codecov-io commented 5 years ago

Codecov Report

Merging #8 into master will increase coverage by 0.09%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #8      +/-   ##
==========================================
+ Coverage   97.08%   97.17%   +0.09%     
==========================================
  Files           5        5              
  Lines         274      283       +9     
==========================================
+ Hits          266      275       +9     
  Misses          8        8
Impacted Files Coverage Δ
graphene_django_optimizer/query.py 96.73% <100%> (+0.12%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4611fec...9af9b57. Read the comment docs.

hilmarhausmart commented 5 years ago

Aborted, will pull request more changes along with these later.