graphql-safe-guards 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mateo Diaz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # graphql-safe-guards
2
+
3
+ Protect your GraphQL API with a single import.
4
+
5
+ ## Installation
6
+
7
+ npm install graphql-safe-guards
8
+
9
+ ## Usage
10
+
11
+ ```ts
12
+ import { graphqlSafeGuards } from "graphql-safe-guards";
13
+
14
+ const server = new ApolloServer({
15
+ schema,
16
+ validationRules: graphqlSafeGuards({
17
+ depth: 3,
18
+ complexity: 10,
19
+ }),
20
+ });
21
+ ```
22
+
23
+ What it includes
24
+
25
+ - Query depth limiting
26
+ - Query complexity limiting
27
+ - Sensible defaults
28
+ - Framework agnostic
29
+
30
+ ---
@@ -0,0 +1,3 @@
1
+ import type { ValidationRule } from "graphql";
2
+ import { GraphQLSafeGuardsOptions } from "./types";
3
+ export declare function graphqlSafeGuards(options?: GraphQLSafeGuardsOptions): ValidationRule[];
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphqlSafeGuards = graphqlSafeGuards;
4
+ const graphql_safe_depth_1 = require("graphql-safe-depth");
5
+ const graphql_complexity_validation_1 = require("graphql-complexity-validation");
6
+ function graphqlSafeGuards(options = {}) {
7
+ const { depth = 5, complexity = 100 } = options;
8
+ return [
9
+ (0, graphql_safe_depth_1.createDepthLimitRule)({ maxDepth: depth }),
10
+ (0, graphql_complexity_validation_1.createComplexityLimitRule)({ maxComplexity: complexity }),
11
+ ];
12
+ }
@@ -0,0 +1,4 @@
1
+ export interface GraphQLSafeGuardsOptions {
2
+ depth?: number;
3
+ complexity?: number;
4
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "graphql-safe-guards",
3
+ "version": "1.0.1",
4
+ "description": "Opinionated GraphQL security guards (depth + complexity) in one import",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "vitest",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "dependencies": {
13
+ "-": "^0.0.1",
14
+ "graphql-complexity-validation": "^1.0.4",
15
+ "graphql-safe-depth": "^1.0.0"
16
+ },
17
+ "peerDependencies": {
18
+ "graphql": "^14 || ^15 || ^16"
19
+ },
20
+ "keywords": [
21
+ "graphql",
22
+ "security",
23
+ "depth",
24
+ "complexity",
25
+ "apollo",
26
+ "nest",
27
+ "yoga"
28
+ ],
29
+ "author": "Mateo diaz lopez <mateodiaz401@gmail.com>",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/Mateodiaz401/graphql-safe-guards.git"
34
+ },
35
+ "homepage": "https://github.com/Mateodiaz401/graphql-safe-guards",
36
+ "bugs": {
37
+ "url": "https://github.com/Mateodiaz401/graphql-safe-guards/issues"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^25.0.9",
41
+ "@vitest/coverage-v8": "^4.0.17",
42
+ "typescript": "^5.9.3",
43
+ "vitest": "^4.0.17"
44
+ }
45
+ }
@@ -0,0 +1,15 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { graphqlSafeGuards } from "../src";
3
+
4
+ describe("graphqlSafeGuards", () => {
5
+ it("returns validation rules", () => {
6
+ const rules = graphqlSafeGuards({
7
+ depth: 3,
8
+ complexity: 10,
9
+ });
10
+
11
+ expect(rules).toHaveLength(2);
12
+ expect(typeof rules[0]).toBe("function");
13
+ expect(typeof rules[1]).toBe("function");
14
+ });
15
+ });