GithubHelp home page GithubHelp logo

streaming-chat-app's Introduction

streaming-chat-app

Step 1: One-click deployment on Hasura Cloud

The fastest and easiest way to try Hasura out is via Hasura Cloud.

  1. Click on the following button to deploy GraphQL engine on Hasura Cloud including Postgres add-on or using an existing Postgres database:

    Deploy to Hasura Cloud

  2. Open the Hasura console

    Click on the button "Launch console" to open the Hasura console.

Step 2: Apply migrations and metadata

Go to Run SQL in Console and execute the following:

CREATE TABLE public.channel_users (
    channel_id integer NOT NULL,
    user_id integer NOT NULL
);
CREATE TABLE public.messages (
    id integer NOT NULL,
    message text NOT NULL,
    author_id integer NOT NULL,
    channel_id integer NOT NULL
);
ALTER TABLE ONLY public.channel_users
    ADD CONSTRAINT channel_users_pkey PRIMARY KEY (channel_id, user_id);
ALTER TABLE ONLY public.messages
    ADD CONSTRAINT messages_pkey PRIMARY KEY (id);

Save the following in a file and then go to Import Metadata in Console:

{
  "metadata": {
    "version": 3,
    "sources": [
      {
        "name": "default",
        "kind": "postgres",
        "tables": [
          {
            "table": {
              "name": "channel_users",
              "schema": "public"
            }
          },
          {
            "table": {
              "name": "messages",
              "schema": "public"
            },
            "array_relationships": [
              {
                "name": "recipients",
                "using": {
                  "manual_configuration": {
                    "column_mapping": {
                      "channel_id": "channel_id"
                    },
                    "insertion_order": null,
                    "remote_table": {
                      "name": "channel_users",
                      "schema": "public"
                    }
                  }
                }
              }
            ],
            "select_permissions": [
              {
                "role": "user",
                "permission": {
                  "columns": [
                    "id",
                    "message",
                    "author_id",
                    "channel_id"
                  ],
                  "filter": {
                    "recipients": {
                      "user_id": {
                        "_eq": "X-Hasura-User-Id"
                      }
                    }
                  }
                }
              }
            ]
          }
        ],
        "configuration": {
          "connection_info": {
            "database_url": {
              "from_env": "PG_DATABASE_URL"
            },
            "isolation_level": "read-committed",
            "use_prepared_statements": false
          }
        }
      }
    ]
  }
}

Step 3: Try streaming subscriptions

Insert a few rows in messages and channel_users, then try a streaming subscriptions:

subscription {
  messages_stream(cursor: {initial_value: {id: 0} }, batch_size: 5) {
    id
    message
    author_id
  }
}

streaming-chat-app's People

Contributors

tirumaraiselvan avatar

Stargazers

Carolina avatar

Watchers

Aaron Johnson avatar Rajoshi Ghosh avatar Manas Agarwal avatar Vamshi Surabhi avatar  avatar

Forkers

anhmike

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.