Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing model_fields across relationship boundaries #60

Open
qeternity opened this issue Jan 24, 2021 · 1 comment
Open

Optimizing model_fields across relationship boundaries #60

qeternity opened this issue Jan 24, 2021 · 1 comment

Comments

@qeternity
Copy link

qeternity commented Jan 24, 2021

It doesn't seem possible from a cursory glance of the code, and I haven't spent enough time to see if it's an easy patch so I figured I'd ask the experts here first.

Is it possible to optimize across model relationship boundaries, for instance let's presume we wanted to make some things available at the top level resolver to avoid lots of nesting (the pseudo example below is not a particularly good one, but the question still stands):

class OrganizationType:
    def resolve_parent_organization(root, info):
        return root.parent_organization
    def resolve_accounts(root, info):
        return root.accounts.all()

class UserType:
@gql_optimizer.resolver_hints(model_field="organization__parent_organization")
    def resolve_parent_organization(root, info):
        return root.organization.parent_organization

and then we'd like to be able to optimize queries according to a pattern such as this:

user {
    parentOrganization {
        accounts
    }
}

The hacky approach we're taking at the moment is to prefetch downstream data when we access the parentOrganization resolver because this is ultimately better than N+1 queries but it still results in lots of overfetching. For instance, let's say that instead of accounts we only want the parentOrganization name.

@olidacombe
Copy link

I've been working o functionality to this end, see master...olidacombe:deep_model_field_hint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants