### Run Hive Gateway Example Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.docker.md This command starts the GraphQL Hive Gateway example. It assumes Node.js and npm are installed. The gateway will be accessible at http://localhost:4000. ```bash npm start ``` -------------------------------- ### Start Subgraphs with npm Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md This command starts all the subgraphs defined in the project. It's a prerequisite for running the Hive Gateway. ```sh npm run start:subgraphs ``` -------------------------------- ### Start Hive Gateway with npm Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md This command starts the Hive Gateway. Ensure subgraphs are running before executing this command. It loads the supergraph configuration from './supergraph.graphql'. ```sh npm run start ``` -------------------------------- ### Hive Gateway Terminal Output Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md This is the expected output in the terminal when the Hive Gateway starts successfully. It indicates the server is running on http://0.0.0.0:4000. ```sh Hive Gateway 💡 Searching for default config files Hive Gateway 💡 Loaded config file Hive Gateway 💡 Loading Supergraph from ./supergraph.graphql Hive Gateway ⚠️ If you want to enable hot reloading when ./supergraph.graphql changes, install "@parcel/watcher" Hive Gateway 💡 Starting server on http://0.0.0.0:4000 ``` -------------------------------- ### Set Environment Variables for Hive Gateway Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md This section provides examples of how to set environment variables for the Hive Gateway to connect to Hive's hosted Supergraph source. This can be done via a .env file or inline commands. ```sh # gateway/.env HIVE_REGISTRY_TOKEN=YOUR_VALUE HIVE_CDN_ENDPOINT=YOUR_VALUE HIVE_CDN_KEY=YOUR_VALUE ``` ```sh HIVE_REGISTRY_TOKEN=YOUR_VALUE \ HIVE_CDN_ENDPOINT=YOUR_VALUE \ HIVE_CDN_KEY=YOUR_VALUE \ npm run start ``` -------------------------------- ### Fetch Supergraph using curl Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md This snippet demonstrates how to fetch the composed Supergraph SDL from Hive's CDN using a curl command. It requires a Hive CDN token and the CDN endpoint. ```sh curl -L -H "X-Hive-CDN-Key: YOUR_HIVE_CDN_TOKEN" CDN_ENDPOINT_HERE ``` -------------------------------- ### Publish Users Subgraph Schema Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md Publishes the 'users' subgraph schema to the Hive registry using the Hive CLI. Requires an access token and specifies service name, URL, author, commit message, and the schema file path. ```sh hive schema:publish \ --registry.accessToken YOUR_TOKEN_HERE \ --service="users" \ --url="http://localhost/4001/graphql" \ --author "Me" \ --commit "First" \ subgraphs/users/typeDefs.graphql ``` -------------------------------- ### Check Comments Subgraph Schema (No Changes) Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md Performs a schema check on the 'comments' subgraph using the Hive CLI to verify if there are any changes compared to the deployed schema. It requires an access token and the schema file path. ```sh hive schema:check \ --registry.accessToken YOUR_TOKEN_HERE \ --service="comments" \ subgraphs/comments/typeDefs.graphql ``` -------------------------------- ### Configure Gateway to poll Supergraph from Hive Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md This TypeScript code shows how to configure the GraphQL Hive Gateway to poll for Supergraph updates from Hive. It replaces the local supergraph file configuration with a polling interval. ```typescript import { defineConfig } from '@graphql-hive/gateway' export const serveConfig = defineConfig({ polling: 10000 }) ``` -------------------------------- ### Comments Subgraph Schema with Added Field Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md Defines a non-breaking change in the 'comments' subgraph by adding a new field 'createdAt' to the 'User' type. This is used to demonstrate Hive's ability to detect non-breaking schema modifications. ```graphql # subgraphs/comments/typeDefs.graphql type Comment @key(fields: "id") { id: ID! text: String! author: User! } type User @key(fields: "id") { id: ID! comments: [Comment!]! # new field createdAt: String } type Query { comments: [Comment] } ``` -------------------------------- ### User 2 Flow: ReadComments and ReadUsersName Roles Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.docker.md This Mermaid diagram depicts the flow for User 2, who has both 'ReadComments' and 'ReadUsersName' roles. This allows the user to successfully query comments and user names, as the flow reaches the 'Users' subgraph for name resolution. ```mermaid flowchart LR 1(["End-user"]) --->|"query { comments { id author { id name }}}"| 2 3--->7["Remote JWKS"] subgraph Hive Gateway 2["Gateway Engine"] 3["JWT Plugin"] 4["Query Planner"] 2--->|"Bearer XYZ"|3 3--->|"{ sub: 2, roles: ["ReadComments", "ReadUsersNames"] }"|2 2--->4 end subgraph "Users" 5["Yoga Engine"] 5--->9["validateHMAC"] 5--->10["extractJWT"] 4--->|"X-HMAC-Signature: AbC\nquery: query { _entities(representations: $r) { ... on User { name }} }\nextensions: { jwt: { sub: 2, roles: ["ReadComments", "ReadUsersNames"] }}"|5 end subgraph "Comments" 6["Yoga Engine"] 6--->8["validateHMAC"] 4--->|"X-HMAC-Signature: XyZ\nquery: query { comments { id author { id }} }\nextensions: { jwt: { sub: 123, sub: 2, roles: ["ReadComments", "ReadUsersNames"] }}"|6 end ``` -------------------------------- ### Check Comments Subgraph Schema (Non-Breaking Change) Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md Performs a schema check on the modified 'comments' subgraph schema (with an added field) using the Hive CLI. This demonstrates Hive's detection of non-breaking schema changes. ```sh hive schema:check \ --registry.accessToken YOUR_TOKEN_HERE \ --service="comments" \ subgraphs/comments/typeDefs.graphql ``` -------------------------------- ### User 1 Flow: ReadComments Role Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.docker.md This Mermaid diagram illustrates the flow for User 1, who has the 'ReadComments' role. The query for user names is blocked due to insufficient permissions, as indicated by the flow not reaching the 'Users' subgraph for name resolution. ```mermaid flowchart LR 1(["End-user"]) --->|"query { comments { id author { id name }}}"| 2 3--->7["Remote JWKS"] subgraph Hive Gateway 2["Gateway Engine"] 3["JWT Plugin"] 4["Query Planner"] 2--->|"Bearer XYZ"|3 3--->|"{ sub: 1, roles: ["ReadComments"] }"|2 2--->4 end subgraph "Comments" 6["Yoga Engine"] 6--->8["validateHMAC"] 4--->|"X-HMAC-Signature: XyZ\nquery: query { comments { id author { id }} }\nextensions: { jwt: { sub: 1, roles: ["ReadComments"] }}"|6 end ``` -------------------------------- ### Publish Comments Subgraph Schema Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md Publishes the 'comments' subgraph schema to the Hive registry using the Hive CLI. Requires an access token and specifies service name, URL, author, commit message, and the schema file path. ```sh hive schema:publish \ --registry.accessToken YOUR_TOKEN_HERE \ --service="comments" \ --url="http://localhost/4002/graphql" \ --author "Me" \ --commit "First" \ subgraphs/comments/typeDefs.graphql ``` -------------------------------- ### Check Comments Subgraph Schema (Breaking Change) Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md Performs a schema check on the 'comments' subgraph schema with a breaking change (renamed field) using the Hive CLI. This demonstrates Hive's detection of breaking schema changes. ```sh hive schema:check \ --registry.accessToken YOUR_TOKEN_HERE \ --service="comments" \ subgraphs/comments/typeDefs.graphql ``` -------------------------------- ### Comments Subgraph Schema with Renamed Field (Breaking Change) Source: https://github.com/graphql-hive/hive-gateway-example/blob/main/README.md Defines a breaking change in the 'comments' subgraph by renaming the 'comments' field to 'newComments' in the 'User' type. This is used to demonstrate Hive's detection of breaking schema modifications. ```graphql # subgraphs/comments/typeDefs.graphql extend type User @key(fields: "id") { id: ID! @external # renamed field newComments: [Comment!]! } type Comment @key(fields: "id") { id: ID! text: String! author: User! } type Query { comments: [Comment] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.