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.18k stars 2.77k forks source link

Support for table to action relationships #4900

Open fungiboletus opened 4 years ago

fungiboletus commented 4 years ago

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 } }
tirumaraiselvan commented 4 years ago

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.

alaarihan commented 4 years ago

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.

DMezhenskyi commented 4 years ago

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.

jgoux commented 3 years ago

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.

thiagodamas commented 2 years ago

Upvote here too!

davidpanic commented 1 year ago

Any update on this?

manasag commented 7 months ago

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.