0

I want to modify the response of hasura fetch query.

the current response is this:

{
  "data": {
   "ids": [
    {
      "id_object": {
        "id": 33102
      }
    },
    {
      "id_object": {
        "id": 33104
      }
    }
   ]
  }
}

And I want to remove "id_object" and want just array of id's like this:

{
  "data": {
   "ids": [
    {
      "id": 33102
    },
    {
      "id": 33104
    }
   ]
  }
}
DevError404
  • 129
  • 2
  • 14
Punit
  • 3
  • 3

1 Answers1

1

A GraphQL server exposes an exact set of operations and the shape of the allowed responses for those operations. When interacting with any GraphQL server (Hasura or otherwise), it is therefore not possible to to arbitrarily modify the shape of the returned data.

You're free to map it into a new form when you receive the data on the client side.

If you really need the server itself to be able to respond using this shape, you'll need to extend Hasura's schema to be able to specifically support this query pattern.

There are a number of different ways that you could accomplish this:

  • You could write a custom Hasura Action
  • You could expose this query from your own GraphQL server and then stitch it together with Hasura using Remote Schemas
  • You could use a Postgres View or Function to shape the data as required and expose it as a new operation
Jesse Carter
  • 20,062
  • 7
  • 64
  • 101