hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.19k stars 2.77k forks source link

Content-Type header's value override #10527

Open Nevemoire opened 2 months ago

Nevemoire commented 2 months ago

Is your proposal related to a problem? Yes

I'm using Hasura to communicate with OpenStack's API. Trying to make a change to existing image instance I've encountered a problem that I can't change Content-Type header to my value, it's always transformed automatically to application/json. Accordingly to an OpenStack's API Docs it's value must be application/openstack-images-v2.1-json-patch, otherwise it will return 415 status error.

Describe the solution you'd like

The best solution would be to have an opportunity to override default values if needed.

rakeshkky commented 2 months ago

Hi @Nevemoire, Please provide additional details such as -

Nevemoire commented 2 months ago

Hi @rakeshkky. Yes, all the communication with OpenStack is handled via Hasura Actions.

For POST, GET and DELETE calls everything works fine as far as I pass OpenStack's token via X-Auth-Token header. The problem appears when I'm trying to make a PATCH request as it's needed to pass a custom Content-Type header as I've mentioned above.

When I'm testing update Action via Hasura's API explorer, here is what I'm passing: "headers": [ { "name": "Content-Type", "value": "application/openstack-images-v2.1-json-patch" }, { "name": "X-Forwarded-Host", "value": "xxx:8080" }, { "name": "X-Forwarded-User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 YaBrowser/24.7.0.0 Safari/537.36" }, { "name": "X-Forwarded-Origin", "value": "http://xxx:8080" }, { "name": "x-request-id", "value": "3b9086ee-4a6f-4ede-af0b-0213e276a630" }, { "name": "X-Auth-Token", "value": "xxx" } ], but in transformed request Content-Type equals application/json, therefore I receive 415 status error from OpenStack.

Sorry if my explanation is not clear

rakeshkky commented 2 months ago

Thank you for the information. Have you checked out Request Transformation in Actions? It has a way to set the Content-Type header value. Ref: Rest Connectors

Nevemoire commented 2 months ago

@rakeshkky gotcha. Now I'm trying to manually import metadata where I specify request_transform as: "request_transform": { "method": "PATCH", "query_params": {}, "template_engine": "Kriti", "url": "{{$base_url}}/{{escapeUri($body.input.id)}}", "content_type": "application/openstack-images-v2.1-json-patch", "version": 1 },, but after importing it removes a content_type field. Can you please explain what am I doing wrong?

Nevemoire commented 2 months ago

Full action: { "name": "updateImage", "definition": { "handler": "http://ip:port/v2/images", "output_type": "UpdatedImage", "forward_client_headers": true, "arguments": [ { "name": "id", "type": "String!" }, { "name": "name", "type": "String" }, { "name": "size", "type": "Int" } ], "request_transform": { "method": "PATCH", "query_params": {}, "template_engine": "Kriti", "url": "{{$base_url}}/{{escapeUri($body.input.id)}}", "content_type": "application/openstack-images-v2.1-json-patch", "version": 1 }, "type": "mutation", "kind": "synchronous" } }