tfoxy/graphene-django-optimizer

graphene 3.1 use 'FieldNode' instead 'str'

Closed this issue · 1 comments

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

field_def = get_field_def(info.schema, info.parent_type, info.field_name)

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

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