Hasura query action exception

Viewed 847

Got a small problem (I guess). I created c# rest web API on docker swarm environment. Rest API is working properly - tested via the postman. Then I tried to compose Hasura service on the same docker swarm environment. The console is working properly also. The problem is with query action.

Code:

Action definition:

type Query {
  getWeatherForecast : [WeatherForecastResonse]
}

New types definition:

type WeatherForecastResonse {
  date : String
  temperatureC : Int
  temperature : Int
  summary : String
}

Handler:

http://{api ip}:{api port}/WeatherForecast

While trying to execute query:

query MyQuery {
  getWeatherForecast {
    temperature
    summary
    date
    temperatureC
  }
}

All I got from response is error with json:

{
  "errors": [
    {
      "extensions": {
        "internal": {
          "error": "invalid json: Error in $: not enough input",
          "response": {
            "status": 405,
            "body": "",
            "headers": [
              {
                "value": "Mon, 14 Jun 2021 13:54:00 GMT",
                "name": "Date"
              },
              {
                "value": "Kestrel",
                "name": "Server"
              },
              {
                "value": "0",
                "name": "Content-Length"
              },
              {
                "value": "GET",
                "name": "Allow"
              }
            ]
          },
          "request": {
            "body": {
              "session_variables": {
                "x-hasura-role": "admin"
              },
              "input": {},
              "action": {
                "name": "getWeatherForecast"
              }
            },
            "url": "http://{api ip}:{api port}/WeatherForecast",
            "headers": []
          }
        },
        "path": "$",
        "code": "unexpected"
      },
      "message": "not a valid json response from webhook"
    }
  ]
}

I got desired response by using postman white calling: http://{api ip}:{api port}/WeatherForecast (GET method)

Where should I improve, to finally get desired result from rest api?

P.S. hasura version: v2.0.0-alpha.4 (tried also with v1.3.3)

UPDATE: Released a new version of web API. Inside WeatherForecastController included a new method with POST attribute. Query remained the same, but now graphql query returns what I want.

So the question is: Is it possible to call/access web api methods with GET attribute with Hasura action query?

2 Answers

From the version v2.1.0 and above we can do this using the REST Connectors.Hasura Actions RESTConnectors Methods

Go to the Actions tab on the console and create or modify an action. Scroll down to Configure REST Connectors.

In the Configure REST Connectors section, click on Add Request Options Transform

Along with this you can do a lot of other configurations.

Related