ariadne-codegen icon indicating copy to clipboard operation
ariadne-codegen copied to clipboard

GraphQLClientError et al should be sourced from a separate package

Open ddevault opened this issue 3 months ago • 2 comments

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?

ddevault avatar Aug 07 '25 11:08 ddevault