import { Callout } from '@theguild/components'

# Envelop

<Callout type="warning">
  If you are using GraphQL Yoga, please use the dedicated [GraphQL Yoga
  plugin](/docs/other-integrations/graphql-yoga) for Hive.
</Callout>

## Installation

```sh npm2yarn
npm i @graphql-hive/envelop
```

<Callout type="info">
  We recommend installing Hive Client package as a direct dependency of your project, because it
  includes a runtime to send usage reports and schemas to Hive registry.
</Callout>

The `@graphql-hive/envelop` package exports an
[Envelop plugin](https://the-guild.dev/graphql/envelop), that can be used directly with any server
that supports Envelop.

## Configuration

A full configuration guide can be found in the
["Configuration"](../api-reference/client.mdx#configuration) page.

## Integration Guide

### Publishing Schemas

Please use the [Hive CLI to publish your GraphQL schema](../api-reference/cli.mdx#publish-a-schema).
Follow the [CI/CD instructions](./ci-cd.mdx) for automating the process.

### Usage Reporting

<Callout>
  For more configuration options, such as sampling, client name and version reporting, please refer
  to the [Hive client configuration](../api-reference/client.mdx#configuration) reference.
</Callout>

You can send usage reporting to Hive registry by using the `usage` section of the configuration:

```ts
import { createServer } from 'node:http'
import { createYoga } from 'graphql-yoga'
import { useHive } from '@graphql-hive/envelop'
import { schema } from './schema'

const plugin = useHive({
  enabled: true, // Enable/Disable Hive Client
  token: 'YOUR-TOKEN',
  usage: true
})
```

## Additional Resources

- [`@graphql-hive/envelop` source code](https://github.com/graphql-hive/platform/tree/main/packages/libraries/envelop)
- [`HivePluginOptions` configuration reference](https://github.com/graphql-hive/platform/blob/main/packages/libraries/cire/src/client/types.ts)
- [Envelop](https://the-guild.dev/graphql/envelop)
