Skip to main content

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 }:

Basic Output

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:

Output Without Frame Suppression

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:

Output With Request

❗ 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

rich-strawberry-0.1.2.tar.gz (7.0 kB view hashes)

Uploaded Source

Built Distribution

rich_strawberry-0.1.2-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page