tfoxy / graphene-django-optimizer

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

graphene 3.1 use 'FieldNode' instead 'str' #82

Closed Vitalick closed 1 year ago

Vitalick commented 2 years ago

Hello everyone, I got some errors when update graphene from 3.0 to 3.1.

https://github.com/tfoxy/graphene-django-optimizer/blob/474bc685e72d2f63535ee7af33555f0e8c3183d0/graphene_django_optimizer/query.py#L54 In this line we use get_field_def from https://github.com/graphql-python/graphql-core/blob/c214c1d93a78d7d1a1a0643b1f92a8bf29f4ad14/src/graphql/execution/execute.py#L1133 and now they using FieldNode instead of str.

So I did "monkey patch" for this package and replaced info.field_name to info.field_nodes[0] like this:


class MyQueryOptimizer(QueryOptimizer):

    def optimize(self, queryset):
        info = self.root_info
        field_def = get_field_def(
            info.schema,
            info.parent_type,
            info.field_nodes[0])
        store = self._optimize_gql_selections(
            self._get_type(field_def),
            info.field_nodes[0],
            # info.parent_type,
        )
        return store.optimize_queryset(queryset)

def query_opt(queryset, info, **options):
    return MyQueryOptimizer(info, **options).optimize(queryset)

graphene_django_optimizer.query = query_opt
nikolaik commented 2 years ago

graphene 3.1 pulls inn graphql-core version 3.2 which broke some of this library's usage. Made an attempt of fixing it in #83