{"id":20331877,"url":"https://github.com/grafbase/gateway-hooks-demo","last_synced_at":"2025-09-23T02:31:53.638Z","repository":{"id":250275759,"uuid":"833757196","full_name":"grafbase/gateway-hooks-demo","owner":"grafbase","description":"Async http requests and logging with hooks","archived":true,"fork":false,"pushed_at":"2024-07-30T08:22:04.000Z","size":133,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-08-17T00:33:06.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grafbase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-25T17:23:43.000Z","updated_at":"2025-01-07T08:35:14.000Z","dependencies_parsed_at":"2024-07-29T12:43:59.500Z","dependency_job_id":"c555b7f9-8188-4021-a822-addaaef492a5","html_url":"https://github.com/grafbase/gateway-hooks-demo","commit_stats":null,"previous_names":["grafbase/gateway-hooks-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/grafbase/gateway-hooks-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafbase%2Fgateway-hooks-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafbase%2Fgateway-hooks-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafbase%2Fgateway-hooks-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafbase%2Fgateway-hooks-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grafbase","download_url":"https://codeload.github.com/grafbase/gateway-hooks-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafbase%2Fgateway-hooks-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276503589,"owners_count":25653915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T20:23:57.619Z","updated_at":"2025-09-23T02:31:53.545Z","avatar_url":"https://github.com/grafbase.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gateway hooks example\n\nIn this example we will use the gateway hooks to change the behavior of the gateway. This repository contains the following:\n\n- `subgraph`: a GraphQL server exposing a few users\n- `auth-service`: a HTTP service imitating an authorization endpoint to grant access to some data.\n- `federated-schema.graphql`: the federated GraphQL schema generated with the `subgraph`.\n- `grafbase.toml`: the configuration for the Grafbase Gateway`\n\n## Setup\n\n### Dependencies\n\nTo run this example, you need the Grafbase Gateway version 0.4.0 or later, read more how to install it from:\n\nhttps://grafbase.com/docs/self-hosted-gateway\n\nAdditionally, the following tools are needed:\n\n- A C compiler, such as clang together with pkg-config (install based on your system, `cc` command is required)\n- If on Linux, cargo-component depends on OpenSSL (`libssl-dev` on Debian)\n- Rust compiler ([install docs](https://www.rust-lang.org/learn/get-started))\n- Cargo component ([install docs](https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#installation))\n- A GraphQL client, such as [Altair](https://altair-gql.sirmuel.design/)\n\nFor the advanced users using nix with flakes support:\n\n```\nnix develop\n```\n\n### Running the example\n\nFirst, start the subgraph in one terminal:\n\n```bash\ncd subgraph\ncargo run --release\n```\n\nThen the authorization service:\n\n```sh\ncd auth-service\ncargo run --release\n```\n\nNext compile the WebAssembly hook functions into a Wasm component in another terminal:\n\n```bash\ncd hooks\ncargo component build --release\n```\n\nAfter a successful build, the Wasm component should be located at `target/wasm32-wasip1/release/demo_hooks.wasm`.\n\nFinally start the `grafbase-gateway`:\n\n```bash\ngrafbase-gateway --schema federated-schema.graphql --config grafbase.toml\n```\n\nNow you are ready to send queries!\n\n## Design\n\nThe hooks implement the following authorization rules:\n\n1. An user with id N can see all users with an ID equal or inferior to N: User 3 can see users 1, 2 and 3 but not 4\n2. An admin can see the list of all users (header `x-role: admin`)\n3. The address is only available to the user himself\n\nThe header `x-current-user-id` determines the current user id and `x-role` defines the role.\n\n### Examples\n\nCan not access any user data:\n\n```sh\ncurl -X POST http://127.0.0.1:5000/graphql \\\n    --data '{\"query\": \"query { user(id: 1) { name } }\"}' \\\n    -H 'Content-Type: application/json'\n```\n\nCan access one's own data:\n\n```sh\ncurl -X POST http://127.0.0.1:5000/graphql \\\n    --data '{\"query\": \"query { user(id: 3) { name address { street } } }\"}' \\\n    -H 'Content-Type: application/json' \\\n    -H 'x-current-user-id: 2'\n```\n\nCan access user name from 1 \u0026 2, but not 3 \u0026 4, and only its own address:\n\n```sh\ncurl -X POST http://127.0.0.1:5000/graphql \\\n    --data '{\"query\": \"query { users { name address { street } } }\"}' \\\n    -H 'Content-Type: application/json' \\\n    -H 'x-current-user-id: 2'\n```\n\nCan access all user names, but only its own address:\n\n```sh\ncurl -X POST http://127.0.0.1:5000/graphql \\\n    --data '{\"query\": \"query { users { name address { street } } }\"}' \\\n    -H 'Content-Type: application/json' \\\n    -H 'x-current-user-id: 2' \\\n    -H 'x-role: admin'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrafbase%2Fgateway-hooks-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrafbase%2Fgateway-hooks-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrafbase%2Fgateway-hooks-demo/lists"}