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

Error when importing flask_graphql #92

Open
sciencehope opened this issue Jan 4, 2023 · 2 comments
Open

Error when importing flask_graphql #92

sciencehope opened this issue Jan 4, 2023 · 2 comments

Comments

@sciencehope
Copy link

sciencehope commented Jan 4, 2023

Unable to import this library into my project. I always get an ImportError even if I create a new project with only one import.

My code api.py

from http.client import HTTPException
from multiprocessing import AuthenticationError
import os
from flask import Flask, request, jsonify, abort
from sqlalchemy import exc
import json
from flask_cors import CORS
from graphene import ObjectType, String, Schema
from flask_graphql import GraphQLView

app = Flask(__name__)

My requirements.txt
In the beginning, I specify the version of each library, but there was an error. To solve the error, I removed the FLask-GraphQL because it is in conflict with other graphene dependency. As it said, could not import flask_graphql I remove graphene version and specify the last version in the Flask-GraphQL so that my project use the last version of this library and solve the dependency conflict with graphene. But always the same error.

Flask == 2.2.2
Flask-SQLAlchemy == 3.0.2
Jinja2 == 3.1.2
pylint == 2.15.9
Flask-Cors == 3.0.10
graphene  #For graphql python support
Flask-GraphQL == 2.0.1

Error message

Error: While importing 'src.api', an ImportError was raised:

Traceback (most recent call last):
  File "/home/sticlab/Documents/NotebookProject/rasa-car-location-services/backend/venv/lib/python3.10/site-packages/flask/cli.py", line 218, in locate_app
    __import__(module_name)
  File "/home/sticlab/Documents/NotebookProject/rasa-car-location-services/backend/src/api.py", line 9, in <module>
    from flask_graphql import GraphQLView
  File "/home/sticlab/Documents/NotebookProject/rasa-car-location-services/backend/venv/lib/python3.10/site-packages/flask_graphql/__init__.py", line 1, in <module>
    from .blueprint import GraphQL
  File "/home/sticlab/Documents/NotebookProject/rasa-car-location-services/backend/venv/lib/python3.10/site-packages/flask_graphql/blueprint.py", line 5, in <module>
    from .graphqlview import GraphQLView
  File "/home/sticlab/Documents/NotebookProject/rasa-car-location-services/backend/venv/lib/python3.10/site-packages/flask_graphql/graphqlview.py", line 7, in <module>
    from graphql_server import (HttpQueryError, default_format_error,
  File "/home/sticlab/Documents/NotebookProject/rasa-car-location-services/backend/venv/lib/python3.10/site-packages/graphql_server/__init__.py", line 2, in <module>
    from collections import namedtuple, MutableMapping
ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
@jouyang3
Copy link

I have the same issue. I think it has to do with collections.MutableMapping is moved to collections.abc.MutableMapping: https://stackoverflow.com/questions/70870041/cannot-import-name-mutablemapping-from-collections

Any workaround or patches?

@MalcolmDwyer
Copy link

For people following tutorials and still landing here, use this instead of flask_graphql:

from graphql_server.flask import GraphQLView

Example: https://github.com/graphql-python/graphql-server/blob/master/docs/flask.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants