Introduce is_graphql_request() utility function

This commit is contained in:
Jeremy Stretch 2025-07-28 15:38:14 -04:00
parent f3155973f6
commit 55e1929744

View File

@ -23,6 +23,7 @@ __all__ = (
'get_serializer_for_model', 'get_serializer_for_model',
'get_view_name', 'get_view_name',
'is_api_request', 'is_api_request',
'is_graphql_request',
) )
@ -60,6 +61,13 @@ def is_api_request(request):
return request.path_info.startswith(api_path) and request.content_type == HTTP_CONTENT_TYPE_JSON return request.path_info.startswith(api_path) and request.content_type == HTTP_CONTENT_TYPE_JSON
def is_graphql_request(request):
"""
Return True of the request is being made via the GraphQL API.
"""
return request.path_info == reverse('graphql') and request.content_type == HTTP_CONTENT_TYPE_JSON
def get_view_name(view): def get_view_name(view):
""" """
Derive the view name from its associated model, if it has one. Fall back to DRF's built-in `get_view_name()`. Derive the view name from its associated model, if it has one. Fall back to DRF's built-in `get_view_name()`.