Django GraphQL Endpoint Not Found When Requested via Krakend API Gateway

Django GraphQL Endpoint Not Found When Requested via Krakend API Gateway


0

Hello StackOverflow Community,

I am currently experiencing an issue with a Django project using GraphQL, specifically when attempting to access the GraphQL endpoint through the Krakend API Gateway.

Environment:

  • Django: 4.2.6
  • GraphQL
  • Krakend API Gateway
  • Dockerized environment

Problem:

When I send a request directly to the Django backend’s /graphql endpoint, it works as expected. However, when I attempt to access the same endpoint via the Krakend API Gateway, I receive a 404 Not Found error.

Error Log:

Here is the error message received in the Docker logs:

backend_1   | Not Found: /graphql
backend_1   | [14/Oct/2023 23:32:52] "POST /graphql HTTP/1.1" 404 2961

This indicates that when the request is routed through Krakend to the Django backend, the /graphql endpoint cannot be found.

Code:

In my urls.py, I have the /graphql endpoint defined as:

from django.urls import path, re_path
from graphene_django.views import GraphQLView
from django.views.decorators.csrf import csrf_exempt

urlpatterns = [
    path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True, name='graphql'))),
    # ... other paths ...
]

My settings (pertinent to the URLs and middleware) in settings.py include:

ALLOWED_HOSTS = ['backend', 'frontend', 'localhost', ...]
INSTALLED_APPS = ['graphene_django', ...]
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ORIGIN_WHITELIST = ["https://localhost:3000"]

Attempted Solutions:

  1. Verified the /graphql endpoint is defined correctly in Django.
  2. Ensured that Docker services are networked properly.
  3. Checked Krakend configurations to ensure correct routing to the Django backend.
  4. Tried direct access to the Django backend endpoint, which works as expected, confirming that the endpoint does exist and function.

Despite the above, the issue persists.

Questions:

  1. How might Krakend be mishandling or misrouting the requests such that the /graphql endpoint is not found?
  2. Could there be a configuration issue within Django that is affecting the routing of requests coming from Krakend but not direct requests?
  3. Are there any additional logging or debugging steps that might illuminate why Krakend cannot access the /graphql endpoint?

Any insights or assistance with this issue would be greatly appreciated. Thank you in advance for your time and help!


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *