tfoxy / graphene-django-optimizer

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

Fix Relay Connection ID #56

Closed iorlandini closed 4 years ago

iorlandini commented 4 years ago

The issue

The only optimization is being aborted when using the GlobalID as expected in Relay.

Example

Given:

from django.db import models
from graphene import relay
from graphene_django_optimizer import OptimizedDjangoObjectType

class Customer(models.Model):
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)

class CustomerType(OptimizedDjangoObjectType):
    class Meta:
        model = Customer
        name = "Customer"
        interfaces = (relay.Node,)

class Query(graphene.ObjectType):
    customers = OptimizedConnectionField(CustomerType)

And performing:

{
    customers {
        edges {
            node {
                id
            }
        }
    }
}

The following query is executed:

SELECT
    "customer_customer"."id",
    "customer_customer"."first_name",
    "customer_customer"."last_name",
FROM
    "customer_customer";

Expected:

SELECT
    "customer_customer"."id"
FROM
    "customer_customer";
codecov-commenter commented 4 years ago

Codecov Report

Merging #56 into master will increase coverage by 0.03%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #56      +/-   ##
==========================================
+ Coverage   93.73%   93.76%   +0.03%     
==========================================
  Files           6        6              
  Lines         319      321       +2     
==========================================
+ Hits          299      301       +2     
  Misses         20       20              
Impacted Files Coverage Δ
graphene_django_optimizer/query.py 92.27% <100.00%> (+0.06%) :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 760676e...5ff4689. Read the comment docs.

iorlandini commented 4 years ago

Hi @tfoxy, any chance to get this reviewed?

tfoxy commented 4 years ago

Thanks for taking time for this. v0.7.1 released with this fix! Sorry it took so long.

iorlandini commented 4 years ago

Thanks for taking time for this. v0.7.1 released with this fix! Sorry it took so long.

Do not worry about the delayed answer, also, thank you for writing the module in the first place. Anyway, I have been using my own fork.

On the other hand, I created another PR to fix another issue https://github.com/tfoxy/graphene-django-optimizer/pull/57. Again, I'm using it from my own fork. But I think it would be good to fix it in this repository as well.