Skip to content

Commit

Permalink
GraphQL v16 compatibility (#140)
Browse files Browse the repository at this point in the history
* GraphQL v16 compatibility

* Remove TSLint
  • Loading branch information
ardatan authored Nov 2, 2021
1 parent d75988c commit 2876dd8
Show file tree
Hide file tree
Showing 40 changed files with 1,661 additions and 1,803 deletions.
46 changes: 46 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"eslint:recommended",
"standard",
"prettier",
"plugin:@typescript-eslint/recommended"
],
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"max-len": "off",
"arrow-parens": "off",
"no-shadow": "off",
"@typescript-eslint/interface-name-prefix": "off",
"comma-dangle": "off",
"sort-keys": "off",
"max-classes-per-file": "off"
},
"env": {
"es6": true,
"node": true
},
"overrides": [
{
"files": [
"**/{test,tests,testing}/**/*.{ts,js}",
"*.{spec,test}.{ts,js}"
],
"env": {
"jest": true
},
"rules": {
"@typescript-eslint/no-unused-vars": "off",
"import/no-extraneous-dependencies": "off"
}
}
],
"ignorePatterns": [
"dist",
"node_modules"
]
}
14 changes: 9 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:

strategy:
matrix:
node-version: [10, 12, 14, 15]
node-version: [12, 14, 16]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
graphql-version: [15, 16]

steps:
- uses: actions/checkout@v2
Expand All @@ -33,17 +34,20 @@ jobs:
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-${{matrix.node-version}}-${{matrix.graphql-version}}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-${{matrix.node-version}}-${{matrix.graphql-version}}-yarn-
- name: Use GraphQL v${{matrix.graphql-version}}
run: node ./scripts/match-graphql.js ${{matrix.graphql-version}}

- name: Install from network when no cache hit
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --ignore-optional --prefer-offline
run: yarn install --ignore-optional --prefer-offline

- name: Install from cache on cache-hit
if: steps.yarn-cache.outputs.cache-hit == 'true'
run: yarn install --frozen-lockfile --ignore-optional --offline
run: yarn install --ignore-optional --offline

- name: Format and Lint check
run: yarn check-format && yarn lint
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "none"
}
2 changes: 2 additions & 0 deletions examples/blog/src/query-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ValidationError extends Error {
*/
export default class QueryStore {
private store = new Map<string, CompiledQuery>();
// eslint-disable-next-line no-useless-constructor
constructor(private schema: GraphQLSchema) {}

get(id: string): CompiledQuery | undefined {
Expand All @@ -27,6 +28,7 @@ export default class QueryStore {

const compiledQuery = compileQuery(this.schema, parse(query));
if (!isCompiledQuery(compiledQuery)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
throw new ValidationError(compiledQuery.errors!);
}

Expand Down
32 changes: 19 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"scripts": {
"precommit": "lint-staged",
"prepublishOnly": "yarn && yarn build",
"format": "prettier --no-config --write 'src/**/*.ts' '*.js'",
"check-format": "prettier --no-config -l 'src/**/*.ts' '*.js'",
"lint": "tslint --project .",
"lint-fix": "tslint --project . --fix",
"build": "tsc",
"format": "prettier --write 'src/**/*.ts' '*.js'",
"check-format": "prettier -l 'src/**/*.ts' '*.js'",
"lint": "eslint --ext .ts .",
"lint-fix": "eslint --ext .ts . --fix",
"build": "tsc --project tsconfig.build.json",
"test": "jest",
"mutation-test": "stryker run",
"codecov": "codecov",
Expand Down Expand Up @@ -61,18 +61,24 @@
"@types/lodash.merge": "^4.6.6",
"@types/lodash.mergewith": "^4.6.6",
"@types/node": "^10.17.26",
"@typescript-eslint/eslint-plugin": "5.2.0",
"@typescript-eslint/parser": "5.2.0",
"benchmark": "^2.1.4",
"codecov": "^3.3.0",
"graphql": "^15.1.0",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.1",
"eslint-plugin-standard": "^5.0.0",
"graphql": "^16.0.0",
"jest": "^24.7.1",
"lint-staged": "^8.1.5",
"prettier": "^1.19.1",
"prettier": "^2.4.1",
"ts-jest": "^24.0.2",
"ts-node": "^8.0.3",
"tslint": "^5.15.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.9.5"
"typescript": "^4.4.4"
},
"dependencies": {
"@graphql-typed-document-node/core": "3.1.0",
Expand All @@ -86,7 +92,7 @@
"lint-staged": {
"linters": {
"*.ts": [
"tslint -c tslint.json -p tsconfig.json --fix",
"eslint --fix",
"prettier --no-config --write",
"git add"
],
Expand All @@ -96,4 +102,4 @@
]
}
}
}
}
20 changes: 20 additions & 0 deletions scripts/match-graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { writeFileSync } = require('fs');
const { resolve } = require('path');
const { argv, cwd } = require('process');

const pkgPath = resolve(cwd(), './package.json');

const pkg = require(pkgPath);

const version = argv[2];

if (pkg.devDependencies.graphql.startsWith(version)) {
console.info(`GraphQL v${version} is match! Skipping.`);
return;
}

// If it is not stable version, use pinned version
const npmVersion = version.includes('-') ? version : `^${version}`;
pkg.devDependencies.graphql = npmVersion;

writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), 'utf8');
40 changes: 18 additions & 22 deletions src/__benchmarks__/benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,22 @@ async function runBenchmarks() {
debug: true
} as any);
if (!isCompiledQuery(compiledQuery)) {
// tslint:disable-next-line:no-console
// eslint-disable-next-line no-console
console.error(`${bench} failed to compile`);
return null;
}
// tslint:disable-next-line:no-console
// eslint-disable-next-line no-console
console.log(
`size of function for ${bench}: ${
(compiledQuery as any)
.__DO_NOT_USE_THIS_OR_YOU_WILL_BE_FIRED_compilation.length
}`
);
const graphqlJsResult = await execute(
const graphqlJsResult = await execute({
schema,
query,
undefined,
undefined,
variables || {}
);
document: query,
variableValues: variables || {}
});
const graphqlJitResult = await compiledQuery.query(
undefined,
undefined,
Expand All @@ -84,7 +82,7 @@ async function runBenchmarks() {
if (
JSON.stringify(graphqlJitResult) !== JSON.stringify(graphqlJsResult)
) {
// tslint:disable-next-line:no-console
// eslint-disable-next-line no-console
console.error(
JSON.stringify(graphqlJitResult),
"is different of",
Expand All @@ -98,15 +96,13 @@ async function runBenchmarks() {
minSamples: 150,
defer: true,
fn(deferred: any) {
const result = execute(
const result = execute({
schema,
query,
undefined,
undefined,
variables || {}
);
document: query,
variableValues: variables || {}
});
if (isPromise(result)) {
return result.then(res =>
return result.then((res) =>
deferred.resolve(skipJSON ? res : JSON.stringify(res))
);
}
Expand All @@ -127,7 +123,7 @@ async function runBenchmarks() {
variables || {}
);
if (isPromise(result)) {
return result.then(res =>
return result.then((res) =>
deferred.resolve(
skipJSON ? res : compiledQuery.stringify(res)
)
Expand All @@ -140,11 +136,11 @@ async function runBenchmarks() {
})
// add listeners
.on("cycle", (event: any) => {
// tslint:disable-next-line:no-console
// eslint-disable-next-line no-console
console.log(String(event.target));
})
.on("start", () => {
// tslint:disable-next-line:no-console
// eslint-disable-next-line no-console
console.log("Starting", bench);
});
return suite;
Expand All @@ -154,7 +150,7 @@ async function runBenchmarks() {

const benchsToRun = benchs.filter(isNotNull);
let benchRunning = 1;
benchsToRun.forEach(bench =>
benchsToRun.forEach((bench) =>
bench.on("complete", () => {
if (benchRunning < benchsToRun.length) {
benchsToRun[benchRunning++].run();
Expand All @@ -164,12 +160,12 @@ async function runBenchmarks() {
if (benchsToRun.length > 0) {
benchsToRun[0].run();
} else {
// tslint:disable-next-line
// eslint-disable-next-line
console.log("No benchmarks to run");
}
}

// tslint:disable-next-line
// eslint-disable-next-line
runBenchmarks().catch(console.error);

function isNotNull<T>(a: T | null | undefined): a is T {
Expand Down
1 change: 1 addition & 0 deletions src/__benchmarks__/profillable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if (isCompiledQuery(compiled)) {
const now = Date.now();
let operations = 0;
const timelimit = getTimelimit();
// eslint-disable-next-line no-inner-declarations
function benchmark() {
if (Date.now() - now > timelimit) {
console.log(`Ran ${operations} operations in ${timelimit / 1000}s`);
Expand Down
22 changes: 11 additions & 11 deletions src/__benchmarks__/schema-many-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export function schema() {
fields: {
url: {
type: GraphQLString,
resolve: image => Promise.resolve(image.url)
resolve: (image) => Promise.resolve(image.url)
},
width: {
type: GraphQLInt,
resolve: image => Promise.resolve(image.width)
resolve: (image) => Promise.resolve(image.width)
},
height: {
type: GraphQLInt,
resolve: image => Promise.resolve(image.height)
resolve: (image) => Promise.resolve(image.height)
}
}
});
Expand All @@ -34,11 +34,11 @@ export function schema() {
fields: () => ({
id: {
type: GraphQLString,
resolve: author => Promise.resolve(author.id)
resolve: (author) => Promise.resolve(author.id)
},
name: {
type: GraphQLString,
resolve: author => Promise.resolve(author.name)
resolve: (author) => Promise.resolve(author.name)
},
pic: {
args: { width: { type: GraphQLInt }, height: { type: GraphQLInt } },
Expand All @@ -47,7 +47,7 @@ export function schema() {
},
recentArticle: {
type: BlogArticle,
resolve: author => Promise.resolve(author.recentArticle)
resolve: (author) => Promise.resolve(author.recentArticle)
}
})
});
Expand All @@ -57,24 +57,24 @@ export function schema() {
fields: {
id: {
type: new GraphQLNonNull(GraphQLID),
resolve: article => Promise.resolve(article.id)
resolve: (article) => Promise.resolve(article.id)
},
isPublished: {
type: GraphQLBoolean,
resolve: article => Promise.resolve(article.isPublished)
resolve: (article) => Promise.resolve(article.isPublished)
},
author: { type: BlogAuthor },
title: {
type: GraphQLString,
resolve: article => Promise.resolve(article && article.title)
resolve: (article) => Promise.resolve(article && article.title)
},
body: {
type: GraphQLString,
resolve: article => Promise.resolve(article.body)
resolve: (article) => Promise.resolve(article.body)
},
keywords: {
type: new GraphQLList(GraphQLString),
resolve: article => Promise.resolve(article.keywords)
resolve: (article) => Promise.resolve(article.keywords)
}
}
});
Expand Down
Loading

0 comments on commit 2876dd8

Please sign in to comment.