No project description provided
Project description
Rich Strawberry
This is a work in progress!
rich-strawberry
is a small add-on for the strawberry-graphql library that uses rich to print error information nicely.
Basic Example
At the moment, you have to use a special SchemaWithRichLogger
class when defining your schema to use the RichGraphQLLogger
. Here's a basic example:
import strawberry
from rich_strawberry import SchemaWithRichLogger
@strawberry.type
class Query:
@strawberry.field
def version(self) -> int:
raise ValueError
schema = SchemaWithRichLogger(query=Query)
This will give you the following output in the console for the query query { version }
:
Configuration
Suppressing frames
By default the logger uses rich
'es feature to suppress the frames from graphql
and strawberry-graphql
libraries. You can configure the list of modules for which the frames will be suppressed. For example, if you want the full traceback:
import strawberry
from rich_strawberry import RichGraphQLLogger, SchemaWithRichLogger
@strawberry.type
class Query:
@strawberry.field
def version(self) -> int:
raise ValueError
debug_logger = RichGraphQLLogger(suppress_traceback_from=[])
schema = SchemaWithRichLogger(query=Query, debug_logger=debug_logger)
Here's the full console output:
Logging context
You can also configure some values from the context to be logged on error.
import strawberry
from rich_strawberry import RichGraphQLLogger, SchemaWithRichLogger
@strawberry.type
class Query:
@strawberry.field
def version(self) -> int:
raise ValueError
debug_logger = RichGraphQLLogger(log_context_keys=("request",))
schema = SchemaWithRichLogger(query=Query, debug_logger=debug_logger)
This will use rich.inspect
to print that context value into the console:
❗ This feature is not very well tested with different integrations so it might not work as expected.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file rich-strawberry-0.1.3.tar.gz
.
File metadata
- Download URL: rich-strawberry-0.1.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.4.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | abab0ffcc4538b63c7429dbc1647e0a0b3202ef6d426f38ef8e7746e8cae2cf9 |
|
MD5 | 91b0b089a582d201a00fcc6feb89b7ad |
|
BLAKE2b-256 | dbcdfdb3e5ae7ff784c2797be8c654dc926e12e433ecd1a2dfe8620ad9b89871 |
File details
Details for the file rich_strawberry-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: rich_strawberry-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.4.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b42c0aeeef83cd5c5f954518502524c0b9a2a33c4caa895fcfd8164231acaf3 |
|
MD5 | 990f70827e4b64c5a2c4eaa9db7f4a9a |
|
BLAKE2b-256 | 04e30b5f9b5c5619c7b812688a048d324aae509396fde82245a621d59abd9e2b |