tfoxy / graphene-django-optimizer

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

Add support for skip and include directives #81

Open TurnrDev opened 2 years ago

TurnrDev commented 2 years ago

What is the possibility of adding support for skip and include directives? I found when including a field in a query but then excluding it with @include(if: false), Graphene Django Optimizer still includes it in the SQL Query:

An anonymized example:

query Thing {
  things: Things(startDate: $startDate, first: 10) {
    totalCount
    edges {
      node {
        excludedThing @include(if: false)
        }
      }
    }
  }
}

This would still put excludedThing is the SQL query

TurnrDev commented 2 years ago

After some basic exploration work, I found that we can add a check on line 167 where we check the directives and possibly don't add the field (and any children) to the SQL query if skipped.

I still need investigate is Graphene will still attempt to pull the values anyway.

tfoxy commented 2 years ago

Hi @TurnrDev! This would be a great addition. I'm not working anymore with python, but feel free to create a PR and will gladly review it so we can merge it.

As you said, it would be good to know if graphene knows supports the directives.