# @envelop/extended-validation

Latest version **7.2.1** (published 2026-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @envelop/extended-validation
pnpm add @envelop/extended-validation
yarn add @envelop/extended-validation
bun add @envelop/extended-validation
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.2.1 |
| Published | 2026-09-16 |
| First published | 2021-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 2 |
| Unpacked size | 30.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 8529 |
| Author | Dotan Simha <dotansimha@gmail.com> |
| Maintainers | dotansimha, enisdenjo, theguild-bot |

## Links

- npm: https://www.npmjs.com/package/@envelop/extended-validation
- Repository: https://github.com/graphql-hive/graphql-yoga
- Homepage: https://github.com/graphql-hive/graphql-yoga/tree/main/packages/envelop/plugins/extended-validation#readme
- npm.io page: https://npm.io/package/@envelop/extended-validation

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.5.0
- [@graphql-tools/utils](https://npm.io/package/@graphql-tools/utils.md) ^11.2.0

## Recent versions

- 7.2.1 (latest) — 2026-09-16
- 8.0.0-alpha-20260420122826-afff629b648b45dc56cbf71f10a44eb4006be3c3 (alpha) — 2026-04-20
- 5.1.3-rc-20250306153119-ed3979491f3ac71caf439dd723f2d12d26b1000f (rc) — 2025-03-06
- 7.2.0 — 2026-08-19
- 7.1.2-alpha-20260220144136-711686b126e6dd25230f0bb3c500a7a031985b0e — 2026-02-20
- 7.1.2-alpha-20260220131826-1b3a1e9e27b8b8aa558355d0c2f0e695b96d70cb — 2026-02-20
- 7.1.2-alpha-20260220131728-1041a1750b5b3fc9b884e99d2faee0f168627271 — 2026-02-20
- 7.1.2-alpha-20260220131011-a35ff9b25933403c69d677eddc47f62e241284f2 — 2026-02-20
- 7.1.2-alpha-20260220130904-211898c307097b3cc67903d5c3c227f14d9682db — 2026-02-20
- 7.1.2-alpha-20260220130823-c2a2d78d42fdabd997939bf0acb354c3e2e12050 — 2026-02-20
- 7.1.2-alpha-20260220130803-9ecead51d07d2d27d2566b9dbae5e166a53b7f2c — 2026-02-20
- 7.1.2-alpha-20260220130406-9e30e6b21868124f2e95d8178dade31b122188f6 — 2026-02-20
- 7.1.2-alpha-20260220130319-b0b7578d1e4ea902b60dc0359460903320969daa — 2026-02-20
- 7.1.2-alpha-20260220130301-e72a8134fdf82c1a8d7f2dcae344f023f7e34876 — 2026-02-20
- 7.1.2-alpha-20260220085650-7b12e0b83f88e98e453b6211263b13226c3eb3bf — 2026-02-20
- … 1658 more at https://npm.io/package/@envelop/extended-validation/versions

## README

## `@envelop/extended-validation`

Extended validation plugin adds support for writing GraphQL validation rules, that has access to all
`execute` parameters, including variables.

While GraphQL supports fair amount of built-in validations, and validations could be extended, it's
doesn't expose `variables` to the validation rules, since operation variables are not available
during `validate` flow (it's only available through execution of the operation, after
input/variables coercion is done).

This plugin runs before `validate` but allow developers to write their validation rules in the same
way GraphQL `ValidationRule` is defined (based on a GraphQL visitor).

## Getting Started

Start by installing the plugin:

```
yarn add @envelop/extended-validation
```

Then, use the plugin with your validation rules:

```ts
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine } from '@envelop/core'
import { useExtendedValidation } from '@envelop/extended-validation'

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    useExtendedValidation({
      rules: [
        /* ... your rules here  */
      ]
    })
  ]
})
```

To create your custom rules, implement the `ExtendedValidationRule` interface and return your
GraphQL AST visitor.

For example:

```ts
import { ExtendedValidationRule } from '@envelop/extended-validation'

export const MyRule: ExtendedValidationRule = (validationContext, executionArgs) => {
  return {
    OperationDefinition: node => {
      // This will run for every executed Query/Mutation/Subscription
      // And now you also have access to the execution params like variables, context and so on.
      // If you wish to report an error, use validationContext.reportError or throw an exception.
    }
  }
}
```

## Built-in Rules

### Union Inputs: `@oneOf`

This directive provides validation for input types and implements the concept of union inputs. You
can find the [complete spec RFC here](https://github.com/graphql/graphql-spec/pull/825).

You can use union inputs either via a the SDL flow, by annotating types and fields with `@oneOf` or
via the `extensions` field.

First, make sure to add that rule to your plugin usage:

```ts
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine } from '@envelop/core'
import { OneOfInputObjectsRule, useExtendedValidation } from '@envelop/extended-validation'

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    useExtendedValidation({
      rules: [OneOfInputObjectsRule]
    })
  ]
})
```

#### Schema Directive Flow

Make sure to include the following directive in your schema:

```graphql
directive @oneOf on INPUT_OBJECT | FIELD_DEFINITION
```

Then, apply it to field definitions, or to a complete `input` type:

```graphql
## Apply to entire input type
input FindUserInput @oneOf {
  id: ID
  organizationAndRegistrationNumber: GraphQLInt
}

## Or, apply to a set of input arguments

type Query {
  foo(id: ID, str1: String, str2: String): String @oneOf
}
```

#### Programmatic extensions flow

```tsx
const GraphQLFindUserInput = new GraphQLInputObjectType({
  name: 'FindUserInput',
  fields: {
    id: {
      type: GraphQLID
    },
    organizationAndRegistrationNumber: {
      type: GraphQLInt
    }
  },
  extensions: {
    oneOf: true
  }
})

const Query = new GraphQLObjectType({
  name: 'Query',
  fields: {
    foo: {
      type: GraphQLString,
      args: {
        id: {
          type: GraphQLID
        },
        str1: {
          type: GraphQLString
        },
        str2: {
          type: GraphQLString
        }
      },
      extensions: {
        oneOf: true
      }
    }
  }
})
```

---
_Source: https://npm.io/package/@envelop/extended-validation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
