Hello KrakenD Community,
I am currently learning how to use KrakenD as API-Gateway and 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:
```plaintext
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:
```python
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:
```python
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 = ["
http://localhost:3000"]
```
My krakend.json settings:
```json
{
"version": 3,
"name": "API Gateway",
"port": 8080,
"cache_ttl": "3600s",
"timeout": "3s",
"extra_config": {
"security/cors": {
"allow_origins": [
"*"
],
"allow_methods": [
"GET",
"HEAD",
"POST"
],
"expose_headers": [
"Content-Length",
"Content-Type"
],
"allow_headers": [
"Accept-Language",
"Content-Type",
"Authorization"
],
"max_age": "12h",
"allow_credentials": false,
"debug": false
},
"router": {
"auto_options": true
}
},
"endpoints": [
{
"endpoint": "/api/graphql",
"method": "POST",
"input_query_strings":["*"],
"backend": [
{
"timeout": "4100ms",
"host": ["
http://backend:8000"],
"url_pattern": "/graphql?timeout=4s/"
}
]
}
]
}
```
**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!