Skip to content

No unified way of setting up SQLAlchemy sessions #223

Description

@guilhermelou

The session setup has to be done twice and ideally there should be a single point of contact for it.
As of now, there's a session setup for the Dataloader injected in the context and one for the relay connections, e.g.:

Session Setup For Dataloaders

# context is expected to have an instance of StrawberrySQLAlchemyLoader
class CustomGraphQLView(GraphQLView):
    def get_context(self):
        return {
            "sqlalchemy_loader": StrawberrySQLAlchemyLoader(bind=YOUR_SESSION),
        }

Session Setup For Relay

@mapper.type(fruit_table)
class Fruit(relay.Node):
    id: relay.NodeID[int]

@strawberry.type
class Query:
    fruits: relay.ListConnection[Fruit] = connection(sessionmaker=sessionmaker)

The issue had already been spotted by the author on this comment: #65 (comment) and discussed on a community-chat session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions