graphql-python/graphene

cannot import name 'connection_from_list_slice' from 'graphql_relay.connection.arrayconnection'

louistwiice opened this issue · 2 comments

Hi everyone,

I am using graphene with the following stack am facing the following error after running the project

  • FastAPI
  • sqlalchemy
  • graphene

File "/.pyenv/versions/3.9.10/envs/fastapigraphene/lib/python3.9/site-packages/graphene_sqlalchemy/__init__.py", line 1, in <module> from .types import SQLAlchemyObjectType File "/.pyenv/versions/3.9.10/envs/fastapigraphene/lib/python3.9/site-packages/graphene_sqlalchemy/types.py", line 12, in <module> from .converter import ( File "/.pyenv/versions/3.9.10/envs/fastapigraphene/lib/python3.9/site-packages/graphene_sqlalchemy/converter.py", line 9, in <module> from .fields import createConnectionField File "/.pyenv/versions/3.9.10/envs/fastapigraphene/lib/python3.9/site-packages/graphene_sqlalchemy/fields.py", line 7, in <module> from graphql_relay.connection.arrayconnection import connection_from_list_slice ImportError: cannot import name 'connection_from_list_slice' from 'graphql_relay.connection.arrayconnection' (/.pyenv/versions/3.9.10/envs/fastapigraphene/lib/python3.9/site-packages/graphql_relay/connection/arrayconnection.py)

My project

# --- models.py ---
import uuid
import re

from sqlalchemy import Boolean, Column, String, TIMESTAMP, text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship, validates

class User(Base):
    __tablename__ = "users"

    id = Column(UUID(as_uuid=True), primary_key=True, index=True, default=uuid.uuid4)
    username = Column(String, unique=True, index=True)
    first_name = Column(String)
    last_name = Column(String)
    email = Column(String, unique=True, index=True)

serializers.py

# --- serializers.py ---
from graphene_sqlalchemy import SQLAlchemyObjectType

from .models import User

class User(SQLAlchemyObjectType):
    model = User

main.py

# --- serializers.py ---
import graphene
import uvicorn
from starlette.applications import Starlette
from starlette_graphene3 import GraphQLApp, make_graphiql_handler

from serializers import User


class Query(graphene.ObjectType):
    users = graphene.List(User)

    def resolve_users(self, info):
        query = User.get_query(info)
        return query.all()


schema = graphene.Schema(query=Query)

async def homepage(request):
    return {"message": "Hello Bigger Applications!"}


app = Starlette(routes=routes)
app.mount("/graphql", GraphQLApp(schema, on_get=make_graphiql_handler()))


if __name__ == '__main__':
    uvicorn.run(app, port=8000)

requirements.txt

sqlalchemy==1.4.44
pydantic==1.10.2
email-validator==1.3.0
psycopg2-binary==2.9.5
fastapi==0.88.0 # <--
starlette==0.22.0
alembic==1.8.1
bcrypt==4.0.1
passlib==1.7.4
pytz
rstr==3.2.0
starlette_graphene3==0.6.0 
graphene_sqlalchemy==2.1.0 
uvicorn[standard]
promise==2.3

I think it is a problem related to package dependencies but I can't correct it. Do you guyz know how to solve this problem?

Thank again for your help?

You're using starlette-graphene3 but graphene-sqlalchemy <3 which is incompatible with the starlette integration. You'll need to upgrade to graphene 3 & graphene-sqlalchemy 3 beta (latest is 3.0.0b3). Please let me know if that works!

Hello @erikwrede

Thank you very much for your help. It works now perfectly. There is no more problem