graphql-python / graphene-sqlalchemy

Graphene SQLAlchemy integration
http://docs.graphene-python.org/projects/sqlalchemy/en/latest/
MIT License
975 stars 225 forks source link

Encounter an error when trying the example #321

Closed MingzXIE closed 2 years ago

MingzXIE commented 2 years ago

Hi there,

I was trying the example code in the Readme file. However, I met this error:

  File "C:\Users\ming\.pyenv\pyenv-win\versions\3.9.5\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\ming\.pyenv\pyenv-win\versions\3.9.5\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\ming\Documents\GitHubPrivate\orderingapp\venv\Scripts\uvicorn.exe\__main__.py", line 7, in <module>
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\click\core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\click\core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\click\core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\uvicorn\main.py", line 425, in main
    run(app, **kwargs)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\uvicorn\main.py", line 447, in run
    server.run()
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\uvicorn\server.py", line 68, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Users\ming\.pyenv\pyenv-win\versions\3.9.5\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\ming\.pyenv\pyenv-win\versions\3.9.5\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\uvicorn\server.py", line 76, in serve
    config.load()
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\uvicorn\config.py", line 448, in load
    self.loaded_app = import_from_string(self.app)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
  File "C:\Users\ming\.pyenv\pyenv-win\versions\3.9.5\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\ming\Documents\GitHubPrivate\orderingapp\.\main.py", line 15, in <module>
    from graphql_builder.schema import schema
  File "C:\Users\ming\Documents\GitHubPrivate\orderingapp\.\graphql_builder\schema.py", line 5, in <module>
    class User(SQLAlchemyObjectType):
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\graphene\types\objecttype.py", line 29, in __new__
    base_cls = super().__new__(
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\graphene\utils\subclass_with_meta.py", line 46, in __init_subclass__
    super_class.__init_subclass_with_meta__(**options)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\graphene_sqlalchemy\types.py", line 226, in __init_subclass_with_meta__
    construct_fields(
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\graphene_sqlalchemy\types.py", line 161, in construct_fields
    field = convert_sqlalchemy_column(attr, registry, resolver, **orm_field.kwargs)
  File "c:\users\ming\documents\githubprivate\orderingapp\venv\lib\site-packages\graphene_sqlalchemy\converter.py", line 163, in convert_sqlalchemy_column
    return Field(
TypeError: __init__() missing 1 required positional argument: 'type_'

This is my schema file which is the same as the example:

import graphene
from sql.models.credential import CredentialModel
from graphene_sqlalchemy import SQLAlchemyObjectType

class User(SQLAlchemyObjectType):
    class Meta:
        model = CredentialModel

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)

And my model file:

from sql.models import Base
from sqlalchemy import Column, String, BigInteger

class CredentialModel(Base):
    __tablename__ = 'Credential'
    id = Column(BigInteger, primary_key=True)
    username = Column(String(50))
    password = Column(String(30))

Did I miss something? Many thanks!

MingzXIE commented 2 years ago

By the way the version I am using is:

graphene-sqlalchemy==2.3.0

chrisberks commented 2 years ago

It looks like you're using Graphene v3. Version 3 is still in beta and is not compatible with the latest stable release of Graphene-SQLAlchemy.

MingzXIE commented 2 years ago

Thanks @chrisberks

Sine we are using FastAPI, so we need starlette-graphene3 which requires Graphene V3

Just close this issue since it looks like a package version issue

github-actions[bot] commented 1 year ago

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.