Flask GraphQL import fails

1.8k views Asked by At

I have the package versions

...
Flask               2.0.2
Flask-GraphQL       2.0.0
Flask-Script        2.0.6
...
graphene            3.0
graphql-core        3.1.6
graphql-relay       3.1.0
graphql-server-core 1.1.1
...

and when I import flask_graphql I get

Traceback (most recent call last):
  File "/Users/Rax/Documents/Projects/Web/Sites/proj/_foo.py", line 1, in <module>
    import flask_graphql
  File "/Users/Rax/Documents/Projects/Coding/Python/venvs/proj/lib/python3.9/site-packages/flask_graphql/__init__.py", line 1, in <module>
    from .blueprint import GraphQL
  File "/Users/Rax/Documents/Projects/Coding/Python/venvs/proj/lib/python3.9/site-packages/flask_graphql/blueprint.py", line 5, in <module>
    from .graphqlview import GraphQLView
  File "/Users/Rax/Documents/Projects/Coding/Python/venvs/proj/lib/python3.9/site-packages/flask_graphql/graphqlview.py", line 7, in <module>
    from graphql_server import (HttpQueryError, default_format_error,
  File "/Users/Rax/Documents/Projects/Coding/Python/venvs/proj/lib/python3.9/site-packages/graphql_server/__init__.py", line 5, in <module>
    from graphql import get_default_backend
ImportError: cannot import name 'get_default_backend' from 'graphql' (/Users/Rax/Documents/Projects/Coding/Python/venvs/proj/lib/python3.9/site-packages/graphql/__init__.py)

How do I avoid this error. Are there different versions or version ranges I should be requiring?

1

There are 1 answers

0
Matt Kleinsmith On

An option: Downgrade.

Cost: Losing new features.

How: Pin these packages to these versions:

flask-graphql==2.0.1
graphene==2.1.9
graphene-sqlalchemy==2.3.0

See GitHub issue: https://github.com/graphql-python/graphene-sqlalchemy/issues/380


Note: If you're trying to get the Flask example to work, replace the entire contents of graphene-sqlalchemy/examples/flask_sqlalchemy/requirements.txt with the above text.

You can test that the Flask example works with this query:

{
  allEmployees {
    edges {
      node {
        name
      }
    }
  }
}