Revert field resolver logic to fix poor query performance by sjdemartini · Pull Request #1401 · graphql-python/graphene-django (original) (raw)

Thanks for the stamp firaskafri!

I've also just added a new unit-test that validates select_related and prefetch_related query-optimizations are respected in resolver code, which should help ensure that if/when we add back functionality like the CustomField resolver being reverted here, it is still performant.

For instance, adding back the resolver code now gives a test failure showing:

Failed: Expected to perform 2 queries but 11 were done

Queries:
========
SELECT "tests_article"."id", "tests_article"."headline", "tests_article"."pub_date", "tests_article"."pub_date_time", "tests_article"."reporter_id", "tests_article"."editor_id", "tests_article"."lang", "tests_article"."importance", "tests_reporter"."id", "tests_reporter"."first_name", "tests_reporter"."last_name", "tests_reporter"."email", "tests_reporter"."a_choice", "tests_reporter"."reporter_type", T3."id", T3."first_name", T3."last_name", T3."email", T3."a_choice", T3."reporter_type" FROM "tests_article" INNER JOIN "tests_reporter" ON ("tests_article"."reporter_id" = "tests_reporter"."id") INNER JOIN "tests_reporter" T3 ON ("tests_article"."editor_id" = T3."id") ORDER BY "tests_article"."headline" ASC
SELECT ("tests_film_reporters"."reporter_id") AS "_prefetch_related_val_reporter_id", "tests_film"."id", "tests_film"."genre", "tests_filmdetails"."id", "tests_filmdetails"."location", "tests_filmdetails"."film_id" FROM "tests_film" INNER JOIN "tests_film_reporters" ON ("tests_film"."id" = "tests_film_reporters"."film_id") LEFT OUTER JOIN "tests_filmdetails" ON ("tests_film"."id" = "tests_filmdetails"."film_id") WHERE "tests_film_reporters"."reporter_id" IN (1, 2)
SELECT "tests_reporter"."id", "tests_reporter"."first_name", "tests_reporter"."last_name", "tests_reporter"."email", "tests_reporter"."a_choice", "tests_reporter"."reporter_type" FROM "tests_reporter" WHERE "tests_reporter"."id" = 2 LIMIT 21
...