Skip to content

GraphQLClientError et al should be sourced from a separate package #373

@ddevault

Description

@ddevault

Hi! I'm running into a small frustration when experimenting with ariadne-codegen. Types like GraphQLClientError are just copied as-is from Ariadne into the generated namespace, resulting in something like foo.graphql_client.GraphQLClientError as the fully qualified type. For my use-case, we have standardized error handling throughout several different projects which each use their own generated GraphQL client -- but it's not straightforward to feed these exceptions into common error handling code (to, for instance, catch the errors and translate them into error feedback on HTML form inputs). I end up doing something like this in my generic code:

class ErrorHandlingContextThingy:
    def __enter__(self):
        pass

    def __exit__(self, exc_type, exc_value, traceback):
        if exc_type is None:
            return

        is_gql = exc_type.__name__ == "GraphQLClientGraphQLMultiError"

        if not is_gql:
            raise exc_value

        for err in exc_value.errors:
            # ...process the errors...

Because I don't know the fully qualified name of the exception in advance.

It seems to me that some features common to all GraphQL clients, such as the set of standard exceptions, and perhaps the BaseClient as well, would benefit from being sourced from a common graphql_client package (or similar) rather than being copied into the generated code.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions