6

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?

davidism
  • 121,510
  • 29
  • 395
  • 339
orome
  • 45,163
  • 57
  • 202
  • 418
  • try upgrading Flask-GraphQL vesrion to 2.0.1 – Zalak Bhalani Dec 02 '21 at 19:27
  • @ZalakBhalani 2.0.0 is what I get with `pip install Flask-GraphQL`. In fact updating to the latest is what triggered this. – orome Dec 02 '21 at 21:16
  • @ZalakBhalani I can get 2.0.1 manually with `pip install Flask-GraphQL==2.0.1` but then I get `graphql-relay 3.1.0 requires graphql-core>=3.1 ...` and `graphene 3.0 requires graphql-core~=3.1.2 ... which is incompatible.` – orome Dec 02 '21 at 21:27
  • 1
    @ZalakBhalani Ah I see, `flask-graphql>=2.0.1` in my `requirements.txt` is the way to do it. Then `pip install -U -r requirements.txt` will install the needed versions of `graphql-core`. When was the error above introduced? – orome Dec 02 '21 at 21:35
  • @orome hi, are you solve this problem? – RoyalGoose Jan 25 '22 at 19:29
  • I got the same problem. – ABCD May 09 '22 at 03:21
  • 1
    The error can be reproduced by cloning and running the official graphql example https://github.com/graphql-python/graphene-sqlalchemy/tree/master/examples/flask_sqlalchemy as explained in the repo – Florian Metzger-Noel Oct 07 '22 at 10:20

1 Answers1

0

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
      }
    }
  }
}
Matt Kleinsmith
  • 1,017
  • 3
  • 13
  • 24