GraphQL Yoga Metrics Plugin
The Stellate Yoga Metrics Plugin is designed to integrate Stellate with the Guild’s GraphQL Yoga Server and Yoga APIs. The Guild Yoga Server is offers a highly performant GraphQL Server with an easy setup. Our Yoga Server Metrics Plugin enables metrics logging, allowing for a seamless connection with the Stellate service for performance insights and analytics for Yoga Server-based APIs.
The Stellate graphql-yoga
plugin is simple and straightforward to integrate, with just a few lines of code.
Benefits
The Stellate Yoga Server Metrics Plugin lets you collect metrics without setting up the Stellate Edge proxy. For more information about the Stellate Edge proxy metrics, read Stellate Edge proxy. In addition, the Yoga Server Metrics Plugin features:
- Easy setup and integration.
- Ability to log metrics, which are useful for monitoring and analyzing API usage.
- Automatically synchronize your GraphQL schema with your Stellate service, ensuring that your Yoga Server GraphQL API structure is always up to date.
- The
yoga-server
plugin, as do all of the plugins for JavaScript-based servers, takes afetch
function as an argument. This enables using the plugin in any JavaScript environment. If you are running NodeJS you can use thenode-fetch
package, and in an edge environment (such as Cloudflare Workers) you can pass the globalfetch
function.
Before You Begin
Before you install and use the Stellate Yoga Server Plugin, you need to set up your GraphQL Yoga Server. For information, read The Guild GraphQL Yoga documentation . Additionally, you need to:
Set Up a Stellate Service
You must have an active Stellate service set up. Our GraphQL Apollo Server Plugin is designed to work with your Stellate service. It provides performance insights and analytics for Apollo Server-based APIs.
Create a Logging Token
To implement this plugin, you need to create a logging token specific to your Stellate service. This token is used to authenticate and log metrics data from your GraphQL API to your Stellate dashboard. You can get your logging token by going to your Stellate Dashboard > Services > Your Service > Config > Token.
Setup Yoga Server Metrics Plugin
To install and use the plugin for yoga-server:
- Set up a Stellate service and create a logging token. See the prior Before You Begin section for more information.
- Copy and paste the following JavaScript plugin code to your server:
import { createStellateLoggerPlugin } from 'stellate/graphql-yoga'
import { createServer } from 'node:http'
import { createYoga, createSchema } from 'graphql-yoga'
const stellatePlugin = createStellateLoggerPlugin({
serviceName: '${serviceName}',
token: '${loggingToken}',
// a fetch compliant function, can be from `node-fetch` if you are running in NodeJS,
// or the global fetch function if running in a v8 environment (e.g. Cloudflare Workers)
fetch: fetch,
})
const yoga = createYoga({ schema, plugins: [stellatePlugin] })
const server = createServer(yoga)
server.listen(4000)
- Start the server to begin handling requests.
- Refresh your dashboard to show the incoming requests and metrics, highlighting the plugin’s capability to track Yoga Server GraphQL API usage.