Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kevinmichaelchen/hasura-n-plus-one-remote-rel
A Hasura demo showing the N+1 problem with Remote Relationships
https://github.com/kevinmichaelchen/hasura-n-plus-one-remote-rel
Last synced: about 2 months ago
JSON representation
A Hasura demo showing the N+1 problem with Remote Relationships
- Host: GitHub
- URL: https://github.com/kevinmichaelchen/hasura-n-plus-one-remote-rel
- Owner: kevinmichaelchen
- Created: 2024-06-18T11:30:36.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-25T22:40:19.000Z (7 months ago)
- Last Synced: 2024-07-10T14:31:30.984Z (6 months ago)
- Language: Go
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hasura-n-plus-one-remote-rel
This demo shows the N+1 problem in Hasura when using Remote Relationships
(“remote joins”).## Getting started
### Step 0: Prerequisites
1. Docker
1. [pkgx](https://pkgx.sh/)
1. install with … `sudo rm -rf $(which pkgx) ; curl -fsS https://pkgx.sh | sh`
1. A Hasura Pro Key to see traces [locally in Jaeger](http://localhost:16686)
1. `export HASURA_GRAPHQL_PRO_KEY=foobar`### Step 1: Run everything
```shell
make
```### Step 2: Create some data
```graphql
mutation SeedData {
owners: insertOwner(
objects: [
{ name: "Gravy", pets: { data: { name: "Porkchop" } } }
{ name: "Blueberry", pets: { data: { name: "Oatmeal" } } }
]
) {
returning {
id
name
pets {
id
name
}
}
}
}
```### Step 3: Query remote schemas
```graphql
query GetStuff {
owners: owner {
id
nickname
pets {
id
nickname
}
}
}
```## What's the problem?
Here, we are requesting multiple owners, and for each owner, we are requesting
their pet. Each `nickname` field is an HTTP call to our Nickname service. These
calls aren't batched.This is the `N + 1` problem (or `1 + N` problem, if you prefer). Hasura will
make one call for the owners, and then N calls for each of their nicknames.**There is no batching happening!**
## How to solve?
Hasura needs to support batching, similar to [how Tailcall does][tailcall].
[tailcall]:
https://tailcall.run/docs/graphql-n-plus-one-problem-solved-tailcall/#batch-apis