-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
useValidationRule()
plugin (#2215)
* Add useValidationRule * Add changeset * Add a test * Fix syntax in docs
- Loading branch information
Showing
7 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@envelop/core': patch | ||
--- | ||
|
||
feat: add `useValidationRule()` plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#### `useValidationRule` | ||
|
||
This plugin is the simplest plugin for adding a validation rule to your GraphQL schema. You can | ||
specify any function that conforms to | ||
[the `ValidationRule` type](https://github.com/graphql/graphql-js/blob/8a95335f545024c09abfa0f07cc326f73a0e466f/src/validation/ValidationContext.ts#L269). | ||
|
||
```ts | ||
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql' | ||
import { envelop, useEngine, useValidationRule } from '@envelop/core' | ||
import { depthLimit } from '@graphile/depth-limit' | ||
|
||
const getEnveloped = envelop({ | ||
plugins: [ | ||
useEngine({ parse, validate, specifiedRules, execute, subscribe }), | ||
useValidationRule( | ||
depthLimit({ | ||
maxDepth: 12, | ||
maxListDepth: 4, | ||
maxSelfReferentialDepth: 2 | ||
}) | ||
) | ||
// ... other plugins ... | ||
] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Plugin } from '@envelop/types'; | ||
|
||
export const useValidationRule = (rule: any): Plugin => { | ||
return { | ||
onValidate({ addValidationRule }) { | ||
addValidationRule(rule); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters