Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask example gives ImportError #380

Closed
MattKleinsmith opened this issue Feb 14, 2023 · 6 comments
Closed

Flask example gives ImportError #380

MattKleinsmith opened this issue Feb 14, 2023 · 6 comments

Comments

@MattKleinsmith
Copy link

MattKleinsmith commented Feb 14, 2023

Might be the only answer for now?

Approach: Downgrade.

How: Replace the entire contents of graphene-sqlalchemy/examples/flask_sqlalchemy/requirements.txt with:

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

Original post

Hello,

I followed the README instructions for Example Flask+SQLAlchemy Project and I'm getting the following error:

ImportError: cannot import name 'get_default_backend' from 'graphql' (/home/mwk/code/graphene-sqlalchemy/.venv/lib/python3.9/site-packages/graphql/__init__.py)

My intention with this issue is to figure it out, documenting it for others, including a future me. Help is welcomed.

Upon pip install -r requirements.txt, I see this list of packages and versions (removed some probably-irrelevant ones:

"Successfully installed":

  • Flask-GraphQL-2.0.0
  • SQLAlchemy-1.4.46
  • flask-2.2.2
  • graphene-3.2.1
  • graphene-sqlalchemy-3.0.0b3
  • graphql-core-3.2.3
  • graphql-relay-3.2.0
  • graphql-server-core-1.1.1

Perhaps one of these versions is not the one I should be using.

I'm using Python 3.9.4, on WSL 2, Ubuntu 22.04.1 LTS, VS Code, pipenv shell.

Relevant discussions:

graphql-python/graphene#1086
https://stackoverflow.com/questions/70204957/flask-graphql-import-fails
#348
graphql-python/graphql-server#29
graphql-python/flask-graphql#66

@MattKleinsmith
Copy link
Author

MattKleinsmith commented Feb 14, 2023

Someone suggested upgrading Flask-GraphQL to 2.0.1, here:

https://stackoverflow.com/questions/70204957/flask-graphql-import-fails

I'll try it.

"Successfully installed":

  • Flask-GraphQL-2.0.1
  • graphql-core-2.3.2
  • rx-1.6.3

Now the error is:

ImportError: cannot import name 'GraphQLResolveInfo' from 'graphql' (/home/mwk/code/graphene-sqlalchemy/.venv/lib/python3.9/site-packages/graphql/__init__.py)

I used pip install Flask-GraphQL==2.0.1, but someone in the same Stack Overflow post recommended putting flask-graphql>=2.0.1 in requirements.txt instead. I'll try it.

Result: Pip conflict:

The conflict is caused by:
flask-graphql 2.0.1 depends on graphql-core<3 and >=2.1
graphene 3.2.1 depends on graphql-core<3.3 and >=3.1
[...]
flask-graphql 2.0.1 depends on graphql-core<3 and >=2.1
graphene 3.0b7 depends on graphql-core<4 and >=3.1.2

Interesting note from flask-graphql:

image

@MattKleinsmith
Copy link
Author

MattKleinsmith commented Feb 14, 2023

Going to try downgrading graphene-sqlalchemy (or Graphene itself?) from v3.0, because the README says:

Version 3.0 is in beta stage. Please read #348 to learn about progress and changes in upcoming beta releases.

Scratch this. Not sure which version I should downgrade to. Going to instead chase the errors by editing the pip packages.

@MattKleinsmith
Copy link
Author

MattKleinsmith commented Feb 14, 2023

Okay, flask-graphql's fix was to pin graphql-core to be under version 3.

However, the latest graphene versions require graphql-core to be over version 3.1.

So, I will try to find the latest graphene version that allows graphql-core to be under version 3.

The target version seems to be: graphene==2.1.9
Given this: https://pypi.org/project/graphene/#history

This leads to a new dependency error:

The user requested graphene==2.1.9
graphene-sqlalchemy 3.0.0b3 depends on graphene>=3.0.0b7

The target version seems to be: graphene-sqlalchemy==2.3.0
Given this: https://pypi.org/project/graphene-sqlalchemy/#history

@MattKleinsmith
Copy link
Author

Seems to be working now:

image

Approach: Downgrade.

How: Replace the entire contents of graphene-sqlalchemy/examples/flask_sqlalchemy/requirements.txt with:

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

@erikwrede
Copy link
Member

I'd strongly advise using the 3.0 beta if you're starting off a new project. It works best together with an asyncio-based framework like FastAPI, but flask is also fine.
https://github.com/ciscorn/starlette-graphene3

This should work with flask + graphene 3: https://github.com/graphql-python/graphql-server

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants