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

New version of graphql-core breaks package #29

Closed
ms42Q opened this issue Dec 5, 2019 · 13 comments
Closed

New version of graphql-core breaks package #29

ms42Q opened this issue Dec 5, 2019 · 13 comments
Assignees

Comments

@ms42Q
Copy link

ms42Q commented Dec 5, 2019

Description

I am using Flask-GraphQL and since graphql-core:3 was released I get an import error.

  File "app.py", line 3, in <module>
    from flask_graphql import GraphQLView
  File "/usr/local/lib/python3.7/site-packages/flask_graphql/__init__.py", line 1, in <module>
    from .blueprint import GraphQL
  File "/usr/local/lib/python3.7/site-packages/flask_graphql/blueprint.py", line 5, in <module>
    from .graphqlview import GraphQLView
  File "/usr/local/lib/python3.7/site-packages/flask_graphql/graphqlview.py", line 7, in <module>
    from graphql_server import (HttpQueryError, default_format_error,
  File "/usr/local/lib/python3.7/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' (/usr/local/lib/python3.7/site-packages/graphql/__init__.py)

See:

https://raw.githubusercontent.com/graphql-python/graphql-server-core/7ff9553602cf33b5b137eaa6e8bff62dd1377043/graphql_server/__init__.py

Suggested change

Pin dependency to graphql-core==2.2.1 or even better upgrade to newer version of graphql-core.

Workaround

In my case pinning +graphql-core==2.2.1 worked.

@ms42Q
Copy link
Author

ms42Q commented Dec 5, 2019

@Cito
Copy link
Member

Cito commented Dec 5, 2019

This is already fixed in master, but it needs to be released on PyPI - see #28.

@Cito Cito self-assigned this Dec 5, 2019
@Cito
Copy link
Member

Cito commented Dec 6, 2019

This has now been released as v1.1.2. Let me know if there are still any problems.

@Cito Cito closed this as completed Dec 6, 2019
@pgzmnk
Copy link

pgzmnk commented Dec 23, 2021

Pinning graphql-core to <3 might have seemed a quick fix 2 years ago.

The package is now at version 3.2.0 which significantly enhances async support.

What needs to happen to upgrade graphql-server to support graphql-core >3 ?

@Cito
Copy link
Member

Cito commented Dec 23, 2021

@pgzmnk v3.0.0b4 already supports graphql-core >= 3.1. What we need is people reporting whether there are still issues with this beta version or whether it works nicely, and when everything looks ok, somebody who would cut a final release. I am currently working on graphql-core 3.2, but would be willing to test and help after I have released that.

@Cito
Copy link
Member

Cito commented Dec 23, 2021

@jkimbo what do you think?

@pgzmnk
Copy link

pgzmnk commented Dec 23, 2021

@Cito This is great to hear.

Here's the scenario:

I'm upgrading a graphene-sqlalchemy Flask API to graphene==3. As you suggested, I installed graphql-server==3.0.0b4.

Python 3.9.7

pip freeze:

graphene==3.0
graphene-sqlalchemy==3.0.0b1
graphql-core==3.1.3
graphql-relay==3.1.0
graphql-server==3.0.0b4
graphql-server-core==2.0.0

app.py

import os

from flask import Flask
from flask_cors import CORS
from graphql_server.flask import GraphQLView
# from flask_graphql import GraphQLView # produces same error

import src.models
from src.extensions import db
from src.schema import schema

app = Flask(__name__)

app.debug = True
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("SQLALCHEMY_DATABASE_URI")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
CORS(app)

app.add_url_rule(
    '/graphql',
    view_func=GraphQLView.as_view(
        'graphql',
        schema=schema,
        graphiql=True
    )
)


db.init_app(app)


if __name__ == '__main__':
    app.run()

Log:

Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/demo_graphene/src/app.py", line 6, in <module>
    from graphql_server.flask import GraphQLView
  File "/demo_graphene/.venv/lib/python3.9/site-packages/graphql_server/__init__.py", line 15, in <module>
    from graphql import get_default_backend
ImportError: cannot import name 'get_default_backend' from 'graphql' (/demo_graphene/.venv/lib/python3.9/site-packages/graphql/__init__.py)

There seems to be an outdated import statement.

Relevant discussion: graphql-python/graphene#1086

@Cito
Copy link
Member

Cito commented Dec 23, 2021

This looks like you have actually intstalled a very old (1.1.3 or so) version of graphql-server, 3.0.0b4 should not throw that error. Are you sure you ran the pip freeze with that demo_graphene/.venv activated?

@pgzmnk
Copy link

pgzmnk commented Dec 23, 2021

This is the observed output with a fresh .venv.

(.venv3) p@Ps-MacBook-Pro demo_graphene % pip freeze | grep graph
graphene==3.0
graphene-sqlalchemy==3.0.0b1
graphql-core==3.1.2
graphql-relay==3.1.0
graphql-server==3.0.0b4
graphql-server-core==2.0.0
(.venv3) p@Ps-MacBook-Pro demo_graphene % python3 -m src.app     
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/demo_graphene/src/app.py", line 5, in <module>
    from flask_graphql import GraphQLView
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_graphql/__init__.py", line 1, in <module>
    from .blueprint import GraphQL
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_graphql/blueprint.py", line 5, in <module>
    from .graphqlview import GraphQLView
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_graphql/graphqlview.py", line 7, in <module>
    from graphql_server import (HttpQueryError, default_format_error,
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/graphql_server/__init__.py", line 18, in <module>
    from graphql import get_default_backend
ImportError: cannot import name 'get_default_backend' from 'graphql' (/demo_graphene/.venv3/lib/python3.9/site-packages/graphql/__init__.py)

Uninstalling then reinstalling graphql-server then produces this different log, for the same pip freeze.

(.venv3) p@Ps-MacBook-Pro demo_graphene % pip freeze | grep graph            
graphene==3.0
graphene-sqlalchemy==3.0.0b1
graphql-core==3.1.2
graphql-relay==3.1.0
graphql-server==3.0.0b4
graphql-server-core==2.0.0
(.venv3) p@Ps-MacBook-Pro demo_graphene % python3 -m src.app                 
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/demo_graphene/src/app.py", line 5, in <module>
    from flask_graphql import GraphQLView
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_graphql/__init__.py", line 1, in <module>
    from .blueprint import GraphQL
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_graphql/blueprint.py", line 5, in <module>
    from .graphqlview import GraphQLView
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_graphql/graphqlview.py", line 7, in <module>
    from graphql_server import (HttpQueryError, default_format_error,
ImportError: cannot import name 'default_format_error' from 'graphql_server' (/demo_graphene/.venv3/lib/python3.9/site-packages/graphql_server/__init__.py)

@pgzmnk
Copy link

pgzmnk commented Dec 23, 2021

Setting format_error=None to temporarily overcome this issue results in:

Traceback (most recent call last):
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/flask/views.py", line 83, in view
    self = view.view_class(*class_args, **class_kwargs)  # type: ignore
  File "/demo_graphene/.venv3/lib/python3.9/site-packages/graphql_server/flask/graphqlview.py", line 58, in __init__
    assert isinstance(
AssertionError: A Schema is required to be provided to GraphQLView.

I will look into an alternative to Flask's app.

@Cito
Copy link
Member

Cito commented Dec 23, 2021

In the second installation it looks like you have flask_graphql installed. I think that was only needed with v2 and is incompatible with v3. Flask support is included already in graphql-server v3. In you lust dump it looks right again, but maybe the schema is somehow not passed properly, or mabye it's not a v3 schema.

@pgzmnk
Copy link

pgzmnk commented Dec 24, 2021

Thank you @Cito

Setting schema to schema.graphql_schema resolved the last issue. Successfully upgraded to graphene 3.0.

app.add_url_rule(
    '/graphql',
    view_func=GraphQLView.as_view(
        'graphql',
        schema=schema.graphql_schema,
        graphiql=True
    )
)

Reference: https://issueexplorer.com/issue/graphql-python/graphene/1127#926804

@Cito
Copy link
Member

Cito commented Dec 24, 2021

Glad to hear @pgzmnk .

I have just commited 476edf3 that allows passing a Graphene schema as well.

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