mirror of
https://github.com/hasura/graphql-engine.git
synced 2025-01-07 08:13:18 +03:00
docs: update getting-started docker
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7146 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Sean Park-Ross <94021366+seanparkross@users.noreply.github.com> GitOrigin-RevId: 7e5a35d3a9f78ab10feafdcfe6549eda6f033f90
This commit is contained in:
parent
24cba66344
commit
23e232eedd
@ -15,74 +15,48 @@ import Thumbnail from '@site/src/components/Thumbnail';
|
|||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
This guide will help you get the Hasura GraphQL Engine and a Postgres database to store its Metadata running as Docker
|
This guide will help you get up and running quickly with the Hasura GraphQL Engine and a Postgres database running as
|
||||||
containers using Docker Compose. This is the easiest way to set up Hasura GraphQL Engine on your **local environment**.
|
Docker containers using Docker Compose.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
You'll need to have Docker installed in order to run the container. Check out
|
- [Docker](https://docs.docker.com/install/) installed and running.
|
||||||
[the Docker documentation](https://docs.docker.com/install/) for instructions.
|
|
||||||
|
|
||||||
## Step 1: Get the docker-compose file
|
## Step 1: Get the Compose file & start the containers
|
||||||
|
|
||||||
The [hasura/graphql-engine/install-manifests](https://github.com/hasura/graphql-engine/tree/stable/install-manifests)
|
Get the Compose file from our repo. If you're using curl, run this command in a new directory:
|
||||||
repo contains all installation manifests required to deploy Hasura anywhere. Get the docker compose file from there:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# in a new directory run
|
|
||||||
wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml
|
|
||||||
# or run
|
|
||||||
curl https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml -o docker-compose.yml
|
curl https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml -o docker-compose.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 2: Run Hasura GraphQL Engine
|
If you're using wget, run this command in a new directory:
|
||||||
|
|
||||||
The following command will run Hasura GraphQL Engine along with a Postgres database to store its Metadata.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker compose up -d
|
wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
Check if the containers are running:
|
Then, run the following command to start both the Hasura GraphQL Engine and the Postgres database in Docker containers:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker ps
|
docker compose up -d
|
||||||
|
|
||||||
CONTAINER ID IMAGE ... CREATED STATUS PORTS ...
|
|
||||||
097f58433a2b hasura/graphql-engine ... 1m ago Up 1m 8080->8080/tcp ...
|
|
||||||
b0b1aac0508d postgres ... 1m ago Up 1m 5432/tcp ...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 3: Connect a database
|
## Step 2: Connect a database
|
||||||
|
|
||||||
Head to `http://localhost:8080/console` to open the Hasura Console.
|
Open the Hasura Console by navigating to `http://localhost:8080/console`. From the Console, click the `Data` tab:
|
||||||
|
|
||||||
Navigate to `Data -> Manage -> Connect Database`:
|
|
||||||
|
|
||||||
<Thumbnail src="/img/getting-started/connect-db-console.png" alt="Connect database" width="1000px" />
|
<Thumbnail src="/img/getting-started/connect-db-console.png" alt="Connect database" width="1000px" />
|
||||||
|
|
||||||
Enter your database connection URL. _(See the note below if you do not have an existing database)_
|
Select the `Environment Variable` option and enter `PG_DATABASE_URL` as the environment variable name:
|
||||||
|
|
||||||
|
<Thumbnail src="/img/getting-started/connect-db-env-var.png" alt="Enter URL for existing database" width="1000px" />
|
||||||
|
|
||||||
Click `Connect Database`.
|
Click `Connect Database`.
|
||||||
|
|
||||||
<Thumbnail src="/img/getting-started/connect-db-core.png" alt="Enter URL for existing database" width="700px" />
|
## Step 3: Try out Hasura
|
||||||
|
|
||||||
:::info Starting from scratch
|
### Create a table and insert some demo data
|
||||||
|
|
||||||
If you are looking to start setting up a backend from scratch, we recommend using Postgres as the database.
|
|
||||||
|
|
||||||
If you do not have an existing Postgres database, you can choose to connect to the Postgres database that was created
|
|
||||||
along with Hasura (to store its metadata) and use it as a data source as well. The docker-compose file has an additional
|
|
||||||
env var `PG_DATABASE_URL` which points to the created Metadata database. You can use this env var to connect the same
|
|
||||||
database as a data source and continue.
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
## Step 4: Try out Hasura
|
|
||||||
|
|
||||||
<!-- TODO: add options to track existing vs create new tables -->
|
|
||||||
|
|
||||||
### Create a table
|
|
||||||
|
|
||||||
On the Hasura Console, navigate to `Data -> Create table` and create a sample table called `profiles` with the following
|
On the Hasura Console, navigate to `Data -> Create table` and create a sample table called `profiles` with the following
|
||||||
columns:
|
columns:
|
||||||
@ -115,56 +89,63 @@ You'll see that you get all the inserted data!
|
|||||||
|
|
||||||
<Thumbnail src="/img/getting-started/profile-query.png" alt="Try out a query" width="1200px" />
|
<Thumbnail src="/img/getting-started/profile-query.png" alt="Try out a query" width="1200px" />
|
||||||
|
|
||||||
## Next steps
|
## Recap
|
||||||
|
|
||||||
### Learn tutorial
|
What did we just do? Well, you just created a powerful, full-featured GraphQL API in less than five minutes. 🎉
|
||||||
|
|
||||||
For a full hands-on tour of Hasura, check out our
|
We started two Docker containers - one for the Hasura GraphQL Engine and one for the Postgres database. In this example,
|
||||||
[30-Minute Hasura Basics Tutorial](https://hasura.io/learn/graphql/hasura/introduction/).
|
our Postgres database also contains the [Hasura Metadata](/migrations-metadata-seeds/manage-metadata.mdx); which is how
|
||||||
|
Hasura records its information about the GraphQL schema, the relationships between tables, and much more. Finally, we
|
||||||
|
connected our Postgres database to the Hasura GraphQL Engine, which allowed Hasura Engine to automatically create a full
|
||||||
|
CRUD GraphQL API for our Postgres database which we could then easily query, mutate and subscribe to.
|
||||||
|
|
||||||
### Stay up to date
|
:::info Important: Set up the Hasura CLI
|
||||||
|
|
||||||
We release new features every month. Sign up for our newsletter by using the link below. We send newsletters only once a
|
The Hasura CLI is a powerful tool that helps you manage your Hasura project and is recommended for the majority of
|
||||||
month. <https://hasura.io/newsletter/>.
|
development workflows. It helps track and manage your
|
||||||
|
[Hasura Metadata and Migrations](/migrations-metadata-seeds/index.mdx) and commit them to version control and allows you
|
||||||
### Security Announcements
|
to quickly move between environments like development and production.
|
||||||
|
|
||||||
Join the [Hasura Security Announcements](https://groups.google.com/forum/#!forum/hasura-security-announce) group for
|
|
||||||
emails about security announcements.
|
|
||||||
|
|
||||||
### Database operations
|
### Database operations
|
||||||
|
|
||||||
- [Database modeling](/schema/postgres/index.mdx): Learn how to model your database schema, as well as how to extend it.
|
We omitted the CLI steps in this guide for the sake of simplicity and brevity, but in a typical new project, you would
|
||||||
- [Querying data](/queries/postgres/index.mdx): Use GraphQL queries to query data from your GraphQL API.
|
always include the CLI setup steps.
|
||||||
- [Inserting data](/mutations/postgres/index.mdx): Use GraphQL mutations to insert data into your GraphQL API.
|
|
||||||
|
|
||||||
### Business logic
|
Every developer working with Hasura should have the Hasura CLI installed. You can do so by
|
||||||
|
[following this guide](/hasura-cli/install-hasura-cli.mdx) and learn more by checking out our
|
||||||
|
[Advanced Hasura course](https://hasura.io/learn/graphql/hasura-advanced/introduction/).
|
||||||
|
|
||||||
There are several options for the implementation of business logic, depending on your use case.
|
:::
|
||||||
|
|
||||||
|
## Next steps
|
||||||
|
|
||||||
|
- If you're interested in taking a deep dive into Hasura, check out our hands-on
|
||||||
|
[30-Minute Hasura Basics Tutorial](https://hasura.io/learn/graphql/hasura/introduction/).
|
||||||
|
|
||||||
|
- There are several options for the implementation of business logic, depending on your use case.
|
||||||
|
|
||||||
- [Actions](/actions/index.mdx): Actions can be used if you'd like to extend your GraphQL schema by integrating with a
|
- [Actions](/actions/index.mdx): Actions can be used if you'd like to extend your GraphQL schema by integrating with a
|
||||||
REST endpoint.
|
REST endpoint.
|
||||||
- [Remote Schemas](/remote-schemas/index.mdx): If you have an existing GraphQL server or if you're comfortable with
|
- [Remote Schemas](/remote-schemas/index.mdx): If you have an existing GraphQL server or if you're comfortable with
|
||||||
implementing one, you can use Remote Schemas.
|
implementing one, you can use Remote Schemas.
|
||||||
- [Event Triggers](/event-triggers/index.mdx): To trigger a serverless function based on a database event, use event
|
- [Event Triggers](/event-triggers/index.mdx): To trigger a serverless function based on a database event, use Event
|
||||||
triggers.
|
Triggers.
|
||||||
- [Scheduled Triggers](/scheduled-triggers/index.mdx): Scheduled Triggers are used to execute custom business logic at
|
- [Scheduled Triggers](/scheduled-triggers/index.mdx): Scheduled Triggers are used to execute custom business logic at
|
||||||
specific points in time.
|
specific points in time.
|
||||||
|
|
||||||
### Migrations
|
- If you're new to database modeling, check out these guides:
|
||||||
|
|
||||||
Set up [Hasura Migrations](/migrations-metadata-seeds/migrations-metadata-setup.mdx) to track your database alterations.
|
- [Database modeling](/schema/postgres/index.mdx): Learn how to model your database schema, as well as how to extend
|
||||||
This will make it easier to move to a different environment (e.g. staging or prod) later.
|
it.
|
||||||
|
- [Querying data](/queries/postgres/index.mdx): Use GraphQL queries to query data from your GraphQL API.
|
||||||
|
- [Inserting data](/mutations/postgres/index.mdx): Use GraphQL mutations to insert data into your GraphQL API.
|
||||||
|
|
||||||
### Secure your endpoint
|
- **Security Announcements**: Join the [Hasura Security Announcements](https://groups.google.com/forum/#!forum/hasura-security-announce) group for
|
||||||
|
emails about security announcements.
|
||||||
|
|
||||||
[Add an admin secret](/deployment/deployment-guides/docker.mdx#docker-secure) to make sure that your GraphQL endpoint
|
|
||||||
and the Hasura Console are not publicly accessible.
|
|
||||||
|
|
||||||
## Detailed Docker setup
|
- We release new features every month. Sign up for our newsletter by using the link below. We send newsletters only once
|
||||||
|
a month. <https://hasura.io/newsletter/>.
|
||||||
This was a quickstart guide to get the Hasura GraphQL Engine up and running quickly. For more detailed instructions on
|
|
||||||
deploying using Docker, check out [Run Hasura GraphQL Engine using Docker](/deployment/deployment-guides/docker.mdx).
|
|
||||||
|
|
||||||
:::info Additional Resources
|
:::info Additional Resources
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 79 KiB |
BIN
docs/static/img/getting-started/connect-db-env-var.png
vendored
Normal file
BIN
docs/static/img/getting-started/connect-db-env-var.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 149 KiB |
Loading…
Reference in New Issue
Block a user