Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide documentation for django-specific error formatter #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/django-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,23 @@ type_defs = """

schema = make_executable_schema(type_defs, [date_scalar, datetime_scalar, ...])
```

## Error Formatting

Ariadne sets clear expectations for delivery of validation messages and similar server side errors in
[Error Messaging](error-messaging.md). A default formatter with django-specific error handling is provided.
This formatter also handles djangorestframework's errors if you use that as well. This can be configured
similar to the following:

```python
from ariadne.contrib.django.format_error import format_graphql_error
from ariadne.contrib.django.views import GraphQLView
from django.urls import path

from .schema import schema

urlpatterns = [
...
path("graphql/", GraphQLView.as_view(schema=schema, error_formatter=format_graphql_error), name="graphql"),
]
```
6 changes: 6 additions & 0 deletions docs/error-messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ def my_format_error(error: GraphQLError, debug: bool = False) -> dict:

app = GraphQL(schema, error_formatter=my_format_error)
```

### Django

A default error formatted that covers a number of django and djangorestframework-specific errors has been provided
in `ariadne.contrib.django.format_error.format_graphql_error`. You can an updated set of constants as a dictionary
to override messaging. If not, this file can serve as a helpful starting point for building your own formatter.