kensho-technologies / graphql-compiler

Turn complex GraphQL queries into optimized database queries.
Apache License 2.0
553 stars 50 forks source link

Import error on Python version 3.10.X #1022

Open aakash-sahai opened 10 months ago

aakash-sahai commented 10 months ago

I am running Python 3.10.12 (on MacOS M1). Upon importing graphql_compiler, I get the following error:

Stacktrace

>>> from graphql_compiler import graphql_to_sql
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/asahai/repos/cat/.venv/lib/python3.10/site-packages/graphql_compiler/__init__.py", line 3, in <module>
    from .compiler import (  # noqa
  File "/Users/asahai/repos/cat/.venv/lib/python3.10/site-packages/graphql_compiler/compiler/__init__.py", line 2, in <module>
    from .common import (  # noqa
  File "/Users/asahai/repos/cat/.venv/lib/python3.10/site-packages/graphql_compiler/compiler/common.py", line 4, in <module>
    from . import (
  File "/Users/asahai/repos/cat/.venv/lib/python3.10/site-packages/graphql_compiler/compiler/emit_cypher.py", line 3, in <module>
    from .blocks import Fold, QueryRoot, Recurse, Traverse
  File "/Users/asahai/repos/cat/.venv/lib/python3.10/site-packages/graphql_compiler/compiler/blocks.py", line 7, in <module>
    from .helpers import (
  File "/Users/asahai/repos/cat/.venv/lib/python3.10/site-packages/graphql_compiler/compiler/helpers.py", line 4, in <module>
    from collections import Hashable, namedtuple
ImportError: cannot import name 'Hashable' from 'collections' (/opt/homebrew/Cellar/python@3.10/3.10.12_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

Steps to reproduce

from graphql_compiler import graphql_to_sql

How to fix

The Hashtable has been moved to collections.abc from Python 3.3 onwards, so the fix is to break up the above import into two imports as follows:

from collections import namedtuple
from collections.abc import Hashable

Version error is found

graphql-compiler 1.11.0

ElementalWarrior commented 8 months ago

Specify version ~2.0.0b3~ 2.0.0.dev36 will probably solve your problem. They haven't updated the default version at pypi since 2019