From 55e1929744a0269726200be276e49078bedd286c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 28 Jul 2025 15:38:14 -0400 Subject: [PATCH] Introduce is_graphql_request() utility function --- netbox/utilities/api.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/netbox/utilities/api.py b/netbox/utilities/api.py index 6793c0526..cc13e1b13 100644 --- a/netbox/utilities/api.py +++ b/netbox/utilities/api.py @@ -23,6 +23,7 @@ __all__ = ( 'get_serializer_for_model', 'get_view_name', '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 +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): """ Derive the view name from its associated model, if it has one. Fall back to DRF's built-in `get_view_name()`.