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.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

rich_strawberry-0.1.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for rich-strawberry-0.1.3.tar.gz
Algorithm Hash digest
SHA256 abab0ffcc4538b63c7429dbc1647e0a0b3202ef6d426f38ef8e7746e8cae2cf9
MD5 91b0b089a582d201a00fcc6feb89b7ad
BLAKE2b-256 dbcdfdb3e5ae7ff784c2797be8c654dc926e12e433ecd1a2dfe8620ad9b89871

See more details on using hashes here.

File details

Details for the file rich_strawberry-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for rich_strawberry-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b42c0aeeef83cd5c5f954518502524c0b9a2a33c4caa895fcfd8164231acaf3
MD5 990f70827e4b64c5a2c4eaa9db7f4a9a
BLAKE2b-256 04e30b5f9b5c5619c7b812688a048d324aae509396fde82245a621d59abd9e2b

See more details on using hashes here.

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