From dc753ed5f99bd651a352034bbd6308c499719f16 Mon Sep 17 00:00:00 2001 From: Sabar Dasgupta Date: Wed, 15 Feb 2023 11:15:07 -0500 Subject: [PATCH 1/3] fix: warnings in docs build --- docs/conf.py | 2 +- docs/inheritance.rst | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b660fc8..1d8830b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -178,7 +178,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] +# html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied diff --git a/docs/inheritance.rst b/docs/inheritance.rst index 277f87e..d7fcca9 100644 --- a/docs/inheritance.rst +++ b/docs/inheritance.rst @@ -1,9 +1,13 @@ Inheritance Examples ==================== + Create interfaces from inheritance relationships ------------------------------------------------ -.. note:: If you're using `AsyncSession`, please check the section `Eager Loading & Using with AsyncSession`_. + +.. note:: + If you're using `AsyncSession`, please check the chapter `Eager Loading & Using with AsyncSession`_. + SQLAlchemy has excellent support for class inheritance hierarchies. These hierarchies can be represented in your GraphQL schema by means of interfaces_. Much like ObjectTypes, Interfaces in @@ -111,8 +115,10 @@ class to the Schema constructor via the `types=` argument: See also: `Graphene Interfaces `_ + Eager Loading & Using with AsyncSession ---------------------------------------- + When querying the base type in multi-table inheritance or joined table inheritance, you can only directly refer to polymorphic fields when they are loaded eagerly. This restricting is in place because AsyncSessions don't allow implicit async operations such as the loads of the joined tables. To load the polymorphic fields eagerly, you can use the `with_polymorphic` attribute of the mapper args in the base model: From f86380d42b247c16827d831bf694872ac5b5c2c9 Mon Sep 17 00:00:00 2001 From: Sabar Dasgupta Date: Mon, 27 Feb 2023 12:05:30 -0500 Subject: [PATCH 2/3] add sphinx as docs requirement --- docs/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/requirements.txt b/docs/requirements.txt index 666a8c9..220b7cf 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,3 @@ +sphinx # Docs template http://graphene-python.org/sphinx_graphene_theme.zip From 57cf21251e401bda2a12218c745adb56a61928f0 Mon Sep 17 00:00:00 2001 From: Sabar Dasgupta Date: Mon, 27 Feb 2023 12:30:19 -0500 Subject: [PATCH 3/3] fix: autodoc warnings and formatting --- docs/api.rst | 4 +-- docs/tips.rst | 1 + graphene_sqlalchemy/types.py | 54 +++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index acdcbf1..237cf1b 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -11,8 +11,8 @@ SQLAlchemyInterface ORMField -------------------- -.. autoclass:: graphene_sqlalchemy.fields.ORMField +.. autoclass:: graphene_sqlalchemy.types.ORMField SQLAlchemyConnectionField ------------------------- -.. autoclass:: graphene_sqlalchemy.SQLAlchemyConnectionField \ No newline at end of file +.. autoclass:: graphene_sqlalchemy.SQLAlchemyConnectionField diff --git a/docs/tips.rst b/docs/tips.rst index daee173..a3ed69e 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -5,6 +5,7 @@ Tips Querying -------- .. _querying: + In order to make querying against the database work, there are two alternatives: - Set the db session when you do the execution: diff --git a/graphene_sqlalchemy/types.py b/graphene_sqlalchemy/types.py index 226d1e8..66db1e6 100644 --- a/graphene_sqlalchemy/types.py +++ b/graphene_sqlalchemy/types.py @@ -408,13 +408,15 @@ class SQLAlchemyObjectType(SQLAlchemyBase, ObjectType): Usage: - class MyModel(Base): - id = Column(Integer(), primary_key=True) - name = Column(String()) + .. code-block:: python - class MyType(SQLAlchemyObjectType): - class Meta: - model = MyModel + class MyModel(Base): + id = Column(Integer(), primary_key=True) + name = Column(String()) + + class MyType(SQLAlchemyObjectType): + class Meta: + model = MyModel """ @classmethod @@ -450,30 +452,32 @@ class SQLAlchemyInterface(SQLAlchemyBase, Interface): Usage (using joined table inheritance): - class MyBaseModel(Base): - id = Column(Integer(), primary_key=True) - type = Column(String()) - name = Column(String()) + .. code-block:: python - __mapper_args__ = { - "polymorphic_on": type, - } + class MyBaseModel(Base): + id = Column(Integer(), primary_key=True) + type = Column(String()) + name = Column(String()) - class MyChildModel(Base): - date = Column(Date()) + __mapper_args__ = { + "polymorphic_on": type, + } - __mapper_args__ = { - "polymorphic_identity": "child", - } + class MyChildModel(Base): + date = Column(Date()) - class MyBaseType(SQLAlchemyInterface): - class Meta: - model = MyBaseModel + __mapper_args__ = { + "polymorphic_identity": "child", + } - class MyChildType(SQLAlchemyObjectType): - class Meta: - model = MyChildModel - interfaces = (MyBaseType,) + class MyBaseType(SQLAlchemyInterface): + class Meta: + model = MyBaseModel + + class MyChildType(SQLAlchemyObjectType): + class Meta: + model = MyChildModel + interfaces = (MyBaseType,) """ @classmethod