Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
project: './tsconfig.json'
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
'plugin:prettier/recommended'
],
rules: {
'interface-name': 0,
'object-literal-sort-keys': 0,
'no-increment-decrement': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-non-null-assertion': 0
}
};
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Continuous Integration

on:
pull_request:
push:
branches:
- master

jobs:
test-and-lint:
name: Run tests and lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v1
with:
node-version: '14.x'
- run: yarn install
- run: yarn lint
- run: yarn typecheck
- run: yarn test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to add yarn report-coverage and set up coveralls for GH actions

- run: yarn build
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GraphQL Query Rewriter

[![CircleCI](https://circleci.com/gh/ef-eng/graphql-query-rewriter/tree/master.svg?style=shield)](https://circleci.com/gh/ef-eng/graphql-query-rewriter/tree/master)
[![CircleCI](https://circleci.com/gh/graphql-query-rewriter/core/tree/master.svg?style=shield)](https://circleci.com/gh/ef-eng/graphql-query-rewriter/tree/master)
[![Coverage Status](https://coveralls.io/repos/github/chanind/graphql-query-rewriter/badge.svg?branch=master)](https://coveralls.io/github/ef-eng/graphql-query-rewriter?branch=master)
[![npm](https://badgen.net/npm/v/graphql-query-rewriter)](https://www.npmjs.com/package/graphql-query-rewriter)
[![license](https://badgen.net/npm/license/graphql-query-rewriter)](https://opensource.org/licenses/MIT)
Expand Down
109 changes: 49 additions & 60 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
{
"name": "graphql-query-rewriter",
"name": "@graphql-query-rewriter/core",
"version": "0.0.1",
"description": "",
"keywords": [],
"main": "dist/index.umd.js",
"module": "dist/index.es5.js",
"typings": "dist/types/index.d.ts",
"keywords": [
"graphql",
"query",
"rewriter",
"ast",
"schema"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"author": "David Chanin <chanindav@gmail.com>",
"repository": {
"type": "git",
"url": "https://github.com/ef-eng/graphql-query-rewriter"
"url": "https://github.com/ef-en/graphql-query-rewriter"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this URL isn't correct - should be https://github.com/graphql-query-rewriter/core

},
"license": "MIT",
"engines": {
"node": ">=6.0.0"
"node": ">=10.0.0"
},
"scripts": {
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rimraf dist",
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably fine to get rid of rollup, just out of curiosity why remove it? Is it related to updating the node version? This wall all from https://github.com/alexjoverm/typescript-library-starter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I saw the similarities, I reality I never saw something similar to that setup. If you look around all libs that mainly support node all use similar tsconfig and output commonjs code with types near the js code. So unless we need to do something fancy there is no need at this point to support es5/umd/other types of import.

"start": "rollup -c rollup.config.ts -w",
"lint": "eslint --ext .ts,.js src/ test/",
"prebuild": "rimraf dist && rimraf docs",
"build": "tsc -p tsconfig.build.json && typedoc --tsconfig tsconfig.build.json",
"test": "jest --coverage",
"test:watch": "jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache",
"deploy-docs": "ts-node tools/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"commit": "git-cz",
"semantic-release": "semantic-release",
"semantic-release-prepare": "ts-node tools/semantic-release-prepare",
"precommit": "lint-staged",
"travis-deploy-once": "travis-deploy-once"
"typecheck": "tsc -p tsconfig.build.json --noEmit"
},
"lint-staged": {
"{src,test}/**/*.ts": [
"prettier --write",
"git add"
"prettier --write"
]
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"jest": {
"transform": {
".(ts|tsx)": "ts-jest"
Expand Down Expand Up @@ -76,52 +72,45 @@
"prettier": {
"singleQuote": true
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"devDependencies": {
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@types/express": "^4.16.1",
"@types/graphql": "^14.2.0",
"@types/jest": "^23.3.2",
"@types/node": "^10.11.0",
"colors": "^1.3.2",
"commitizen": "^3.0.0",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"dedent-js": "^1.0.1",
"graphql": "^14.2.1",
"husky": "^1.0.1",
"jest": "^23.6.0",
"jest-config": "^23.6.0",
"lint-staged": "^8.0.0",
"lodash.camelcase": "^4.3.0",
"prettier": "^1.14.3",
"prompt": "^1.0.0",
"replace-in-file": "^3.4.2",
"rimraf": "^2.6.2",
"rollup": "^0.67.0",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.18.0",
"semantic-release": "^15.9.16",
"shelljs": "^0.8.3",
"travis-deploy-once": "^5.0.9",
"ts-jest": "^23.10.2",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-config-prettier": "^1.15.0",
"typedoc": "^0.12.0",
"typescript": "~3.3.0"
"@commitlint/cli": "11.0.0",
"@commitlint/config-conventional": "11.0.0",
"@types/express": "4.17.11",
"@types/jest": "26.0.20",
"@types/node": "14.14.25",
"@typescript-eslint/eslint-plugin": "4.14.1",
"@typescript-eslint/parser": "4.14.1",
"colors": "1.4.0",
"coveralls": "3.1.0",
"dedent-js": "1.0.1",
"eslint": "7.19.0",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-prettier": "3.3.1",
"graphql": "15.5.0",
"husky": "4.3.8",
"jest": "26.6.3",
"lint-staged": "10.5.3",
"prettier": "2.2.1",
"rimraf": "3.0.2",
"semantic-release": "17.3.7",
"shelljs": "0.8.4",
"ts-jest": "26.5.0",
"ts-node": "9.1.1",
"typedoc": "0.20.20",
"typescript": "4.1.3"
},
"peerDependencies": {
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0"
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
}
}
15 changes: 15 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": ["config:base"],
"timezone": "America/New_York",
"schedule": ["before 10am on Friday"],
"lockFileMaintenance": {
"enabled": true,
"schedule": "before 10am on Friday"
},
"packageRules": [
{
"updateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
}
]
}
38 changes: 0 additions & 38 deletions rollup.config.ts

This file was deleted.

10 changes: 5 additions & 5 deletions src/RewriteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default class RewriteHandler {
public matches: RewriterMatch[] = [];

private rewriters: Rewriter[];
private hasProcessedRequest: boolean = false;
private hasProcessedResponse: boolean = false;
private hasProcessedRequest = false;
private hasProcessedResponse = false;

constructor(rewriters: Rewriter[]) {
this.rewriters = rewriters;
Expand All @@ -35,7 +35,7 @@ export default class RewriteHandler {
let rewrittenVariables = variables;
const rewrittenDoc = rewriteDoc(doc, (nodeAndVars, parents) => {
let rewrittenNodeAndVars = nodeAndVars;
this.rewriters.forEach(rewriter => {
this.rewriters.forEach((rewriter) => {
const isMatch = rewriter.matches(nodeAndVars, parents);
if (isMatch) {
rewrittenVariables = rewriter.rewriteVariables(rewrittenNodeAndVars, rewrittenVariables);
Expand All @@ -50,7 +50,7 @@ export default class RewriteHandler {
}
this.matches.push({
rewriter,
paths
paths,
});
}
return isMatch;
Expand All @@ -71,7 +71,7 @@ export default class RewriteHandler {
this.hasProcessedResponse = true;
let rewrittenResponse = response;
this.matches.reverse().forEach(({ rewriter, paths }) => {
paths.forEach(path => {
paths.forEach((path) => {
rewrittenResponse = rewriteResultsAtPath(
rewrittenResponse,
path,
Expand Down
20 changes: 10 additions & 10 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class FragmentTracer {
fragmentName: string,
pathWithinFragment: ReadonlyArray<string>
): ReadonlyArray<ReadonlyArray<string>> {
return this.getPathsToFragment(fragmentName).map(path => [...path, ...pathWithinFragment]);
return this.getPathsToFragment(fragmentName).map((path) => [...path, ...pathWithinFragment]);
}

private getFragmentDefs(): ReadonlyArray<FragmentDefinitionNode> {
Expand Down Expand Up @@ -125,7 +125,7 @@ export class FragmentTracer {
}

private buildFragmentPathMap(): FragmentPathMap {
const mainOperation = this.doc.definitions.find(node => node.kind === 'OperationDefinition');
const mainOperation = this.doc.definitions.find((node) => node.kind === 'OperationDefinition');
if (!mainOperation) return {};

// partial paths are the paths inside of each fragmnt to other fragments
Expand All @@ -151,7 +151,7 @@ export class FragmentTracer {
)) {
fragmentPathMap[mergedFragmentName] = [
...(fragmentPathMap[mergedFragmentName] || []),
...mergedFragmentPaths
...mergedFragmentPaths,
];
}
}
Expand Down Expand Up @@ -183,11 +183,11 @@ export const rewriteDoc = (
if (key === 'loc') continue;
const val = (node as any)[key];
if (Array.isArray(val)) {
(node as any)[key] = val.map(elm => {
(node as any)[key] = val.map((elm) => {
if (typeof elm === 'object') {
const next: NodeAndVarDefs = {
variableDefinitions,
node: elm
node: elm,
};
return walkRecursive(next, nextParents);
}
Expand All @@ -196,7 +196,7 @@ export const rewriteDoc = (
} else if (typeof val === 'object') {
const next: NodeAndVarDefs = {
variableDefinitions,
node: val
node: val,
};
(node as any)[key] = walkRecursive(next, nextParents);
}
Expand All @@ -206,7 +206,7 @@ export const rewriteDoc = (

const root: NodeAndVarDefs = {
variableDefinitions,
node: doc
node: doc,
};
const rewrittenDoc = walkRecursive(root, []) as DocumentNode;
return replaceVariableDefinitions(rewrittenDoc, variableDefinitions);
Expand All @@ -229,7 +229,7 @@ export const replaceVariableDefinitions = (
doc: DocumentNode,
variableDefinitions: ReadonlyArray<VariableDefinitionNode>
): DocumentNode => {
const definitions = doc.definitions.map(def => {
const definitions = doc.definitions.map((def) => {
if (def.kind === 'OperationDefinition') {
return { ...def, variableDefinitions };
}
Expand All @@ -244,7 +244,7 @@ export const replaceVariableDefinitions = (
/** @hidden */
export const extractPath = (parents: ReadonlyArray<ASTNode>): ReadonlyArray<string> => {
const path: string[] = [];
parents.forEach(parent => {
parents.forEach((parent) => {
if (parent.kind === 'Field') {
path.push(parent.name.value);
}
Expand Down Expand Up @@ -285,7 +285,7 @@ export const rewriteResultsAtPath = (
if (curResults === undefined || curResults === null) return results;

if (Array.isArray(curResults)) {
newResults[curPathElm] = curResults.map(result =>
newResults[curPathElm] = curResults.map((result) =>
rewriteResultsAtPath(result, remainingPath, callback)
);
} else {
Expand Down