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()`.