GHC 2019-06-15

1 comment.

, https://git.io/fj25H in graphql-python/graphene-sqlalchemy
I'm talking about auto-generated connection field from your SQLA model, not a SQLAlchemyConnectionField you explicitly add to the query (which does not go through the default connection field factory — you already explicitly instantiated the field).

A default connection field is created when you have, say, a one to many relationship on your SQLA model. You don't show your database models here, but say we have two very simple tables:

```py
Base = declarative_base()


class UserModel(Base):
    __tablename__ = "user"
    id = Column(Integer, primary_key=True)
    transactions = relationship("TransactionModel", back_populates="user")


class TransactionModel(Base):
    __tablename__ = "transaction"
    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey("user.id"), nullable=False)
    user = relationship("UserModel", back_populates="transactions")


class User(SQLAlchemyObjectType):
    class Meta:
        model = UserModel
        interfaces = (Node,)


class Transaction(SQLAlchemyObjectType):
    class Meta:
        model = TransactionModel
        interfaces = (Node,)
```

Then the generated `User` type will have a `transactions` field which is an auto-generated `TransactionConnection`, whereas the `Transaction` type won't have an auto-generated connection field.

**Update**: I made a mistake when I said "the `Transaction` type won't have an auto-generated connection field." Since it has a `user` field, it also ends up with an auto-generated connection field through `User`; one has to exclude `user` to see the effect.