graphql-engine/console
Rakesh Emmadi d52bfcda4e
backend only insert permissions (rfc #4120) (#4224)
* move user info related code to Hasura.User module

* the RFC #4120 implementation; insert permissions with admin secret

* revert back to old RoleName based schema maps

An attempt made to avoid duplication of schema contexts in types
if any role doesn't possess any admin secret specific schema

* fix compile errors in haskell test

* keep 'user_vars' for session variables in http-logs

* no-op refacto

* tests for admin only inserts

* update docs for admin only inserts

* updated CHANGELOG.md

* default behaviour when admin secret is not set

* fix x-hasura-role to X-Hasura-Role in pytests

* introduce effective timeout in actions async tests

* update docs for admin-secret not configured case

* Update docs/graphql/manual/api-reference/schema-metadata-api/permission.rst

Co-Authored-By: Marion Schleifer <marion@hasura.io>

* Apply suggestions from code review

Co-Authored-By: Marion Schleifer <marion@hasura.io>

* a complete iteration

backend insert permissions accessable via 'x-hasura-backend-privilege'
session variable

* console changes for backend-only permissions

* provide tooltip id; update labels and tooltips;

* requested changes

* requested changes

- remove className from Toggle component
- use appropriate function name (capitalizeFirstChar -> capitalize)

* use toggle props from definitelyTyped

* fix accidental commit

* Revert "introduce effective timeout in actions async tests"

This reverts commit b7a59c19d6.

* generate complete schema for both 'default' and 'backend' sessions

* Apply suggestions from code review

Co-Authored-By: Marion Schleifer <marion@hasura.io>

* remove unnecessary import, export Toggle as is

* update session variable in tooltip

* 'x-hasura-use-backend-only-permissions' variable to switch

* update help texts

* update docs

* update docs

* update console help text

* regenerate package-lock

* serve no backend schema when backend_only: false and header set to true

- Few type name refactor as suggested by @0x777

* update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* fix a merge bug where a certain entity didn't get removed

Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Rishichandra Wawhal <rishi@hasura.io>
Co-authored-by: rikinsk <rikin.kachhia@gmail.com>
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
2020-04-24 14:40:53 +05:30
..
bin fix console hot reloading and upgrade to babel 7 (#1618) 2019-02-19 14:00:48 +05:30
cypress console: allow adding post-update checks in update permissions (close #4142) (#4313) 2020-04-22 17:55:10 +05:30
src backend only insert permissions (rfc #4120) (#4224) 2020-04-24 14:40:53 +05:30
static update console error pages image (#2762) 2019-08-21 16:54:12 +05:30
webpack console: set allow-js compiler flag for type checker (#4290) 2020-04-06 20:19:35 +05:30
.babelrc console: add design system base ui components (#3866) 2020-03-18 17:52:29 +05:30
.bootstraprc add console to graphql-engine 2018-06-28 10:27:37 +05:30
.eslintignore add console to graphql-engine 2018-06-28 10:27:37 +05:30
.eslintrc console: allow adding post-update checks in update permissions (close #4142) (#4313) 2020-04-22 17:55:10 +05:30
.gitignore console: add TypeScript setup (#3902) 2020-03-05 15:01:32 +05:30
.prettierignore console: fix linter config (#4137) 2020-04-06 16:53:04 +05:30
cypress.json add parallel tests and update dependencies (#374) 2018-09-08 23:01:14 +05:30
hasuraconfig.js add console to graphql-engine 2018-06-28 10:27:37 +05:30
Makefile console (make): fix gcs bucket name (close #3026) (#3260) 2019-10-28 12:15:16 +05:30
package-lock.json backend only insert permissions (rfc #4120) (#4224) 2020-04-24 14:40:53 +05:30
package.json backend only insert permissions (rfc #4120) (#4224) 2020-04-24 14:40:53 +05:30
README.md noop: replace subdomain links with subpath (#3869) 2020-02-27 15:43:07 +05:30
tsconfig.json console: migrate checkbox, icon and radio button to TypeScript (#4373) 2020-04-22 16:47:10 +05:30

Hasura Console

The Hasura console is an admin dashboard to manage the connected database and to try out GraphQL APIs. It is a React application bundled with webpack and the state is managed using Redux.

Served by:

  1. Hasura GraphQL Engine: The console is served by GraphQL Engine at /console endpoint (when --enable-console flag is used). Typically runs in No Migration Mode which means that actions on the console are not spitting out migration “yaml” files automatically. Most users will be using the Hasura console in this mode.

  2. Hasura CLI: Served by the Hasura CLI using hasura console command, typically runs with migration mode enabled. All the changes to schema/hasura metadata will be tracked and spit out on the filesystem as migration yaml files and a metadata yaml file. This allows for easy version controlling of the schema/hasura metadata.

Contributing to Hasura console

This guide is for setting-up the console for development on your own machine, and how to contribute.

Console issues in the repo

Issues in the repo for the console UI are labelled as c/console(see list). Issues also labelled as good first issue are aimed at those making their first contribution to the repo (see list). Others marked as help wanted are those requiring community contributions on priority (see list).

Please note that some of these issues, labelled with both c/console and c/server, are part of a change/task that requires modifications in both the server and the console.

Feel free to open pull requests to address these issues or to add/fix console features, even if a corresponding issue doesn't exist. If you are unsure about whether to go ahead and work on something like the latter, please get in touch with the maintainers in the GraphQL Engine->contrib channel in the community Discord.

Prerequisites

Set up and install dependencies

  • Fork the repo on GitHub.
  • Clone your forked repo: git clone https://github.com/<your-username>/graphql-engine
git clone https://github.com/<your-user-name>/graphql-engine
cd graphql-engine
cd console
npm ci

Run console development server

Hasura console can be developed in two modes, server or cli mode. If you are looking to add/tweak functionality related to migrations, check out Develop with Hasura CLI, otherwise check out Develop with Hasura GraphQL engine.

Both modes require a running instance of GraphQL Engine. The easiest way to get Hasura GraphQL engine instance is by Heroku. You can get it by following the steps given in this link. Other methods to install Hasura GraphQL engine are documented here.

Dotenv is used for setting environment variables for development. In production, these environment variables are templated by the server or CLI.

Develop with Hasura GraphQL engine (server mode)

In server mode, migrations will be disabled and the corresponding functionality on the console will be hidden.

Set up .env file

Environment variables accepted in server mode:

  • NODE_ENV: Console build environment (development/production)
  • PORT: The port where Hasura console will run locally
  • CDN_ASSETS: Should assets be loaded from CDN (true/false)
  • ASSETS_PATH: Path to console assets
  • ASSETS_VERSION: Version of console assets being served
  • ENABLE_TELEMETRY: Whether to enable telemetry (true/false)
  • URL_PREFIX: Path at which the console is running
  • DATA_API_URL: The Hasura GraphQL engine url. (If you are running it on Heroku, it will look like <app-name>.herokuapp.com, if you are running locally, it will look like http://localhost:<port>)
  • SERVER_VERSION: Hasura GraphQL Engine server version
  • CONSOLE_MODE: In server mode, it should be server
  • IS_ADMIN_SECRET_SET: Is GraphQl engine configured with an admin secret (true/false)

Here's an example .env file for server mode:

NODE_ENV=development
PORT=3000
CDN_ASSETS=true
ASSETS_PATH=https://graphql-engine-cdn.hasura.io/console/assets
ASSETS_VERSION=channel/stable/v1.0
ENABLE_TELEMETRY=true
URL_PREFIX=/
DATA_API_URL=http://localhost:8080
SERVER_VERSION=v1.0.0
CONSOLE_MODE=server
IS_ADMIN_SECRET_SET=true

The server also templates consolePath in window.__env which is the relative path of the current page (something like /console/data/schema/public). Using this path, the console determines the DATA_API_URL in production. You do not need to worry about this in development since you are hardcoding the value of DATA_API_URL in .env.

Run console development server:
 npm run dev

Develop with Hasura CLI (cli mode)

Set up .env file

Environment variables accepted in cli mode:

  • NODE_ENV: Console build environment (development/production)
  • PORT: The port where Hasura console will run locally
  • API_HOST: Hasura CLI host. Hasura CLI runs on http://localhost by default.
  • API_PORT: Hasura CLI port. Hasura CLI exposes the API at 9693 by default
  • CDN_ASSETS: Should assets be loaded from CDN (true/false)
  • ASSETS_PATH: Path to console assets
  • ASSETS_VERSION: Version of console assets being served
  • ENABLE_TELEMETRY: Whether to enable telemetry (true/false)
  • URL_PREFIX: Path at which the console is running
  • DATA_API_URL: The Hasura GraphQL engine url. (If you are running it on Heroku, it will look like <app-name>.herokuapp.com, if you are running locally, it will look like http://localhost:<port>)
  • SERVER_VERSION: Hasura GraphQL Engine server version
  • CONSOLE_MODE: In cli mode, it should be cli
  • ADMIN_SECRET: the admin secret passed via the CLI

Here's an example .env file for cli mode:

NODE_ENV=development
PORT=3000
API_HOST=http://localhost
API_PORT=9693
CDN_ASSETS=true
ASSETS_PATH=https://graphql-engine-cdn.hasura.io/console/assets
ASSETS_VERSION=channel/stable/v1.0
ENABLE_TELEMETRY=true
URL_PREFIX=/
DATA_API_URL=http://localhost:8080
SERVER_VERSION=v1.0.0
CONSOLE_MODE=cli
ADMIN_SECRET=my-admin-secret
Run console development server:

This setup requires a Hasura CLI console server to be running.

Start Hasura CLI console server

Start Hasura CLI console with the same Hasura GraphQL engine url as configured for DATA_API_URL.

hasura console --endpoint <DATA_API_URL> --admin-secret <your-admin-secret> (optional)
Start development console server
npm run dev

Check out the console

Visit http://localhost:3000 to confirm the setup.

Testing Development Server

Make changes to the code

Make changes to the code and the console will reload automatically to reflect the new changes. Keep iterating. When adding a new feature, it is recommended to add corresponding tests too.

Tests are written using Cypress.

You can use the Redux DevTools Extension to inspect and debug the Redux store. It should automatically connect to the Redux store when started in development mode.

By default redux-logger is enabled to assist in development. You can disable it if you wish by commenting out the createLogger line in src/client.js

Run tests

  • Run tests: npm run cypress
  • Write your tests in the cypress directory, integration.

Submitting a pull request

  • All the development work happens in your own fork of the graphql-engine.
  • Make sure your commit messages meet the guidelines.
  • Once the changes are done, create a pull request.
  • CI configured for PR will run the test suite.
  • Once everything goes well, it will generate a preview Heroku app.
  • The source code and the preview app will be reviewed by maintainers.