diff --git a/docs/database.md b/docs/database.md index 627f71d0..571f6b1d 100644 --- a/docs/database.md +++ b/docs/database.md @@ -1,6 +1,15 @@ Starlette includes optional database support. There is currently only a driver for Postgres databases, but MySQL and SQLite support is planned. +Enabling the built-in database support requires `sqlalchemy`, and an appropriate database driver. Currently this means `asyncpg` is a requirement. + +The database support is completely optional - you can either include the middleware or not, or you can build alternative kinds of backends instead. It does not +include support for an ORM, but it does support using queries built using +[SQLAlchemy Core][sqlalchemy-core]. + +Here's a complete example, that includes table definitions, installing the +`DatabaseMiddleware`, and a couple of endpoints that interact with the database. + ```python import os import sqlalchemy diff --git a/docs/graphql.md b/docs/graphql.md index 7de1ff93..16f9188f 100644 --- a/docs/graphql.md +++ b/docs/graphql.md @@ -25,6 +25,22 @@ which you can use to interact with your GraphQL API. ![GraphiQL](img/graphiql.png) +## Accessing request information + +The current request is available in the context. + +```python +class Query(graphene.ObjectType): + user_agent = graphene.String() + + def resolve_user_agent(self, info): + """ + Return the User-Agent of the incoming request. + """ + request = info.context["request"] + return request.headers.get("User-Agent", "") +``` + ## Sync or Async executors If you're working with a standard ORM, then just use regular function calls for diff --git a/docs/release-notes.md b/docs/release-notes.md index 59e41554..6ddc34cc 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,3 +1,9 @@ +## 0.9.2 + +* Add optional database support. +* Add `request` to GraphQL context. +* Hide any password component in `URL.__repr__`. + ## 0.9.1 * Handle startup/shutdown errors properly. diff --git a/starlette/__init__.py b/starlette/__init__.py index d69d16e9..a2fecb45 100644 --- a/starlette/__init__.py +++ b/starlette/__init__.py @@ -1 +1 @@ -__version__ = "0.9.1" +__version__ = "0.9.2"