graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Support for table to action relationships

Open fungiboletus opened this issue 4 years ago • 7 comments

Could Hasura do an action, a HTTP call to another API, in a computed field ?

In my use case, most of my data is sleeping in a postgresql database but some fields needs to be retrieved by accessing other services.

For example, I have a table devices

CREATE TABLE devices (
	id text NOT NULL,
	"type" text NOT NULL,
	CONSTRAINT device_pkey PRIMARY KEY (id)
);

As a very simple example I would use an online boolean saything whether the device is online or not. My real use case also involves retrieving information about a physical device and I don't really want to pull the data all the time and create many PostGresql transactions when it would not be queried very often.

A query would look like this for example :

{ devices { id type online } }

Could it be possible to have an action that will send through HTTP a json like {"id":"abc"} and expect a JSON in return true or false in my case ?

The next step would be to query on such computed fields:

{ devices(where: {online: {_eq: true}}) { id type } }

fungiboletus avatar May 27 '20 14:05 fungiboletus

Since this is a table to API join, maybe you can try Remote Joins: https://github.com/hasura/graphql-engine/pull/2392 . Will be out in v1.3 in few days.

Meanwhile, we have noted the feature request.

tirumaraiselvan avatar Jun 01 '20 09:06 tirumaraiselvan

this feature will be very useful, I have users list in a remote source ( restful api ) I can create query action to get the data to hasura but I need to join the data with products table in hasura db, like

user {
  id
  name
  email
  ...
}

product {
  id
  author_id
  author {
    id
    name
    email
    ...
  }
  name
  price
  ...
}

I know that I can create remote schema for users source and make it as remote schema join but it's much easier to make it with actions in the way I explained above.

alaarihan avatar Jun 11 '20 12:06 alaarihan

Hi, I also find this feature very useful!

Here is my use case. I manage my users and their's profiles in Firebase. In Hasura I have a table posts which has a field user_id which stores user's Firebase ID. Now I want to fetch posts with user profile info which is a trivial operation and I do not want to bring so much complexity like setup Apollo server and serve it as micro-graphql-server which has only one query on my cloud function.

DMezhenskyi avatar Aug 31 '20 14:08 DMezhenskyi

this feature will be very useful, I have users list in a remote source ( restful api ) I can create query action to get the data to hasura but I need to join the data with products table in hasura db, like

user {
  id
  name
  email
  ...
}

product {
  id
  author_id
  author {
    id
    name
    email
    ...
  }
  name
  price
  ...
}

I know that I can create remote schema for users source and make it as remote schema join but it's much easier to make it with actions in the way I explained above.

Other advantages of using an action instead of a remote schema is in the context of serverless like lambdas. It's much more scalable and cost-efficient. You can potentially host tiny remote schema in lambda but there is still a size/abstraction overhead to pay (hello cold starts :D).

We built a whole remote-schema to handle all the custom business logic we couldn't in Hasura, but we're now planning to migrate to actions for above reasons. With the upcoming request payload transformation feature, we will also be able to be more decoupled from Hasura in our lambda action handlers.

jgoux avatar Oct 29 '21 18:10 jgoux

Upvote here too!

thiagodamas avatar Nov 23 '21 02:11 thiagodamas

Any update on this?

davidpanic avatar Dec 09 '22 12:12 davidpanic

Hi, I want to update that we are launching Hasura V3 (DDN) this month. Rewriting Hasura in V3 allowed us to support all kind of relationships that were limitations in V2. V3 supports Model (Table in V2) to Command (Actions in V2) relationships from Day 1 (and a lot more features that V2 actions lacked)

I would highly suggest to join us to see the full power of Hasura DDN at the Hasura Dev Day on April 16 🎉. Sign up here: https://hasura.io/dev-day. Can't make it? Sign up anyway and we'll send you the recording.

manasag avatar Apr 11 '24 14:04 manasag