tfoxy / graphene-django-optimizer

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

Version 0.9.0 raises ImportError #74

Open crazyscientist opened 3 years ago

crazyscientist commented 3 years ago

When using these packages:

Package                        Version
------------------------------ ----------
graphene                       2.1.9
graphene-django                2.15.0
graphene-django-optimizer      0.9.0
graphql-core                   2.3.2
graphql-relay                  2.0.1

the following exception gets raised when running tests or accessing the GraphiQL interface:

Internal Server Error: /graphql/
Traceback (most recent call last):
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphene_django/settings.py", line 80, in import_from_string
    module = importlib.import_module(module_path)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/andi/workspace/smelt/smelt/smelt/schema.py", line 7, in <module>
    from smeltapp import schema
  File "/home/andi/workspace/smelt/smelt/smeltapp/schema.py", line 16, in <module>
    from graphene_django_optimizer import query, OptimizedDjangoObjectType, resolver_hints
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphene_django_optimizer/__init__.py", line 2, in <module>
    from .query import query  # noqa: F401
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphene_django_optimizer/query.py", line 11, in <module>
    from graphql import GraphQLResolveInfo, GraphQLSchema
ImportError: cannot import name 'GraphQLResolveInfo' from 'graphql' (/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphql/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/django/views/generic/base.py", line 62, in view
    self = cls(**initkwargs)
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphene_django/views.py", line 104, in __init__
    schema = graphene_settings.SCHEMA
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphene_django/settings.py", line 127, in __getattr__
    val = perform_import(val, attr)
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphene_django/settings.py", line 66, in perform_import
    return import_from_string(val, setting_name)
  File "/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphene_django/settings.py", line 89, in import_from_string
    raise ImportError(msg)
ImportError: Could not import 'smelt.schema.schema' for Graphene setting 'SCHEMA'. ImportError: cannot import name 'GraphQLResolveInfo' from 'graphql' (/home/andi/virtualenvs/smelt/lib/python3.8/site-packages/graphql/__init__.py).

With version 0.8.0 this exception does not get raised.

sandnima commented 3 years ago

Have the same problem

KristobalJunta commented 3 years ago

Seems like it was caused by adding support for GraphQL Core 3. See https://github.com/tfoxy/graphene-django-optimizer/commit/e5c57fc8e15691d37efde2af60f70e9e787e4344

Unfortunately, v0.9.0 wasn't marked as breaking changes for some reason...

tfoxy commented 3 years ago

Thanks for bringing this up. As @KristobalJunta said, the breaking change was brought by adding support for GraphQL Core 3. Will add a message to the readme so people are aware of this.

tfoxy commented 3 years ago

Added note to readme. If someone knows a way to warn about version incompatibility with pip, please let me know. Will leave this issue open so that people can find it easier.

crazyscientist commented 3 years ago

If someone knows a way to warn about version incompatibility with pip

I'm not aware of such a feature in pip. But you could use Python's warning module to generate a warning at runtime :thinking:

daniel-skale commented 3 years ago

On the same boat using graphene-django==2.15.0 but with no graphene and currently using graphene-django-optimizer==0.6.2. Should the move be to scrap graphene-django (updates are too slow) and just use graphene v3 with graphene-django-optimizer==0.9.0?