### Install @whatwg-node/server Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/performance/compression Install the necessary package for the content encoding plugin. ```sh npm i @whatwg-node/server ``` -------------------------------- ### Install Gateway Testing Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/testing/gateway-tester Install the package as a development dependency. ```bash npm i -D @graphql-hive/gateway-testing ``` -------------------------------- ### Start Hive Router Binary Source: https://the-guild.dev/graphql/hive/docs/schema-registry/get-started/apollo-federation Execute this command in your terminal after installing the Hive Router binary to start the gateway. Ensure the configuration file is accessible. ```sh ./hive-router ``` -------------------------------- ### Setup OpenTelemetry with Node.js SDK Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Initialize and start the OpenTelemetry Node.js SDK with custom limits. This is an alternative for direct Node.js applications. ```typescript import { NodeSDK } from "@opentelemetry/sdk-node"; new NodeSDK({ generalLimits: { //... }, spanLimits: { //... }, }).start(); ``` -------------------------------- ### Endpoint Configuration Examples Source: https://the-guild.dev/graphql/hive/docs/new-laboratory/environment-variables Configure different API endpoints for various environments. This example shows settings for development and production. ```bash # Development DEV_ENDPOINT=http://localhost:4000/graphql # Production PROD_ENDPOINT=https://api.example.com/graphql ``` -------------------------------- ### Install @graphql-mesh/plugin-mock Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/testing/mocking Install the necessary package for mocking your GraphQL API. ```sh npm i @graphql-mesh/plugin-mock ``` -------------------------------- ### Install Pino and Hive Logger Dependencies Source: https://the-guild.dev/graphql/hive/docs/gateway/logging-and-error-handling Install the required peer dependencies for Pino logging. ```bash npm i pino pino-pretty ``` ```bash npm i @graphql-hive/logger ``` -------------------------------- ### Install APQ plugin Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/performance/automatic-persisted-queries Install the required package for Hive Gateway. ```sh npm i @graphql-yoga/plugin-apq ``` -------------------------------- ### Example .env File Configuration Source: https://the-guild.dev/graphql/hive/docs/new-laboratory/environment-variables This example demonstrates a typical .env file structure with API configuration, environment settings, and URLs. Comments are used to explain each section. ```bash # API Configuration API_KEY=sk_live_1234567890 API_SECRET=secret_abc123 # Environment ENV=production DEBUG=false # URLs BASE_URL=https://api.example.com GRAPHQL_ENDPOINT=/graphql ``` -------------------------------- ### Example CORS Configuration Source: https://the-guild.dev/graphql/hive/docs/router/configuration/cors A comprehensive example demonstrating how to configure CORS with various options and policies. ```APIDOC ## Example CORS Configuration ```yaml title="router.config.yaml" cors: enabled: true allow_credentials: false # Default for all origins methods: ["GET", "POST", "OPTIONS"] allow_headers: ["Content-Type", "Authorization"] policies: # Production website - origins: - https://my-app.com - https://www.my-app.com # Local development - origins: - http://localhost:3000 - http://localhost:3001 allow_credentials: true # Override for development # Partner domains with special access - match_origin: - "^https://.*\\.partner\\.com$" allow_credentials: true allow_headers: ["Content-Type", "Authorization", "X-Custom-Header"] ``` ``` -------------------------------- ### GraphQL Yoga HTTP and WebSocket Setup Source: https://the-guild.dev/graphql/hive/docs/other-integrations/graphql-yoga This TypeScript example demonstrates setting up a GraphQL Yoga server with GraphQL Hive integration for both HTTP and WebSocket connections. It requires Node.js and the specified npm packages. ```typescript import { createServer } from "node:http"; import { useServer } from "graphql-ws/lib/use/ws"; import { createYoga } from "graphql-yoga"; import { WebSocketServer } from "ws"; import { useHive } from "@graphql-hive/yoga"; import { schema } from "./schema"; const yoga = createYoga({ schema, graphiql: { subscriptionsProtocol: "WS", }, plugins: [ useHive({ enabled: true, token: "YOUR-TOKEN", usage: { target: "//", }, }), ], }); const httpServer = createServer(yoga); const wsServer = new WebSocketServer({ server: httpServer, path: yoga.graphqlEndpoint, }); useServer( { execute: (args: any) => args.rootValue.execute(args), subscribe: (args: any) => args.rootValue.subscribe(args), onSubscribe: async (ctx, msg) => { const { schema, execute, subscribe, contextFactory, parse, validate } = yoga.getEnveloped({ ...ctx, req: ctx.extra.request, socket: ctx.extra.socket, params: msg.payload, }); const args = { schema, operationName: msg.payload.operationName, document: parse(msg.payload.query), variableValues: msg.payload.variables, contextValue: await contextFactory(), rootValue: { execute, subscribe, }, }; const errors = validate(args.schema, args.document); if (errors.length) return errors; return args; }, }, wsServer, ); httpServer.listen(4000, () => { console.log("Server is running on port 4000"); }); ``` -------------------------------- ### Install OTLP gRPC Exporter Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Install the OTLP gRPC exporter package. ```bash npm i @opentelemetry/exporter-trace-otlp-grpc ``` -------------------------------- ### Install Character Limit Plugin Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/security/character-limit Install the required package via npm or yarn. ```bash npm install @escape.tech/graphql-armor-character-limit ``` -------------------------------- ### Production Logging Example Source: https://the-guild.dev/graphql/hive/docs/router/configuration/log Example configuration for production environments, using 'info' level and 'json' format for machine readability. ```APIDOC ## Production Logging Example ### Description Configures the router for production with informational logs in JSON format. ### Configuration ```yaml log: level: "info" format: "json" ``` ``` -------------------------------- ### Install Router Runtime Package Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/rust-query-planner Install the necessary package for integrating the Rust Query Planner into Hive Gateway. ```sh npm install @graphql-hive/router-runtime ``` -------------------------------- ### Install Hive Logger Source: https://the-guild.dev/graphql/hive/docs/logger Install the package using npm. ```sh npm i @graphql-hive/logger ``` -------------------------------- ### Install graphql-ws Client (npm/yarn) Source: https://the-guild.dev/graphql/hive/docs/router/subscriptions/websockets Command to install the `graphql-ws` client library, recommended for managing WebSocket connections on the client side. ```sh npm install graphql-ws ``` -------------------------------- ### Install Hive CLI via NodeJS Source: https://the-guild.dev/graphql/hive/docs/schema-registry/get-started/first-steps Recommended for JavaScript/NodeJS projects by installing as a devDependency. ```bash npm i -D @graphql-hive/cli ``` ```bash npx hive --version ``` -------------------------------- ### Development Logging Example Source: https://the-guild.dev/graphql/hive/docs/router/configuration/log Example configuration for development environments, using 'debug' level and 'pretty-compact' format for human readability. ```APIDOC ## Development Logging Example ### Description Configures the router for development with debug logs in a human-readable format. ### Configuration ```yaml log: level: "debug" format: "pretty-compact" ``` ``` -------------------------------- ### Install Pino Logger dependencies Source: https://the-guild.dev/graphql/hive/docs/logger/writers Install the required peer dependencies for the Pino log writer. ```bash npm i pino pino-pretty ``` -------------------------------- ### Install Official OpenTelemetry Node SDK Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Install the official OpenTelemetry Node.js SDK and an HTTP OTLP exporter. ```sh npm i @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-http ``` -------------------------------- ### Install Hive Envelop package Source: https://the-guild.dev/graphql/hive/docs/other-integrations/envelop Install the package as a direct dependency to enable runtime reporting. ```bash npm i @graphql-hive/envelop ``` -------------------------------- ### Install Winston and Hive Logger Dependencies Source: https://the-guild.dev/graphql/hive/docs/gateway/logging-and-error-handling Install the required peer dependencies for Winston logging. ```bash npm i winston ``` ```bash npm i @graphql-hive/logger ``` -------------------------------- ### Install Hive SDK for GraphQL Yoga Source: https://the-guild.dev/graphql/hive/docs/schema-registry/app-deployments Install the Hive SDK for GraphQL Yoga to enable persisted documents. ```bash npm i -D @graphql-hive/yoga ``` -------------------------------- ### Install Hive CLI via Binary Source: https://the-guild.dev/graphql/hive/docs/api-reference/cli Download and install the prebuilt binary for Hive CLI on different operating systems. ```sh curl -sSL https://graphql-hive.com/install.sh | sh ``` ```sh powershell -c "irm https://graphql-hive.com/install.ps1 | iex" ``` -------------------------------- ### Install Apollo Client Dependencies Source: https://the-guild.dev/graphql/hive/docs/router/subscriptions/multipart-http Install the necessary packages to use Apollo Client with GraphQL subscriptions. ```bash npm install @apollo/client graphql rxjs ``` -------------------------------- ### Install NestJS Packages Source: https://the-guild.dev/graphql/hive/docs/gateway/deployment/node-frameworks/nestjs Install the necessary packages for NestJS, Hive Gateway, and GraphQL using npm or yarn. ```sh npm i @nestjs/graphql @graphql-hive/nestjs graphql ``` -------------------------------- ### Install Hive Core Source: https://the-guild.dev/graphql/hive/docs/other-integrations/schema-stitching Install the core package as a direct dependency to enable runtime reporting and schema fetching. ```sh npm i @graphql-hive/core ``` ```yarn yarn add @graphql-hive/core ``` -------------------------------- ### Feature Flags Example Configuration Source: https://the-guild.dev/graphql/hive/docs/new-laboratory/environment-variables Control feature availability using boolean environment variables. This example shows flags for enabling analytics and beta features. ```bash ENABLE_ANALYTICS=true ENABLE_BETA_FEATURES=false ``` -------------------------------- ### Full Telemetry Configuration Example Source: https://the-guild.dev/graphql/hive/docs/router/configuration/telemetry A comprehensive example of telemetry configuration, including explicit histogram settings for seconds and bytes, and specific instrument configurations. ```yaml telemetry: metrics: instrumentation: common: histogram: aggregation: explicit seconds: buckets: [ "5ms", "10ms", "25ms", "50ms", "75ms", "100ms", "250ms", "500ms", "750ms", "1s", "2.5s", "5s", "7.5s", "10s", ] record_min_max: false bytes: buckets: [ "128B", "512B", "1KB", "2KB", "4KB", "8KB", "16KB", "32KB", "64KB", "128KB", "256KB", "512KB", "1MB", "2MB", "3MB", "4MB", "5MB", ] record_min_max: false instruments: http.server.request.duration: true http.client.request.duration: attributes: subgraph.name: true http.response.status_code: true server.address: false ``` -------------------------------- ### API Keys Example Configuration Source: https://the-guild.dev/graphql/hive/docs/new-laboratory/environment-variables Store sensitive API keys using environment variables. This example shows common keys for services like Stripe and GitHub. ```bash STRIPE_API_KEY=sk_live_... GITHUB_TOKEN=ghp_... ``` -------------------------------- ### Install Max Aliases Plugin Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/security/max-aliases Install the Max Aliases plugin using npm or yarn. This is the first step before configuring it in your gateway. ```sh npm install @escape.tech/graphql-armor-max-aliases ``` -------------------------------- ### onEnveloped Hook Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/custom-plugins Called at the start of the GraphQL execution pipeline, useful for setup tasks before execution begins. ```APIDOC ## Hook: onEnveloped ### Description This hook is called once per operation, at the start of the GraphQL execution pipeline. It is useful for performing setup tasks immediately before the execution flow. ### Payload Fields - **setSchema** (Function) - Sets the schema to be used. - **context** (Object) - The GraphQL context object. - **extendContext** (Function) - Extends the GraphQL context object with additional fields. ``` -------------------------------- ### Initialize Hive Router Entrypoint Source: https://the-guild.dev/graphql/hive/docs/router/guides/extending-the-router Set up the `src/main.rs` file to configure the global allocator, initialize TLS, and start the Hive Router with a new plugin registry. ```rust use hive_router::{ configure_global_allocator, RouterGlobalAllocator, error::RouterInitError, init_rustls_crypto_provider, router_entrypoint, PluginRegistry, }; // Configure the global allocator that's used by Hive Router configure_global_allocator!(); #[hive_router::main] async fn main() -> Result<(), RouterInitError> { // Configure TLS so your router will be able to make HTTPS requests // By default, Router is using the system's default certificate store. init_rustls_crypto_provider(); // Start the Hive Router with the plugin registry router_entrypoint(PluginRegistry::new()).await } ``` -------------------------------- ### Configure Official OpenTelemetry Node SDK Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Initialize and start the official OpenTelemetry Node.js SDK. This setup is compatible with Hive Gateway when used in a Node.js runtime. ```ts import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"; import { NodeSDK, resources, tracing } from "@opentelemetry/sdk-node"; new NodeSDK({ // All configuration is optional. OTEL rely on env variables or sensible default value. // Defines the exporter, HTTP OTLP most of the time. Traces are batched by default traceExporter: new OTLPTraceExporter({ url: process.env["OTLP_URL"] }), // Optional, enables automatic instrumentation, adding traces like network spans. instrumentations: getNodeAutoInstrumentations(), // Optional, enables automatic resource attributes detection resourceDetectors: getResourceDetectors(), }).start(); ``` ```ts import "./telemetry"; import { defineConfig } from "@graphql-hive/gateway"; export const gatewayConfig = defineConfig({ openTelemetry: { traces: true, }, }); ``` -------------------------------- ### Full HTTP Callback Configuration Example Source: https://the-guild.dev/graphql/hive/docs/router/subscriptions/http-callback An example demonstrating a full configuration for HTTP Callback, including a dedicated listener on port 4001, a specific path, heartbeat interval, and a list of subgraphs using the protocol. ```yaml subscriptions: enabled: true callback: public_url: https://router.internal:4001/callback listen: 0.0.0.0:4001 path: /callback heartbeat_interval: 5s subgraphs: - reviews - products ``` -------------------------------- ### Install GraphQL Armor Max Tokens Plugin Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/security/max-tokens Install the GraphQL Armor Max Tokens plugin using npm or yarn for advanced configuration options. ```bash npm install @escape.tech/graphql-armor-max-tokens ``` -------------------------------- ### Programmatic OpenTelemetry Setup with Gateway Runtime Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Integrate OpenTelemetry tracing into the GraphQL Hive Gateway programmatically using plugins. Install the necessary package and configure `useOpenTelemetry`. ```sh npm i @graphql-hive/plugin-opentelemetry ``` ```typescript import { createGatewayRuntime } from "@graphql-hive/gateway-runtime"; import { useOpenTelemetry } from "@graphql-hive/plugin-opentelemetry"; import { openTelemetrySetup } from "@graphql-hive/plugin-opentelemetry/setup"; openTelemetrySetup({ //... }); export const gateway = createGatewayRuntime({ plugins: (ctx) => [ useOpenTelemetry({ ...ctx, traces: true, }), ], }); ``` -------------------------------- ### Run Hive Router with Docker Source: https://the-guild.dev/graphql/hive/docs/schema-registry/get-started/apollo-federation This Docker command starts a Hive Router instance, mapping port 4000 and mounting your configuration file. Ensure Docker is installed and running. ```sh docker run \ --name hive-router -rm \ -p 4000:4000 \ -v ./router.config.yaml:/app/router.config.yaml \ ghcr.io/graphql-hive/router:latest ``` -------------------------------- ### Configure router headers Source: https://the-guild.dev/graphql/hive/docs/router/configuration/headers Example configuration demonstrating header propagation, insertion, and removal rules. ```yaml headers: all: request: # Forward the Authorization header to all subgraphs. - propagate: named: Authorization # Add a static header to all subgraph requests. - insert: name: X-Via-Router value: hive-router-v1 subgraphs: products: request: # Remove a legacy header only for the 'products' subgraph. - remove: named: X-Legacy-Product-ID ``` -------------------------------- ### Configure Query Planner Settings Source: https://the-guild.dev/graphql/hive/docs/router/configuration/query_planner This example shows how to enable query plan exposure for debugging and set a custom timeout for the query planning phase. Disable 'allow_expose' in production. ```yaml query_planner: allow_expose: true timeout: "5s" ``` -------------------------------- ### Install @graphql-hive/apollo Package Source: https://the-guild.dev/graphql/hive/docs/other-integrations/apollo-gateway Install the Hive client package for Apollo Gateway. It's recommended to install this as a direct dependency. ```sh npm i @graphql-hive/apollo ``` -------------------------------- ### Start Apollo Router via Binary Source: https://the-guild.dev/graphql/hive/docs/other-integrations/apollo-router Run the router binary with the necessary Hive environment variables. ```bash HIVE_TOKEN="..." \ HIVE_TARGET_ID= "..." \ HIVE_CDN_ENDPOINT="..." \ HIVE_CDN_KEY="..." \ ./router --config router.yaml ``` -------------------------------- ### Install Dependencies for GraphQL Yoga Federation Source: https://the-guild.dev/graphql/hive/docs/gateway/subscriptions Installs necessary packages for building GraphQL Yoga federation services. Ensure you have Node.js and npm/yarn installed. ```sh npm i graphql-yoga @apollo/subgraph graphql ``` -------------------------------- ### Create New Rust Project Source: https://the-guild.dev/graphql/hive/docs/router/guides/extending-the-router Initialize a new binary Rust project for your custom router. Ensure you have Rust installed. ```bash cargo new --bin my_custom_router cd my_custom_router ``` -------------------------------- ### Install Hive Gateway via Binary Source: https://the-guild.dev/graphql/hive/docs/gateway Downloads the appropriate binary for the host operating system. ```sh curl -sSL https://graphql-hive.com/install-gateway.sh | sh ``` -------------------------------- ### Install go-gqlhive package Source: https://the-guild.dev/graphql/hive/docs/other-integrations/gqlgen-go Use this command to add the Hive tracer dependency to your Go project. ```sh go get github.com/enisdenjo/go-gqlhive@v2 ``` -------------------------------- ### Develop and Deploy Custom Plugin Source: https://the-guild.dev/graphql/hive/docs/gateway/deployment/docker Demonstrates creating a custom timing plugin, configuring it, and packaging it within a Docker image. ```json { "name": "my-timing", "dependencies": { "moment": "^2" }, "devDependencies": { "@graphql-hive/gateway": "latest", "@graphql-hive/gateway": "latest" } } ``` ```ts import moment from "moment"; import type { GatewayPlugin } from "@graphql-hive/gateway"; export function useTiming(): GatewayPlugin { return { onExecute() { const start = Date.now(); return { onExecuteDone({ result, setResult }) { const duration = moment.duration(Date.now() - start); if (isAsyncIterable(result)) { setResult( mapAsyncIterator(result, (result) => ({ ...result, extensions: { ...result?.extensions, duration: duration.humanize(), }, })), ); return; } setResult({ ...result, extensions: { ...result?.extensions, duration: duration.humanize(), }, }); }, }; }, }; } ``` ```ts import { defineConfig } from "@graphql-hive/gateway"; import { useTiming } from "./my-timing"; export const gatewayConfig = defineConfig({ plugins: () => [useTiming()], }); ``` ```dockerfile FROM ghcr.io/graphql-hive/gateway # we dont install dev deps because: # 1. we need them for type checking only # 2. Hive Gateway is already available in the docker image COPY package*.json . RUN npm i --omit=dev COPY my-time.ts . COPY gateway.config.ts . ``` ```sh docker build -t hive-gateway-w-my-timing . ``` ```sh docker run -p 4000:4000 hive-gateway-w-my-timing supergraph ``` ```sh docker run -p 4000:4000 \ -v "$(pwd)/gateway.config.ts":/gateway/gateway.config.ts \ -v "$(pwd)/my-timing.ts":/gateway/my-timing.ts \ hive-gateway-w-my-timing supergraph ``` -------------------------------- ### Install NATS Dependencies Source: https://the-guild.dev/graphql/hive/docs/gateway/subscriptions Installs the required packages for NATS PubSub integration. ```bash npm i @graphql-hive/pubsub @nats-io/transport-node ``` -------------------------------- ### Install Sentry Dependencies Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Install the required Sentry packages for error and performance tracking. ```sh npm i @sentry/node @sentry/tracing @envelop/sentry ``` -------------------------------- ### Authentication Tokens Example Configuration Source: https://the-guild.dev/graphql/hive/docs/new-laboratory/environment-variables Manage authentication tokens securely with environment variables. This includes JWT tokens and session IDs. ```bash JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... SESSION_ID=abc123def456 ``` -------------------------------- ### Start Apollo Router Binary Source: https://the-guild.dev/graphql/hive/docs/other-integrations/apollo-router Run the Apollo Router binary after downloading it. Set the HIVE_CDN_ENDPOINT and HIVE_CDN_KEY environment variables to authenticate with the CDN. ```bash HIVE_CDN_ENDPOINT="..." \ HIVE_CDN_KEY="..." \ ./router ``` -------------------------------- ### Install OpenTelemetry Dependencies Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Install necessary OpenTelemetry packages for context management and trace exporting. ```sh npm i @opentelemetry/context-async-hooks @opentelemetry/exporter-trace-otlp-http ``` -------------------------------- ### Enable Subscriptions via Environment Variable Source: https://the-guild.dev/graphql/hive/docs/router/subscriptions Enable subscription support using an environment variable. ```bash SUBSCRIPTIONS_ENABLED=true ``` -------------------------------- ### Install Winston Logger dependencies Source: https://the-guild.dev/graphql/hive/docs/logger/writers Install the required peer dependency for the Winston log writer. ```bash npm i winston ``` -------------------------------- ### Setup OpenTelemetry via CLI (HTTP) Source: https://the-guild.dev/graphql/hive/docs/migration-guides/gateway-v1-v2 Configure OpenTelemetry exporter endpoint using the CLI option. Defaults to HTTP OTLP. ```bash hive-gateway supergraph supergraph.graphql \ --opentelemetry "http://localhost:4318" ``` -------------------------------- ### Install LogTape Dependency Source: https://the-guild.dev/graphql/hive/docs/logger/writers Install the '@logtape/logtape' package, which is an optional peer dependency for using LogTapeLogWriter. ```sh npm i @logtape/logtape ``` -------------------------------- ### Initialize Gateway Tester Source: https://the-guild.dev/graphql/hive/docs/gateway/other-features/testing/gateway-tester Example of setting up a gateway tester with mocked subgraphs and a plugin to spy on fetch operations. ```typescript import { expect, vi } from "vitest"; import { createGatewayTester } from "@graphql-hive/gateway-testing"; const onFetchFn = vi.fn(); const books = { name: "books", schema: { typeDefs: /* GraphQL */ ` type Query { book(id: ID!): Book } type Book { id: ID! title: String! } `, resolvers: { Query: { book: (_, { id }) => ({ id, title: "The Hive Handbook" }), }, }, }, }; await using gateway = createGatewayTester({ subgraphs: [books], plugins: () => [ { onFetch({ executionRequest }) { onFetchFn(executionRequest?.operationName); }, }, ], }); await expect( gateway.execute({ query: /* GraphQL */ ` query Test { book(id: "1") { title } } `, }), ).resolves.toStrictEqual({ data: { book: { title: "The Hive Handbook", }, }, }); expect(onFetchFn).toHaveBeenCalledWith("Test"); ``` -------------------------------- ### Start Docker Compose services Source: https://the-guild.dev/graphql/hive/docs/gateway/deployment/docker Launch the defined services using the Docker Compose CLI. ```sh docker compose up ``` -------------------------------- ### Enable Development Mode Source: https://the-guild.dev/graphql/hive/docs/gateway/logging-and-error-handling Command to start the gateway in development mode, which includes original error details in the response. ```sh NODE_ENV=development hive-gateway supergraph MY_SUPERGRAPH ``` -------------------------------- ### Schema Check Output Example Source: https://the-guild.dev/graphql/hive/docs/schema-registry/get-started/apollo-federation Example output from the Hive CLI when breaking changes are detected. ```bash ✖ Detected 1 error - Breaking Change: Field rating was removed from object type Review ℹ Detected 2 changes - Field rating was removed from object type Review - Field averageRating was added to object type Review ``` -------------------------------- ### AggregateError Output Example Source: https://the-guild.dev/graphql/hive/docs/logger/writers Example output showing an AggregateError containing multiple write failures. ```sh AggregateError: Failed to flush 2 writes at async (/project/example.js:20:3) { [errors]: [ Error: Write failed! #1 at Object.write (/project/example.js:9:15), Error: Write failed! #2 at Object.write (/project/example.js:9:15) ] } ``` -------------------------------- ### Verify Hive CLI Installation Source: https://the-guild.dev/graphql/hive/docs/schema-registry/self-hosting/get-started Check the installed version of the Hive CLI to ensure it is configured correctly. ```bash hive --version ``` -------------------------------- ### Run the Deno gateway server Source: https://the-guild.dev/graphql/hive/docs/gateway/deployment/runtimes/deno Execute the gateway script with the necessary network permissions. ```bash deno run --allow-net deno-hive-gateway.ts ``` -------------------------------- ### Install OTLP HTTP Exporter for Jaeger Source: https://the-guild.dev/graphql/hive/docs/gateway/monitoring-tracing Install the OTLP HTTP exporter package for Jaeger integration. ```bash npm i @opentelemetry/exporter-trace-otlp-http ``` -------------------------------- ### Configure Plugin with Custom Fields Source: https://the-guild.dev/graphql/hive/docs/router/plugin-system YAML configuration example showing how to pass custom fields to a plugin's configuration. ```yaml plugins: my_plugin: enabled: true config: some_field: true ``` -------------------------------- ### Start Hive Console with Docker Source: https://the-guild.dev/graphql/hive/docs/schema-registry/self-hosting/get-started Use this command to launch the Hive services defined in your docker-compose file. ```bash docker compose -f docker-compose.with-env.yml up ``` -------------------------------- ### Install Redis PubSub dependencies Source: https://the-guild.dev/graphql/hive/docs/gateway/subscriptions Install the required Hive PubSub package and the ioredis peer dependency. ```sh npm i @graphql-hive/pubsub ioredis ``` -------------------------------- ### Run Hive Gateway with Bun Source: https://the-guild.dev/graphql/hive/docs/gateway/deployment/runtimes/bun Use the createGatewayRuntime function to initialize the gateway and serve it using Bun.serve. This approach is recommended only for advanced use cases where the CLI is not suitable. ```ts import { createGatewayRuntime } from "@graphql-hive/gateway-runtime"; const gatewayRuntime = createGatewayRuntime(/* Your configuration */); const server = Bun.serve({ fetch: gatewayRuntime, }); console.info( `Server is running on ${new URL( server.graphqlEndpoint, `http://${server.hostname}:${server.port}`, )}`, ); ``` -------------------------------- ### Install Hive Gateway Runtime Source: https://the-guild.dev/graphql/hive/docs/gateway/deployment/node-frameworks/sveltekit Install the required package to enable Hive Gateway runtime in your project. ```sh npm i @graphql-hive/gateway-runtime ``` -------------------------------- ### CryptoJS Hashing Examples Source: https://the-guild.dev/graphql/hive/docs/schema-registry/laboratory/preflight-scripts Access CryptoJS for encryption and decryption. Examples include MD5 hashing and HMAC-SHA256. ```javascript CryptoJS.MD5("Message"); CryptoJS.HmacSHA256("Message", "Secret Passphrase"); ``` -------------------------------- ### Install Apollo Server Hive Integration Source: https://the-guild.dev/graphql/hive/docs/schema-registry/app-deployments Install the Hive Apollo integration package using npm or yarn. ```sh npm i -D @graphql-hive/apollo ``` -------------------------------- ### Install Hive CLI via Binary Source: https://the-guild.dev/graphql/hive/docs/schema-registry/get-started/first-steps Use this method for non-JavaScript projects to download and verify the Hive CLI binary. ```bash curl -sSL https://graphql-hive.com/install.sh | sh ``` ```bash hive --version ``` -------------------------------- ### Authorization Examples Source: https://the-guild.dev/graphql/hive/docs/router/configuration/authorization Illustrates how to configure and use authorization in both 'filter' and 'reject' modes. ```APIDOC ## Authorization Examples ### Filter Mode (Default) With `filter` mode, unauthorized fields are silently removed from the operation, but the query continues to execute and return the data the user can access: ```yaml title="router.config.yaml" authorization: directives: enabled: true unauthorized: mode: filter ``` **Request:** ```graphql query { publicData me { name email } } ``` If the user is not authenticated, the response might look like: ```json { "data": { "publicData": "available", "me": null }, "errors": [ { "message": "Unauthorized field or type", "extensions": { "code": "UNAUTHORIZED_FIELD_OR_TYPE", "affectedPath": "me" } } ] } ``` ### Reject Mode With `reject` mode, if any field is unauthorized, the entire request is rejected: ```yaml title="router.config.yaml" authorization: directives: enabled: true unauthorized: mode: reject ``` **Request (same as above):** ```graphql query { publicData me { name email } } ``` **Response:** ```json { "data": null, "errors": [ { "message": "Unauthorized field or type", "extensions": { "code": "UNAUTHORIZED_FIELD_OR_TYPE" } } ] } ``` ``` -------------------------------- ### Install Hive Gateway via NPM Source: https://the-guild.dev/graphql/hive/docs/gateway Installs the Hive Gateway package using the Node.js package manager. ```sh npm i @graphql-hive/gateway ``` -------------------------------- ### Initialize Hive Gateway in Deno Source: https://the-guild.dev/graphql/hive/docs/gateway/deployment/runtimes/deno Create a server instance using the Deno standard library's serve function and the Hive Gateway runtime. ```typescript import { serve } from "https://deno.land/std@0.157.0/http/server.ts"; import { createGatewayRuntime } from "@graphql-hive/gateway-runtime"; const gatewayRuntime = createGatewayRuntime(/* Your programmatic configuration */); serve(gatewayRuntime, { onListen({ hostname, port }) { console.log( `Listening on http://${hostname}:${port}/${gatewayRuntime.graphqlEndpoint}`, ); }, }); ```