GraphQL Yoga is the cross-JavaScript runtime GraphQL server maintained by The Guild. We provide an
easy to use plugin for GraphQL Yoga to integrate with
Hive.
Installation
npm i @graphql-hive/yoga
yarn add @graphql-hive/yoga
pnpm add @graphql-hive/yoga
bun add @graphql-hive/yoga
The @graphql-hive/yoga package exports a
Yoga plugin, that can be
used directly with GraphQL-Yoga.
Configuration
A full configuration guide can be found in the
“Configuration” page.
You can send usage reporting to Hive registry by using the usage section of the configuration:
import { createServer } from "node:http";import { createYoga } from "graphql-yoga";import { useHive } from "@graphql-hive/yoga";import { schema } from "./schema";const yoga = createYoga({ schema, plugins: [ useHive({ enabled: true, // Enable/Disable Hive Client token: "YOUR-TOKEN", // Collects and send usage reporting based on executed operations usage: { target: "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>", }, }), ],});const server = createServer(yoga);server.listen(4000, () => { console.info("Server is running on http://localhost:4000/graphql");});
Cloudflare Workers
To use Hive with Cloudflare Workers, you can use
GraphQL Yoga (as shown below) or use the generic
Hive client with your own GraphQL server
implementation.
Here’s an example of how to use Hive with GraphQL Yoga on Cloudflare Workers:
You can associate a client name and version with any operation reported to Hive, by sending the
client information HTTP headers for requests sent to your GraphQL Yoga server. Those are
x-graphql-client-name (or graphql-client-name) and x-graphql-client-version (or
graphql-client-version).
GraphQL over SSE is a popular protocol for executing GraphQL Subscription (and also Mutation and
Query) operations.
No additional configuration is required for sending usage reporting to Hive when using the
graphql-sse plugin.
Just add the SSE plugin to your Yoga server and the usage reporting will be sent automatically.
SSE HTTP Request Client info
import { createServer } from "node:http";import { createYoga, type YogaInitialContext } from "graphql-yoga";import { useHive } from "@graphql-hive/yoga";import { useGraphQLSSE } from "@graphql-yoga/plugin-graphql-sse";import { schema } from "./schema";const yoga = createYoga({ schema, plugins: [ useGraphQLSSE(), useHive({ enabled: true, token: "YOUR-TOKEN", usage: { target: "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>", }, }), ],});const server = createServer(yoga);server.listen(4000, () => { console.info("Server is running on http://localhost:4000/graphql");});
Client Information
The same rules apply for any other HTTP client, such as Apollo Client, Relay, or any other HTTP.
Just forward send the headers to your server.