Skip to content

Commit

Permalink
Merge branch 'envelop-plugin'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandotv committed Jan 24, 2022
2 parents 2bd3790 + f769837 commit 5e6f3c0
Show file tree
Hide file tree
Showing 25 changed files with 794 additions and 247 deletions.
8 changes: 8 additions & 0 deletions .changeset/few-rings-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'envelop-no-alias': major
'graphql-no-alias': patch
---

Initial publish of `envelop-no-alias`

Update readme for: `graphql-no-alias`
27 changes: 17 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
]
},
{
"name": "Current test file",
"name": "no alias test file",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
// "program": "${workspaceFolder}/node_modules/.bin/jest",
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js", //pnpm fix
"program": "${workspaceFolder}/packages/no-alias/node_modules/jest/bin/jest.js", //pnpm fix
"args": [
"${relativeFile}",
"--no-cache",
Expand All @@ -39,19 +39,26 @@
]
},
{
"name": "Nodemon",
"name": "Envelop test file",
"type": "node",
"request": "attach",
"processId": "${command:PickProcess}",
"restart": true,
"request": "launch",
"cwd": "${workspaceFolder}/packages/envelop",
// "program": "${workspaceFolder}/node_modules/.bin/jest",
"program": "${workspaceFolder}/packages/envelop/node_modules/jest/bin/jest.js", //pnpm fix
"args": [
"${relativeFile}",
"--no-cache",
"--watchAll=false",
"--runInBand"
],
"console": "integratedTerminal",
"protocol": "inspector",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**/*.js"
],
// "localRoot": "${workspaceFolder}/src/regexparam",
// "remoteRoot": "/",
"stopOnEntry": true
]
}
]
}
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@
![Codecov](https://img.shields.io/codecov/c/gh/ivandotv/graphql-no-alias)
[![GitHub license](https://img.shields.io/github/license/ivandotv/graphql-no-alias)](https://github.com/ivandotv/graphql-no-alias/blob/main/LICENSE)

Graphql validation with accompanying directive to limit the number of `alias` queries and mutations you can use.
It effectively disables batching of queries and mutations.
<!-- toc -->

## Why
- [Inspiration](#inspiration)
- [Instalation](#instalation)
- [Usage](#usage)
- [Using the directive](#using-the-directive)
- [Schema setup](#schema-setup)
- [Object type](#object-type)
- [Field type](#field-type)
- [Customizing the declaration](#customizing-the-declaration)
- [Imperative configuration](#imperative-configuration)
- [Customizing the error message](#customizing-the-error-message)
- [Envelop Plugin](#envelop-plugin)
- [License](#license)

<!-- tocstop -->

## Inspiration

Graphql validation with accompanying directive to limit the number of `alias` queries and mutations that can be sent to the GraphQL server.

It will disable certain kinds of attacks that look like this.

Expand Down Expand Up @@ -240,6 +256,10 @@ const { typeDefs, validation } = createValidation({errorFn:(
})
```

## Envelop Plugin

If you are using [GraphQL Envelop](https://www.envelop.dev/). I have made a (plugin)[packages/envelop/README.md] that uses this directive.

### License

This project is licensed under the MIT License - see [LICENSE](LICENSE) file for details
30 changes: 30 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
coverage:
status:
project:
default:
target: auto
graphql-no-alias:
target: auto
flags:
- graphql-no-alias
envelop:
target: auto
flags:
- envelop

comment:
layout: 'reach, diff, flags, files'
behavior: default
require_changes: false
require_base: true
require_head: true

flags:
graphql-no-alias:
paths:
- packages/graphql-no-alias/
carryforward: true
envelop:
paths:
- packages/envelop/
carryforward: true
19 changes: 7 additions & 12 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
module.exports = {
testMatch: [
'<rootDir>/src/**/?(*.)+(spec|test).[jt]s?(x)',
'<rootDir>/tests/?(*.)+(spec|test).[jt]s?(x)'
],
testEnvironment: 'node',
moduleDirectories: ['node_modules', 'src'],
testEnvironment: 'jsdom',
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname'
],
collectCoverageFrom: [
'<rootDir>/src/**',
'!<rootDir>/src/globals.d.ts',
'!<rootDir>/src/__tests__/**',
'!<rootDir>/src/__fixtures__/**'
],
globals: {
__DEV__: true,
__VERSION__: true,
__BUILD_DATE__: true,
__COMMIT_SHA__: true
},
coverageThreshold: {
global: {
branches: 80,
Expand Down
83 changes: 16 additions & 67 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,76 +1,25 @@
{
"name": "graphql-no-alias",
"version": "2.0.0",
"private": false,
"description": "No alias directive for graphql mutation and query types. It can limit the amount of alias fields that can be used for queries and mutations. Preventing batch attacks.",
"keywords": [
"graphql",
"graphql directive",
"graphql validation",
"graphql alias",
"graphql query alias",
"graphql mutation alias"
],
"author": "ivandotv",
"license": "MIT",
"main": "./dist/prod/graphql-no-alias.js",
"exports": {
"import": "./dist/prod/graphql-no-alias.esm.js",
"require": "./dist/prod/graphql-no-alias.js"
},
"types": "./dist/types/index.d.ts",
"files": [
"dist",
"src"
],
"name": "graphql-no-alias-monorepo",
"version": "0.0.0",
"private": true,
"author": "Ivan Vlatkovic",
"scripts": {
"lint": "eslint --fix \"src/**/\"",
"lint:check": "eslint \"src/**/\"",
"lint:ci": "pnpm lint:check && pnpm format:check",
"format": "prettier --write src/**",
"format:check": "prettier --check src/**",
"test": "NODE_ENV=test jest --verbose --coverage --no-cache",
"test:watch": "NODE_ENV=test jest --watch",
"test:ci": "NODE_ENV=test jest --runInBand --ci --coverage --coverageDirectory=coverage",
"build:prod": "NODE_ENV=production microbundle --tsconfig ./tsconfig.json --format modern,cjs --target node --output dist/prod",
"build": "rm -rf ./dist && pnpm build:prod",
"prepublishOnly": "pnpm build",
"test": "pnpm multi run test --workspace-concurrency 1",
"test:ci": "pnpm multi run test:ci --workspace-concurrency 1",
"lint": "pnpm multi run lint",
"lint:ci": "pnpm multi run lint:ci",
"build": "pnpm multi run build",
"prepare": "husky install",
"release": "pnpm run prepublishOnly && pnpm changeset publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ivandotv/graphql-no-alias.git"
},
"bugs": {
"url": "https://github.com/ivandotv/graphql-no-alias/issues"
"release": "pnpm multi run prepublishOnly --workspace-concurrency 1 && pnpm changeset publish"
},
"homepage": "https://github.com/ivandotv/graphql-no-alias#readme",
"peerDependencies": {
"graphql": "^16.2.0"
"dependencies": {
"husky": "^7.0.4",
"lint-staged": "^12.2.2",
"prettier": "^2.5.1"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@changesets/cli": "^2.19.0",
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-tsdoc": "^0.2.14",
"graphql": "^16.2.0",
"husky": "^7.0.4",
"jest": "^27.4.5",
"jest-mock-console": "^1.2.3",
"jest-watch-typeahead": "^1.0.0",
"lint-staged": "^12.1.4",
"microbundle": "^0.14.2",
"prettier": "^2.5.1",
"shx": "^0.3.3"
"del": "^6.0.0",
"minimist": "^1.2.5"
}
}
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions packages/envelop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Envelop Plugin

This package is an [envelop plugin](https://www.envelop.dev) version of
[`graphql-no-alias`](https://github.com/ivandotv/graphql-no-alias) validation directive.

## Install

```sh
npm Install envelop-no-alias
```

## Usage

```ts
import { envelop } from '@envelop/core'
import { useNoAlias, NoAliasConfig } from 'envelop-no-alias'

//optional configuration
const config: NoAliasConfig = {}
const getEnveloped = envelop({
plugins: [useNoAlias(config)]
})
```
14 changes: 14 additions & 0 deletions packages/envelop/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const baseConfig = require('../../jest.config')

module.exports = {
...baseConfig,
rootDir: '.',
projects: undefined,
testMatch: ['<rootDir>/src/__tests__/?(*.)+(spec|test).[jt]s?(x)'],
collectCoverageFrom: [
'<rootDir>/src/**',
'!<rootDir>/src/__tests__/**',
'!<rootDir>/src/__fixtures__/**'
]
}
82 changes: 82 additions & 0 deletions packages/envelop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "envelop-no-alias",
"version": "0.0.0",
"private": false,
"description": "Graphql envelop plugin for no alias graphql directive. It can limit the amount of alias fields that can be used for queries and mutations. Preventing batch attacks.",
"keywords": [
"@envelop",
"envelop",
"graphql",
"graphql directive",
"graphql validation",
"graphql alias",
"graphql query alias",
"graphql mutation alias"
],
"author": "ivandotv",
"license": "MIT",
"main": "./dist/prod/envelop-no-alias.js",
"exports": {
"import": "./dist/prod/envelop-no-alias.esm.js",
"require": "./dist/prod/envelop-no-alias.js"
},
"types": "./dist/types/index.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"lint": "eslint --fix \"src/**/\"",
"lint:check": "eslint \"src/**/\"",
"lint:ci": "pnpm lint:check && pnpm format:check",
"format": "prettier --write src/**",
"format:check": "prettier --check src/**",
"test": "jest --verbose --coverage --no-cache",
"test:watch": "jest --watch",
"test:ci": "jest --runInBand --ci --coverage --coverageDirectory=coverage",
"build:prod": "NODE_ENV=production microbundle --tsconfig ./tsconfig.json --format modern,cjs --target node --output dist/prod",
"build": "rm -rf ./dist && pnpm build:prod",
"prepublishOnly": "pnpm build",
"release": "pnpm run prepublishOnly && pnpm changeset publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ivandotv/graphql-no-alias.git"
},
"bugs": {
"url": "https://github.com/ivandotv/graphql-no-alias/issues"
},
"homepage": "https://github.com/ivandotv/graphql-no-alias#readme",
"dependencies": {
"graphql-no-alias": "../no-alias"
},
"peerDependencies": {
"@envelop/core": "^1.7.1"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@changesets/cli": "^2.19.0",
"@envelop/core": "^1.7.1",
"@envelop/testing": "^3.0.1",
"@envelop/types": "^1.5.1",
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-tsdoc": "^0.2.14",
"graphql": "^16.2.0",
"jest": "^27.4.5",
"jest-watch-typeahead": "^1.0.0",
"lint-staged": "^12.1.4",
"microbundle": "^0.14.2",
"prettier": "^2.5.1",
"shx": "^0.3.3",
"typescript": "^4.5.5"
}
}
Loading

0 comments on commit 5e6f3c0

Please sign in to comment.