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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file rich-strawberry-0.1.2.tar.gz.

File metadata

  • Download URL: rich-strawberry-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 dc7471c52c94547b5ce047580b60a265ef073a0a56d28a7b3fc7f634305ba9ef
MD5 5a048a1790352701f555d1381afe0eb1
BLAKE2b-256 20e3a4cdd518ed2344693ee7b634eca87cad2ed69eb1f971b4da66f740083609

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rich_strawberry-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 404b262a6f3a97297fef29a77c09dce8c1014d5b06322a8f68d33e716926893f
MD5 408fc18d5701088a0b18886e4ef77d2d
BLAKE2b-256 1f1e54cf92ec47f62645d468b572f4027765122c4e7e88fdcbc9a79c7aad0922

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